Skip to content

Commit

Permalink
fix: providers non null
Browse files Browse the repository at this point in the history
  • Loading branch information
sattvikc committed Jul 2, 2024
1 parent b8a6215 commit 1b70227
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ static String getQueryToCreateTenantConfigsTable(Start start) {
+ "passwordless_enabled BOOLEAN,"
+ "third_party_enabled BOOLEAN,"
+ "is_first_factors_null BOOLEAN,"
+ "is_third_party_providers_null BOOLEAN,"
+ "PRIMARY KEY (connection_uri_domain, app_id, tenant_id)"
+ ");";
// @formatter:on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,13 @@ public static TenantConfigRowMapper getInstance(ThirdPartyConfig.Provider[] prov
public TenantConfig map(ResultSet result) throws StorageQueryException {
try {
boolean isFirstFactorsNull = result.getBoolean("is_first_factors_null");
boolean isThirdPartyProvidersNull = result.getBoolean("is_third_party_providers_null");

return new TenantConfig(
new TenantIdentifier(result.getString("connection_uri_domain"), result.getString("app_id"), result.getString("tenant_id")),
new EmailPasswordConfig(result.getBoolean("email_password_enabled")),
new ThirdPartyConfig(
result.getBoolean("third_party_enabled"),
providers.length == 0 && isThirdPartyProvidersNull ? null : providers),
providers),
new PasswordlessConfig(result.getBoolean("passwordless_enabled")),
firstFactors.length == 0 && isFirstFactorsNull ? null : firstFactors,
requiredSecondaryFactors.length == 0 ? null : requiredSecondaryFactors,
Expand All @@ -76,7 +75,7 @@ public static TenantConfig[] selectAll(Start start, HashMap<TenantIdentifier, Ha
throws SQLException, StorageQueryException {
String QUERY = "SELECT connection_uri_domain, app_id, tenant_id, core_config, "
+ " email_password_enabled, passwordless_enabled, third_party_enabled, "
+ " is_first_factors_null, is_third_party_providers_null FROM "
+ " is_first_factors_null FROM "
+ Config.getConfig(start).getTenantConfigsTable() + ";";

TenantConfig[] tenantConfigs = execute(start, QUERY, pst -> {}, result -> {
Expand Down Expand Up @@ -109,8 +108,8 @@ public static void create(Start start, Connection sqlCon, TenantConfig tenantCon
String QUERY = "INSERT INTO " + Config.getConfig(start).getTenantConfigsTable()
+ "(connection_uri_domain, app_id, tenant_id, core_config,"
+ " email_password_enabled, passwordless_enabled, third_party_enabled,"
+ " is_first_factors_null, is_third_party_providers_null)"
+ " VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)";
+ " is_first_factors_null)"
+ " VALUES(?, ?, ?, ?, ?, ?, ?, ?)";

update(sqlCon, QUERY, pst -> {
pst.setString(1, tenantConfig.tenantIdentifier.getConnectionUriDomain());
Expand All @@ -121,7 +120,6 @@ public static void create(Start start, Connection sqlCon, TenantConfig tenantCon
pst.setBoolean(6, tenantConfig.passwordlessConfig.enabled);
pst.setBoolean(7, tenantConfig.thirdPartyConfig.enabled);
pst.setBoolean(8, tenantConfig.firstFactors == null);
pst.setBoolean(9, tenantConfig.thirdPartyConfig.providers == null);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void testDefaultTenant() throws InterruptedException, StorageQueryExcepti
assertTrue(baseTenantConfig.emailPasswordConfig.enabled);
assertTrue(baseTenantConfig.passwordlessConfig.enabled);
assertTrue(baseTenantConfig.thirdPartyConfig.enabled);
assertNull(baseTenantConfig.thirdPartyConfig.providers);
assertEquals(0, baseTenantConfig.thirdPartyConfig.providers.length);

process.kill();
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STOPPED));
Expand Down Expand Up @@ -560,7 +560,7 @@ null, null, new JsonObject()
assertTrue(baseTenantConfig.emailPasswordConfig.enabled);
assertTrue(baseTenantConfig.passwordlessConfig.enabled);
assertTrue(baseTenantConfig.thirdPartyConfig.enabled);
assertNull(baseTenantConfig.thirdPartyConfig.providers);
assertEquals(0, baseTenantConfig.thirdPartyConfig.providers.length);

process.kill();
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STOPPED));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void testCreateAppWorks() throws Exception {
JsonObject tenantObj = tenant.getAsJsonObject();
assertEquals(4, tenantObj.entrySet().size());
assertEquals("public", tenantObj.get("tenantId").getAsString());
assertEquals(0, tenantObj.get("thirdParty").getAsJsonObject().entrySet().size());
assertEquals(1, tenantObj.get("thirdParty").getAsJsonObject().entrySet().size());
assertEquals(3, tenantObj.get("firstFactors").getAsJsonArray().size());
assertEquals(coreConfig, tenantObj.get("coreConfig").getAsJsonObject());
}
Expand Down Expand Up @@ -170,7 +170,7 @@ public void testUpdateAppWorks() throws Exception {
JsonObject tenantObj = tenant.getAsJsonObject();
assertEquals(4, tenantObj.entrySet().size());
assertEquals("public", tenantObj.get("tenantId").getAsString());
assertEquals(0, tenantObj.get("thirdParty").getAsJsonObject().entrySet().size());
assertEquals(1, tenantObj.get("thirdParty").getAsJsonObject().entrySet().size());
assertEquals(3, tenantObj.get("firstFactors").getAsJsonArray().size());
assertEquals(coreConfig, tenantObj.get("coreConfig").getAsJsonObject());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void testCreateConnectionUriDomainWorks() throws Exception {
JsonObject tenantObj = tenant.getAsJsonObject();
assertEquals(4, tenantObj.entrySet().size());
assertEquals("public", tenantObj.get("tenantId").getAsString());
assertEquals(0, tenantObj.get("thirdParty").getAsJsonObject().entrySet().size());
assertEquals(1, tenantObj.get("thirdParty").getAsJsonObject().entrySet().size());
assertEquals(3, tenantObj.get("firstFactors").getAsJsonArray().size());
assertEquals(coreConfig, tenantObj.get("coreConfig").getAsJsonObject());
}
Expand Down Expand Up @@ -178,7 +178,7 @@ public void testUpdateConnectionUriDomainWorks() throws Exception {
JsonObject tenantObj = tenant.getAsJsonObject();
assertEquals(4, tenantObj.entrySet().size());
assertEquals("public", tenantObj.get("tenantId").getAsString());
assertEquals(0, tenantObj.get("thirdParty").getAsJsonObject().entrySet().size());
assertEquals(1, tenantObj.get("thirdParty").getAsJsonObject().entrySet().size());
assertEquals(3, tenantObj.get("firstFactors").getAsJsonArray().size());
assertEquals(coreConfig, tenantObj.get("coreConfig").getAsJsonObject());
}
Expand Down Expand Up @@ -237,7 +237,7 @@ public void testUpdateConnectionUriDomainFromSameConnectionUriDomainWorks() thro
JsonObject tenantObj = tenant.getAsJsonObject();
assertEquals(4, tenantObj.entrySet().size());
assertEquals("public", tenantObj.get("tenantId").getAsString());
assertEquals(0, tenantObj.get("thirdParty").getAsJsonObject().entrySet().size());
assertEquals(1, tenantObj.get("thirdParty").getAsJsonObject().entrySet().size());
assertEquals(3, tenantObj.get("firstFactors").getAsJsonArray().size());
assertEquals(coreConfig, tenantObj.get("coreConfig").getAsJsonObject());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void testDefaultStateWhenNothingIsPassedWhileCreatingAppAndTenant_3_0() t
assertEquals("public", tenant.get("tenantId").getAsString());
assertTrue(tenant.has("thirdParty"));
// firstFactors and requiredSecondaryFactors should be null
assertFalse( tenant.get("thirdParty").getAsJsonObject().has("providers"));
assertTrue( tenant.get("thirdParty").getAsJsonObject().has("providers"));
}

createTenant_3_0(process.getProcess(), new TenantIdentifier(null, "a1", null), "t1", null, null, null, new JsonObject());
Expand Down Expand Up @@ -161,7 +161,7 @@ public void testDefaultStateWhenNothingIsPassedWhileCreatingAppAndTenant_3_0() t
assertTrue(tenant.has("thirdParty"));
assertEquals(new JsonArray(), tenant.get("firstFactors").getAsJsonArray());
// requiredSecondaryFactors should be null
assertFalse( tenant.get("thirdParty").getAsJsonObject().has("providers"));
assertTrue( tenant.get("thirdParty").getAsJsonObject().has("providers"));
}
}

Expand Down Expand Up @@ -207,7 +207,7 @@ public void testDefaultStateWhenNothingIsPassedWhileCreatingAppAndTenant_5_0() t
assertEquals("public", tenant.get("tenantId").getAsString());
assertTrue(tenant.has("thirdParty"));
// firstFactors and requiredSecondaryFactors should be null
assertFalse( tenant.get("thirdParty").getAsJsonObject().has("providers"));
assertTrue( tenant.get("thirdParty").getAsJsonObject().has("providers"));
}

createTenant_5_0(process.getProcess(), new TenantIdentifier(null, "a1", null), "t1", null, null, null, false, null, false, null, new JsonObject());
Expand Down Expand Up @@ -248,7 +248,7 @@ public void testDefaultStateWhenNothingIsPassedWhileCreatingAppAndTenant_5_0() t
assertTrue(tenant.has("thirdParty"));
assertEquals(new JsonArray(), tenant.get("firstFactors").getAsJsonArray());
// requiredSecondaryFactors should be null
assertFalse( tenant.get("thirdParty").getAsJsonObject().has("providers"));
assertTrue( tenant.get("thirdParty").getAsJsonObject().has("providers"));
}
}

Expand Down Expand Up @@ -294,7 +294,7 @@ public void testDefaultStateWhenNothingIsPassedWhileCreatingAppAndTenant_5_1() t
assertEquals("public", tenant.get("tenantId").getAsString());
assertTrue(tenant.has("thirdParty"));
// firstFactors and requiredSecondaryFactors should be null
assertFalse( tenant.get("thirdParty").getAsJsonObject().has("providers"));
assertTrue( tenant.get("thirdParty").getAsJsonObject().has("providers"));
}

createTenant_5_1(process.getProcess(), new TenantIdentifier(null, "a1", null), "t1", false, null, false, null, new JsonObject());
Expand Down Expand Up @@ -387,7 +387,7 @@ public void testCreationOfAppAndTenantUsingFirstFactors() throws Exception {
assertTrue(tenant.has("firstFactors"));
assertEquals(2, tenant.get("firstFactors").getAsJsonArray().size());
// requiredSecondaryFactors should be null
assertFalse( tenant.get("thirdParty").getAsJsonObject().has("providers"));
assertTrue( tenant.get("thirdParty").getAsJsonObject().has("providers"));
}

createTenant_5_1(process.getProcess(), new TenantIdentifier(null, "a1", null), "t1", true, new String[]{"emailpassword", "otp-phone"}, false, null, new JsonObject());
Expand Down Expand Up @@ -486,7 +486,7 @@ public void shouldBeAbleToEnableRecipesForTenantCreatedInOlderCDI() throws Excep
assertTrue(tenant.has("firstFactors"));
assertEquals(2, tenant.get("firstFactors").getAsJsonArray().size());
// requiredSecondaryFactors should be null
assertFalse(tenant.get("thirdParty").getAsJsonObject().has("providers"));
assertTrue(tenant.get("thirdParty").getAsJsonObject().has("providers"));
}
}

Expand Down

0 comments on commit 1b70227

Please sign in to comment.