diff --git a/apps/dashboard/src/main/java/com/akto/action/test_editor/SaveTestEditorAction.java b/apps/dashboard/src/main/java/com/akto/action/test_editor/SaveTestEditorAction.java index 0e870c3128..40cfa33817 100644 --- a/apps/dashboard/src/main/java/com/akto/action/test_editor/SaveTestEditorAction.java +++ b/apps/dashboard/src/main/java/com/akto/action/test_editor/SaveTestEditorAction.java @@ -9,11 +9,14 @@ import com.akto.dao.context.Context; import com.akto.dao.test_editor.TestConfigYamlParser; import com.akto.dao.test_editor.YamlTemplateDao; +import com.akto.dao.test_editor.info.InfoParser; import com.akto.dao.testing.TestingRunResultDao; import com.akto.dto.AccountSettings; import com.akto.dto.ApiInfo; import com.akto.dto.CustomAuthType; import com.akto.dto.User; +import com.akto.dto.test_editor.Category; +import com.akto.dto.test_editor.Info; import com.akto.dto.test_editor.TestConfig; import com.akto.dto.test_editor.TestLibrary; import com.akto.dto.test_editor.YamlTemplate; @@ -32,6 +35,7 @@ import com.akto.testing.TestExecutor; import com.akto.util.Constants; import com.akto.util.enums.GlobalEnums; +import com.akto.util.enums.GlobalEnums.YamlTemplateSource; import com.akto.utils.GithubSync; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; @@ -91,6 +95,29 @@ public String fetchTestingRunResultFromTestingRun() { return SUCCESS.toUpperCase(); } + private String getInfoKeyMissing(Info info){ + if (info.getName() == null){ + return "name"; + } + if(info.getDescription() == null){ + return "description"; + } + if(info.getDetails() == null){ + return "details"; + } + if(info.getCategory() == null){ + return "category"; + } + if(info.getSeverity() == null){ + return "severity"; + } + if(info.getSubCategory() == null){ + return "subcategory"; + } + + return ""; + } + public String saveTestEditorFile() { TestConfig testConfig; try { @@ -106,6 +133,21 @@ public String saveTestEditorFile() { return ERROR.toUpperCase(); } + // adding all necessary fields check for info in editor + InfoParser parser = new InfoParser(); + Info convertedInfo = parser.parse(info); + + String keyMissingInInfo = getInfoKeyMissing(convertedInfo); + if(keyMissingInInfo.length() > 0){ + addActionError("Error in template: " + keyMissingInInfo + " key absent"); + return ERROR.toUpperCase(); + } + + Category category = convertedInfo.getCategory(); + if (category.getName() == null || category.getDisplayName() == null || category.getShortName() == null) { + return ERROR.toUpperCase(); + } + Map infoMap = (Map) info; finalTestId = config.getOrDefault("id", "").toString(); diff --git a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/test_editor/TestEditor.jsx b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/test_editor/TestEditor.jsx index 03f5a0df35..266091da6c 100644 --- a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/test_editor/TestEditor.jsx +++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/test_editor/TestEditor.jsx @@ -87,7 +87,14 @@ const TestEditor = () => { ) + const defaultId = "REMOVE_TOKENS"; + useEffect(() => { + const path = window.location.pathname; + const pathArr = path.split("test-editor") + if(pathArr[1].length < 2){ + navigate(defaultId) + } fetchAllTests() }, []) diff --git a/apps/dashboard/web/polaris_web/web/src/apps/main/App.js b/apps/dashboard/web/polaris_web/web/src/apps/main/App.js index a422c78c5d..c88a760cb0 100644 --- a/apps/dashboard/web/polaris_web/web/src/apps/main/App.js +++ b/apps/dashboard/web/polaris_web/web/src/apps/main/App.js @@ -246,6 +246,10 @@ const router = createBrowserRouter([ path: "test-editor/:testId", element: }, + { + path: "test-editor", + element: + }, { path: "onboarding", element: