Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sattvikc committed Jul 2, 2024
1 parent 1b70227 commit 3d16e01
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
35 changes: 18 additions & 17 deletions src/main/java/io/supertokens/webserver/WebserverAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,15 @@ public static SemVer getLatestCDIVersion() {
}

public SemVer getLatestCDIVersionForRequest(HttpServletRequest req)
throws ServletException, TenantOrAppNotFoundException {
throws ServletException {
SemVer maxCDIVersion = getLatestCDIVersion();
String maxCDIVersionStr = Config.getConfig(
getAppIdentifierWithoutVerifying(req).getAsPublicTenantIdentifier(), main).getMaxCDIVersion();
String maxCDIVersionStr = null;
try {
maxCDIVersionStr = Config.getConfig(
getAppIdentifierWithoutVerifying(req).getAsPublicTenantIdentifier(), main).getMaxCDIVersion();
} catch (TenantOrAppNotFoundException e) {
// ignore missing app
}
if (maxCDIVersionStr != null) {
maxCDIVersion = new SemVer(maxCDIVersionStr);
}
Expand Down Expand Up @@ -534,25 +539,21 @@ protected String getRIDFromRequest(HttpServletRequest req) {
}

protected SemVer getVersionFromRequest(HttpServletRequest req) throws ServletException {
try {
SemVer maxCDIVersion = getLatestCDIVersionForRequest(req);
String version = req.getHeader("cdi-version");
SemVer maxCDIVersion = getLatestCDIVersionForRequest(req);
String version = req.getHeader("cdi-version");

if (version != null) {
SemVer versionFromRequest = new SemVer(version);
if (version != null) {
SemVer versionFromRequest = new SemVer(version);

if (versionFromRequest.greaterThan(maxCDIVersion)) {
throw new ServletException(
new BadRequestException("cdi-version " + versionFromRequest + " not supported"));
}

return versionFromRequest;
if (versionFromRequest.greaterThan(maxCDIVersion)) {
throw new ServletException(
new BadRequestException("cdi-version " + versionFromRequest + " not supported"));
}

return maxCDIVersion;
} catch (TenantOrAppNotFoundException e) {
throw new ServletException(e);
return versionFromRequest;
}

return maxCDIVersion;
}

public static class BadRequestException extends Exception {
Expand Down
5 changes: 4 additions & 1 deletion src/test/java/io/supertokens/test/LoggingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,12 @@ public void testTenantNotFoundExceptionUsesTheRightCUD() throws Exception {
stdOutput.reset();
errorOutput.reset();

JsonObject body = new JsonObject();
body.addProperty("email", "[email protected]");
body.addProperty("password", "abcd");
try {
HttpRequestForTesting.sendJsonPOSTRequest(process.getProcess(), "",
"http://localhost:3567/tenant2/recipe/signin", new JsonObject(), 1000, 1000, null,
"http://localhost:3567/tenant2/recipe/signin", body, 1000, 1000, null,
Utils.getCdiVersionStringLatestForTests(), "emailpassword");
throw new Exception("Should not come here");
} catch (io.supertokens.test.httpRequest.HttpResponseException e) {
Expand Down

0 comments on commit 3d16e01

Please sign in to comment.