Skip to content

Commit

Permalink
fix: PR comment
Browse files Browse the repository at this point in the history
  • Loading branch information
sattvikc committed Nov 15, 2023
1 parent f6da48c commit 597b0b1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I
result.addProperty("status", "INVALID_TOTP_ERROR");
super.sendJsonResponse(200, result, resp);
if (getVersionFromRequest(req).greaterThanOrEqualTo(SemVer.v4_1)) {
result.addProperty("currentNumberOfAttempts", e.currentAttempts);
result.addProperty("maxNumberOfAttempts", e.maxAttempts);
result.addProperty("currentNumberOfFailedAttempts", e.currentAttempts);
result.addProperty("maxNumberOfFailedAttempts", e.maxAttempts);
}
} catch (UnknownTotpUserIdException e) {
result.addProperty("status", "UNKNOWN_USER_ID_ERROR");
Expand All @@ -90,8 +90,8 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I
result.addProperty("status", "LIMIT_REACHED_ERROR");
result.addProperty("retryAfterMs", e.retryAfterMs);
if (getVersionFromRequest(req).greaterThanOrEqualTo(SemVer.v4_1)) {
result.addProperty("currentNumberOfAttempts", e.currentAttempts);
result.addProperty("maxNumberOfAttempts", e.maxAttempts);
result.addProperty("currentNumberOfFailedAttempts", e.currentAttempts);
result.addProperty("maxNumberOfFailedAttempts", e.maxAttempts);
}
super.sendJsonResponse(200, result, resp);
} catch (StorageQueryException | StorageTransactionLogicException | FeatureNotEnabledException |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,16 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I
result.addProperty("status", "INVALID_TOTP_ERROR");

if (getVersionFromRequest(req).greaterThanOrEqualTo(SemVer.v4_1)) {
result.addProperty("currentNumberOfAttempts", e.currentAttempts);
result.addProperty("maxNumberOfAttempts", e.maxAttempts);
result.addProperty("currentNumberOfFailedAttempts", e.currentAttempts);
result.addProperty("maxNumberOfFailedAttempts", e.maxAttempts);
}
super.sendJsonResponse(200, result, resp);
} catch (LimitReachedException e) {
result.addProperty("status", "LIMIT_REACHED_ERROR");
result.addProperty("retryAfterMs", e.retryAfterMs);
if (getVersionFromRequest(req).greaterThanOrEqualTo(SemVer.v4_1)) {
result.addProperty("currentNumberOfAttempts", e.currentAttempts);
result.addProperty("maxNumberOfAttempts", e.maxAttempts);
result.addProperty("currentNumberOfFailedAttempts", e.currentAttempts);
result.addProperty("maxNumberOfFailedAttempts", e.maxAttempts);
}
super.sendJsonResponse(200, result, resp);
} catch (StorageQueryException | StorageTransactionLogicException | TenantOrAppNotFoundException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ public void testApi() throws Exception {
null,
Utils.getCdiVersionStringLatestForTests(),
"totp");
assertEquals(3, res0.entrySet().size());
assert res0.get("status").getAsString().equals("INVALID_TOTP_ERROR");
assertEquals(1, res0.get("currentNumberOfFailedAttempts").getAsInt());
assertEquals(1, res0.get("maxNumberOfFailedAttempts").getAsInt());

// Check that rate limiting is triggered for the user:
JsonObject res3 = HttpRequestForTesting.sendJsonPOSTRequest(
Expand Down

0 comments on commit 597b0b1

Please sign in to comment.