Skip to content

Commit

Permalink
allow all status codes checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushaga14 committed Apr 10, 2024
1 parent e61f05e commit 5c69727
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LegacyCard, Tabs, Text, Button, ButtonGroup, Divider } from '@shopify/polaris';
import { LegacyCard, Tabs, Text, Button, ButtonGroup, Divider, HorizontalStack, Checkbox } from '@shopify/polaris';
import { useState, useEffect } from 'react';
import SpinnerCentered from '../../../components/progress/SpinnerCentered';
import DropdownSearch from '../../../components/shared/DropdownSearch';
Expand All @@ -23,6 +23,7 @@ function LoginStepBuilder({extractInformation, showOnlyApi, setStoreData}) {
regex: "(\d+){1,6}",
type: "LOGIN_FORM",
url: "https://xyz.com",
allowAllStatusCodes: false,
testResponse: ""
}

Expand Down Expand Up @@ -86,6 +87,14 @@ function LoginStepBuilder({extractInformation, showOnlyApi, setStoreData}) {
setSelectedStep(step)
}

function handleStatusCodeToggle(val) {
setSteps(prev => prev.map((step, index) => index === selectedStep ? {
...step,
allowAllStatusCodes: val
}
: step))
}

function handleStepTypeChange(type) {
if (type === "LOGIN_FORM") {
setSteps(prev => prev.map((step, index) => index === selectedStep ? {
Expand Down Expand Up @@ -166,7 +175,14 @@ function LoginStepBuilder({extractInformation, showOnlyApi, setStoreData}) {
<LegacyCard>
<div style={{ display: "grid", gridTemplateColumns: "auto max-content", alignItems: "center", padding: "10px" }}>
<Tabs tabs={stepsTabs} selected={selectedStep} onSelect={handleStepChange}></Tabs>
<Button id={"add-step-button"} primary onClick={handleAddStep}>Add step</Button>
<HorizontalStack gap={"2"}>
<Checkbox
label='Allow All Status codes'
checked={steps[selectedStep].allowAllStatusCodes}
onChange={() => handleStatusCodeToggle(!steps[selectedStep].allowAllStatusCodes)}
/>
<Button id={"add-step-button"} primary onClick={handleAddStep}>Add step</Button>
</HorizontalStack>
</div>

<Divider />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,15 @@ public static LoginFlowResponse runLoginFlow(WorkflowTest workflowTest, AuthMech

Map<String, Object> valuesMap = constructValueMap(loginFlowParams);

int index = 0;
for (Node node: nodes) {
boolean allowAllStatusCodes = false;
WorkflowTestResult.NodeResult nodeResult;
try {
nodeResult = processNode(node, valuesMap, false, false, new ArrayList<>());
if (authMechanism.getRequestData() != null && authMechanism.getRequestData().size() > 0 && authMechanism.getRequestData().get(index).getAllowAllStatusCodes()) {
allowAllStatusCodes = authMechanism.getRequestData().get(0).getAllowAllStatusCodes();
}
nodeResult = processNode(node, valuesMap, allowAllStatusCodes, false, new ArrayList<>());
} catch (Exception e) {
;
List<String> testErrors = new ArrayList<>();
Expand All @@ -261,6 +266,7 @@ public static LoginFlowResponse runLoginFlow(WorkflowTest workflowTest, AuthMech
saveValueMapData(loginFlowParams, valuesMap);
}
}
index++;

}

Expand Down
12 changes: 11 additions & 1 deletion libs/dao/src/main/java/com/akto/dto/testing/RequestData.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ public class RequestData {

private String tokenFetchCommand;

private boolean allowAllStatusCodes;

public RequestData() { }
public RequestData(String body, String headers, String queryParams, String url, String method, String type, String regex, String otpRefUuid, String tokenFetchCommand) {
public RequestData(String body, String headers, String queryParams, String url, String method,
String type, String regex, String otpRefUuid, String tokenFetchCommand, boolean allowAllStatusCodes) {
this.body = body;
this.headers = headers;
this.queryParams = queryParams;
Expand Down Expand Up @@ -102,4 +105,11 @@ public void setOtpRefUuid(String otpRefUuid) {
public void setTokenFetchCommand(String tokenFetchCommand) {
this.tokenFetchCommand = tokenFetchCommand;
}

public boolean getAllowAllStatusCodes() {
return allowAllStatusCodes;
}
public void setAllowAllStatusCodes(boolean allowAllStatusCodes) {
this.allowAllStatusCodes = allowAllStatusCodes;
}
}

0 comments on commit 5c69727

Please sign in to comment.