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

fix: core config validation #894

Merged
merged 10 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres
to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [7.0.16] - 2023-12-04

- Returns 400, instead of 500, for badly typed core config while creating CUD, App or Tenant

## [7.0.15] - 2023-11-28

- Adds test for user pagination from old version
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ compileTestJava { options.encoding = "UTF-8" }
// }
//}

version = "7.0.15"
version = "7.0.16"


repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.supertokens.webserver.api.multitenancy;

import com.fasterxml.jackson.databind.exc.InvalidFormatException;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import io.supertokens.Main;
Expand Down Expand Up @@ -138,6 +139,8 @@ protected void handle(HttpServletRequest req, TenantIdentifier sourceTenantIdent
throw new ServletException(new BadRequestException("Invalid core config: " + e.getMessage()));
} catch (InvalidProviderConfigException e) {
throw new ServletException(new BadRequestException("Invalid third party config: " + e.getMessage()));
} catch (InvalidFormatException e) {
rishabhpoddar marked this conversation as resolved.
Show resolved Hide resolved
throw new ServletException(new BadRequestException("Cannot deserialize value `" + e.getValue() + "` for property `" + e.getPath().get(0).getFieldName() + "`"));
}
}

Expand Down
22 changes: 22 additions & 0 deletions src/test/java/io/supertokens/test/multitenant/api/TestApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -507,4 +507,26 @@ public void testDefaultRecipesEnabledWhileCreatingApp() throws Exception {
assertTrue(tenant.get("thirdParty").getAsJsonObject().get("enabled").getAsBoolean());
assertTrue(tenant.get("passwordless").getAsJsonObject().get("enabled").getAsBoolean());
}

@Test
public void testInvalidTypedValueInCoreConfigWhileCreatingApp() throws Exception {
rishabhpoddar marked this conversation as resolved.
Show resolved Hide resolved
if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) {
return;
}

JsonObject config = new JsonObject();
config.addProperty("access_token_validity", "abcd");
StorageLayer.getBaseStorage(process.getProcess()).modifyConfigToAddANewUserPoolForTesting(config, 1);

try {
JsonObject response = TestMultitenancyAPIHelper.createApp(
process.getProcess(),
new TenantIdentifier(null, null, null),
"a1", null, null, null,
config);
} catch (HttpResponseException e) {
assertEquals(400, e.statusCode);
assertTrue(e.getMessage().contains("Cannot deserialize value `abcd` for property `access_token_validity`"));
}
}
}
Loading