Skip to content

Commit

Permalink
fix: more validation
Browse files Browse the repository at this point in the history
  • Loading branch information
sattvikc committed Dec 20, 2023
1 parent 2019a95 commit 7397f79
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ protected void handle(HttpServletRequest req, TenantIdentifier sourceTenantIdent
JsonObject coreConfig, HttpServletResponse resp)
throws ServletException, IOException {

if (hasFirstFactors && firstFactors != null && firstFactors.length == 0) {
throw new ServletException(new BadRequestException("firstFactors cannot be empty"));
}

if (hasRequiredSecondaryFactors && requiredSecondaryFactors != null && requiredSecondaryFactors.length == 0) {
throw new ServletException(new BadRequestException("requiredSecondaryFactors cannot be empty"));
}

TenantConfig tenantConfig = Multitenancy.getTenantInfo(main,
new TenantIdentifier(targetTenantIdentifier.getConnectionUriDomain(), targetTenantIdentifier.getAppId(),
targetTenantIdentifier.getTenantId()));
Expand Down
34 changes: 34 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 @@ -753,6 +753,23 @@ public void testFirstFactorArrayValueValidationBasedOnDisabledRecipe() throws Ex
false, null, false, null,
config, SemVer.v5_0);

{
try {
TestMultitenancyAPIHelper.createApp(
process.getProcess(),
new TenantIdentifier(null, null, null),
"a1", false, null, null,
true, new String[]{}, false, null,
config, SemVer.v5_0);
fail();
} catch (HttpResponseException e) {
assertEquals(400, e.statusCode);
assertEquals(
"Http error. Status Code: 400. Message: firstFactors cannot be empty",
e.getMessage());
}
}

{
String[] factors = new String[]{"emailpassword", "custom"};
try {
Expand Down Expand Up @@ -885,6 +902,23 @@ public void testRequiredSecondaryFactorArrayValueValidationBasedOnDisabledRecipe
false, null, false, null,
config, SemVer.v5_0);

{
try {
TestMultitenancyAPIHelper.createApp(
process.getProcess(),
new TenantIdentifier(null, null, null),
"a1", false, null, null,
false, null, true, new String[]{},
config, SemVer.v5_0);
fail();
} catch (HttpResponseException e) {
assertEquals(400, e.statusCode);
assertEquals(
"Http error. Status Code: 400. Message: requiredSecondaryFactors cannot be empty",
e.getMessage());
}
}

{
String[] factors = new String[]{"emailpassword", "custom"};
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ public void testFirstFactorsArray() throws Exception {
response = TestMultitenancyAPIHelper.createTenant(
process.getProcess(),
new TenantIdentifier(null, null, null),
"t1", null, null, null,
"t1", null, null, true,
true, new String[]{"otp-phone"}, false, null,
config, SemVer.v5_0);
assertFalse(response.get("createdNew").getAsBoolean());
Expand Down Expand Up @@ -420,7 +420,7 @@ public void testFirstFactorsArray() throws Exception {
response = TestMultitenancyAPIHelper.createTenant(
process.getProcess(),
new TenantIdentifier(null, null, null),
"t1", null, null, null,
"t1", true, null, true,
true, firstFactors, false, null,
config, SemVer.v5_0);
assertFalse(response.get("createdNew").getAsBoolean());
Expand Down Expand Up @@ -470,7 +470,7 @@ public void testRequiredSecondaryFactorsArray() throws Exception {
response = TestMultitenancyAPIHelper.createTenant(
process.getProcess(),
new TenantIdentifier(null, null, null),
"t1", null, null, null,
"t1", null, null, true,
false, null, true, new String[]{"otp-phone"},
config, SemVer.v5_0);
assertFalse(response.get("createdNew").getAsBoolean());
Expand Down Expand Up @@ -516,7 +516,7 @@ public void testRequiredSecondaryFactorsArray() throws Exception {
response = TestMultitenancyAPIHelper.createTenant(
process.getProcess(),
new TenantIdentifier(null, null, null),
"t1", null, null, null,
"t1", true, null, true,
false, null, true, requiredSecondaryFactors,
config, SemVer.v5_0);
assertFalse(response.get("createdNew").getAsBoolean());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@

public class GenerateTenantConfig {
private static final String[] FACTORS = new String[]{
"emailpassword",
"thirdparty",
"otp-email",
"otp-phone",
"link-email",
"link-phone",
"emailpassword1",
"thirdparty1",
"otp-email1",
"otp-phone1",
"link-email1",
"link-phone1",
"totp",
"biometric",
"custom"
Expand Down

0 comments on commit 7397f79

Please sign in to comment.