-
Notifications
You must be signed in to change notification settings - Fork 540
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,15 @@ | |
import io.supertokens.ActiveUsers; | ||
import io.supertokens.Main; | ||
import io.supertokens.ProcessState; | ||
import io.supertokens.featureflag.EE_FEATURES; | ||
import io.supertokens.featureflag.FeatureFlagTestContent; | ||
import io.supertokens.pluginInterface.STORAGE_TYPE; | ||
import io.supertokens.pluginInterface.multitenancy.TenantIdentifier; | ||
import io.supertokens.storageLayer.StorageLayer; | ||
import io.supertokens.test.httpRequest.HttpRequestForTesting; | ||
import io.supertokens.test.httpRequest.HttpResponseException; | ||
import io.supertokens.test.multitenant.api.TestMultitenancyAPIHelper; | ||
import io.supertokens.utils.SemVer; | ||
import org.junit.AfterClass; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
|
@@ -212,4 +217,80 @@ public void activeUserCountAPITest() throws Exception { | |
assert res.get("count").getAsInt() == 2; | ||
} | ||
|
||
@Test | ||
public void testThatActiveUserDataIsSavedInPublicTenantStorage() throws Exception { | ||
String[] args = {"../"}; | ||
|
||
TestingProcessManager.TestingProcess process = TestingProcessManager.start(args); | ||
FeatureFlagTestContent.getInstance(process.getProcess()) | ||
.setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[]{EE_FEATURES.MULTI_TENANCY}); | ||
process.startProcess(); | ||
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED)); | ||
|
||
if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) { | ||
return; | ||
} | ||
|
||
{ // Create a tenant | ||
JsonObject coreConfig = new JsonObject(); | ||
|
||
StorageLayer.getStorage(new TenantIdentifier(null, null, null), process.getProcess()) | ||
.modifyConfigToAddANewUserPoolForTesting(coreConfig, 1); | ||
|
||
TestMultitenancyAPIHelper.createTenant( | ||
process.getProcess(), | ||
new TenantIdentifier(null, null, null), | ||
"t1", true, true, true, | ||
coreConfig); | ||
} | ||
|
||
{ // no active users yet | ||
HashMap<String, String> params = new HashMap<>(); | ||
params.put("since", "0"); | ||
JsonObject res = HttpRequestForTesting.sendGETRequest( | ||
process.getProcess(), | ||
"", | ||
"http://localhost:3567/users/count/active", | ||
params, | ||
1000, | ||
1000, | ||
null, | ||
Utils.getCdiVersionStringLatestForTests(), | ||
""); | ||
|
||
assert res.get("status").getAsString().equals("OK"); | ||
assert res.get("count").getAsInt() == 0; | ||
} | ||
|
||
{ // Sign up, which updates active users | ||
JsonObject responseBody = new JsonObject(); | ||
responseBody.addProperty("email", "[email protected]"); | ||
responseBody.addProperty("password", "validPass123"); | ||
|
||
JsonObject signInResponse = HttpRequestForTesting.sendJsonPOSTRequest(process.getProcess(), "", | ||
"http://localhost:3567/t1/recipe/signup", responseBody, 1000, 1000, null, SemVer.v4_0.get(), | ||
"emailpassword"); | ||
} | ||
|
||
{ // 1 active user in the public tenant | ||
HashMap<String, String> params = new HashMap<>(); | ||
params.put("since", "0"); | ||
JsonObject res = HttpRequestForTesting.sendGETRequest( | ||
process.getProcess(), | ||
"", | ||
"http://localhost:3567/users/count/active", | ||
params, | ||
1000, | ||
1000, | ||
null, | ||
Utils.getCdiVersionStringLatestForTests(), | ||
""); | ||
|
||
assert res.get("status").getAsString().equals("OK"); | ||
assert res.get("count").getAsInt() == 1; | ||
} | ||
|
||
process.kill(); | ||
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STOPPED)); | ||
} | ||
} |