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

handle auth in qp #1474

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading