Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes in required fields and default testid for frontend #680

Merged
merged 10 commits into from
Jan 4, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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<String, Object> infoMap = (Map<String, Object>) info;

finalTestId = config.getOrDefault("id", "").toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,14 @@ const TestEditor = () => {
<TopBar secondaryMenu={headerComp} />
)

const defaultId = "REMOVE_TOKENS";

useEffect(() => {
const path = window.location.pathname;
const pathArr = path.split("test-editor")
if(pathArr[1].length < 2){
navigate(defaultId)
}
fetchAllTests()
}, [])

Expand Down
4 changes: 4 additions & 0 deletions apps/dashboard/web/polaris_web/web/src/apps/main/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ const router = createBrowserRouter([
path: "test-editor/:testId",
element: <TestEditor />
},
{
path: "test-editor",
element: <TestEditor />
},
{
path: "onboarding",
element: <Onboarding />
Expand Down
Loading