Skip to content

Commit

Permalink
handle auth in qp
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushaga14 committed Sep 10, 2024
1 parent 00f90f0 commit 50a28f9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.akto.dto.HttpResponseParams;
import com.akto.dto.runtime_filters.RuntimeFilter;
import com.akto.dto.type.KeyTypes;
import com.akto.dto.type.RequestTemplate;
import com.akto.util.JSONUtils;

import com.mongodb.BasicDBObject;
Expand Down Expand Up @@ -84,7 +85,19 @@ public static boolean findAuthType(HttpResponseParams httpResponseParams, ApiInf
if(!customAuthTypePayloadKeys.isEmpty() ){
BasicDBObject flattenedPayload = null;
try{
BasicDBObject basicDBObject = BasicDBObject.parse(httpResponseParams.getRequestParams().getPayload());
BasicDBObject basicDBObject = new BasicDBObject();
try {
basicDBObject = BasicDBObject.parse(httpResponseParams.getRequestParams().getPayload());
} catch (Exception e) {
// TODO: handle exception
}
BasicDBObject queryParamObj = new BasicDBObject();
try {
queryParamObj = RequestTemplate.getQueryJSON(httpResponseParams.getRequestParams().getURL());
} catch (Exception e) {
// TODO: handle exception
}
basicDBObject.putAll(queryParamObj.toMap());
flattenedPayload = JSONUtils.flattenWithDots(basicDBObject);
} catch (Exception e){
}
Expand Down Expand Up @@ -133,7 +146,6 @@ public static boolean findAuthType(HttpResponseParams httpResponseParams, ApiInf
}
}
}

boolean returnValue = false;
if (authTypes.isEmpty()) {
authTypes.add(ApiInfo.AuthType.UNAUTHENTICATED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public static ExecutionResult checkAuth(Auth auth, RawApi rawApi, TestingRunConf
List<String> customAuthTypePayloadKeys = customAuthType.getPayloadKeys();
for (String payloadAuthKey: customAuthTypePayloadKeys) {
Operations.deleteBodyParam(rawApi, payloadAuthKey);
Operations.deleteQueryParam(rawApi, payloadAuthKey).getErrMsg().isEmpty();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ private static boolean removeAuthIfNotChanged(RawApi originalRawApi, RawApi test
for (String payloadAuthKey: authBodyParams) {
if (unchangedBodyKeys.contains(payloadAuthKey)) {
removed = Operations.deleteBodyParam(testRawApi, payloadAuthKey).getErrMsg().isEmpty() || removed;
removed = Operations.deleteQueryParam(testRawApi, authMechanismHeaderKey).getErrMsg().isEmpty() || removed;
}
}

Expand All @@ -457,7 +458,9 @@ private static boolean removeCustomAuth(RawApi rawApi, List<CustomAuthType> cust
List<String> customAuthTypePayloadKeys = customAuthType.getPayloadKeys();
for (String payloadAuthKey: customAuthTypePayloadKeys) {
removed = Operations.deleteBodyParam(rawApi, payloadAuthKey).getErrMsg().isEmpty() || removed;
removed = Operations.deleteQueryParam(rawApi, payloadAuthKey).getErrMsg().isEmpty() || removed;
}

}
return removed;
}
Expand Down

0 comments on commit 50a28f9

Please sign in to comment.