Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions src/test/java/io/supertokens/test/CDIVersionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
import io.supertokens.featureflag.FeatureFlagTestContent;
import io.supertokens.httpRequest.HttpRequest;
import io.supertokens.multitenancy.Multitenancy;
import io.supertokens.pluginInterface.STORAGE_TYPE;
import io.supertokens.pluginInterface.multitenancy.*;
import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException;
import io.supertokens.storageLayer.StorageLayer;
import io.supertokens.test.httpRequest.HttpRequestForTesting;
import io.supertokens.utils.SemVer;
import io.supertokens.webserver.Webserver;
Expand Down Expand Up @@ -234,6 +236,10 @@ public void testCDIVersionWorksPerApp() throws Exception {
.setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[]{EE_FEATURES.MULTI_TENANCY});
process.startProcess();

if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) {
return;
}

assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED));

Webserver.getInstance(process.getProcess()).addAPI(new WebserverAPI(process.getProcess(), "") {
Expand Down
109 changes: 109 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 @@ -25,6 +25,7 @@
import io.supertokens.multitenancy.exception.BadPermissionException;
import io.supertokens.multitenancy.exception.CannotModifyBaseConfigException;
import io.supertokens.pluginInterface.STORAGE_TYPE;
import io.supertokens.pluginInterface.Storage;
import io.supertokens.pluginInterface.exceptions.InvalidConfigException;
import io.supertokens.pluginInterface.exceptions.StorageQueryException;
import io.supertokens.pluginInterface.multitenancy.TenantIdentifier;
Expand All @@ -36,6 +37,7 @@
import io.supertokens.test.httpRequest.HttpRequestForTesting;
import io.supertokens.test.httpRequest.HttpResponseException;
import io.supertokens.thirdparty.InvalidProviderConfigException;
import io.supertokens.utils.SemVer;
import io.supertokens.webserver.Webserver;
import io.supertokens.webserver.WebserverAPI;
import jakarta.servlet.ServletException;
Expand Down Expand Up @@ -370,4 +372,111 @@ public void testDifferentValuesForAppIdThatShouldNotWork() throws Exception {
}
}
}

@Test
public void testCreationOfAppWithWrongDbSettingsAndLaterUpdateIt() throws Exception {
if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) {
return;
}

JsonObject coreConfig = new JsonObject();

StorageLayer.getStorage(new TenantIdentifier(null, null, null), process.getProcess())
.modifyConfigToAddANewUserPoolForTesting(coreConfig, 1000); // This db should not exist

try {
TestMultitenancyAPIHelper.createApp(
process.getProcess(),
new TenantIdentifier(null, null, null),
"a1", true, true, true,
coreConfig);
fail();
} catch (HttpResponseException e) {
assertEquals(500, e.statusCode);
}

// Ensure storage is created
Storage errorStorage = StorageLayer.getStorage(new TenantIdentifier(null, "a1", null), process.getProcess());
assertNotNull(errorStorage);

{
JsonObject result = TestMultitenancyAPIHelper.listApps(new TenantIdentifier(null, null, null),
process.getProcess());
assertTrue(result.has("apps"));

boolean found = false;

for (JsonElement app : result.get("apps").getAsJsonArray()) {
JsonObject appObj = app.getAsJsonObject();

if (appObj.get("appId").getAsString().equals("a1")) {
found = true;

for (JsonElement tenant : appObj.get("tenants").getAsJsonArray()) {
JsonObject tenantObj = tenant.getAsJsonObject();
assertTrue(tenantObj.get("emailPassword").getAsJsonObject().get("enabled").getAsBoolean());
assertTrue(tenantObj.get("thirdParty").getAsJsonObject().get("enabled").getAsBoolean());
assertTrue(tenantObj.get("passwordless").getAsJsonObject().get("enabled").getAsBoolean());
assertEquals(coreConfig, tenantObj.get("coreConfig").getAsJsonObject());
}
}
}

assertTrue(found);
}

{ // test that api fails
try {
TestMultitenancyAPIHelper.epSignUp(new TenantIdentifier(null, "a1", null),
"test@example.com", "password", process.getProcess());
fail();
} catch (HttpResponseException e) {
assertEquals(500, e.statusCode);
}
}

StorageLayer.getStorage(new TenantIdentifier(null, null, null), process.getProcess())
.modifyConfigToAddANewUserPoolForTesting(coreConfig, 1); // This db should exist

TestMultitenancyAPIHelper.createApp(
process.getProcess(),
new TenantIdentifier(null, null, null),
"a1", true, true, true,
coreConfig);

{
JsonObject result = TestMultitenancyAPIHelper.listApps(new TenantIdentifier(null, null, null),
process.getProcess());
assertTrue(result.has("apps"));

boolean found = false;

for (JsonElement app : result.get("apps").getAsJsonArray()) {
JsonObject appObj = app.getAsJsonObject();

if (appObj.get("appId").getAsString().equals("a1")) {
found = true;

for (JsonElement tenant : appObj.get("tenants").getAsJsonArray()) {
JsonObject tenantObj = tenant.getAsJsonObject();
assertTrue(tenantObj.get("emailPassword").getAsJsonObject().get("enabled").getAsBoolean());
assertTrue(tenantObj.get("thirdParty").getAsJsonObject().get("enabled").getAsBoolean());
assertTrue(tenantObj.get("passwordless").getAsJsonObject().get("enabled").getAsBoolean());
assertEquals(coreConfig, tenantObj.get("coreConfig").getAsJsonObject());
}
}
}

assertTrue(found);
}

Storage workingStorage = StorageLayer.getStorage(new TenantIdentifier(null, "a1", null), process.getProcess());
assertNotNull(workingStorage);
assertNotEquals(errorStorage, workingStorage);

{ // test that api passes
TestMultitenancyAPIHelper.epSignUp(new TenantIdentifier(null, "a1", null),
"test@example.com", "password", process.getProcess());
}
}
}