Skip to content

Commit d6feb61

Browse files
committed
fixes tests
1 parent 911ffcc commit d6feb61

File tree

5 files changed

+91
-51
lines changed

5 files changed

+91
-51
lines changed

src/test/java/io/supertokens/test/dashboard/DashboardTest.java

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import io.supertokens.test.TestingProcessManager;
3535
import io.supertokens.test.Utils;
3636
import io.supertokens.test.httpRequest.HttpRequestForTesting;
37-
import io.supertokens.webserver.WebserverAPI;
3837
import org.junit.AfterClass;
3938
import org.junit.Before;
4039
import org.junit.Rule;
@@ -283,7 +282,11 @@ public void testDashboardUsageStats() throws Exception {
283282
null, 1000, 1000, null, Utils.getCdiVersionStringLatestForTests(), "");
284283
assertEquals(3, response.entrySet().size());
285284
assertEquals("OK", response.get("status").getAsString());
286-
assertEquals(0, response.get("features").getAsJsonArray().size());
285+
if (StorageLayer.isInMemDb(process.getProcess())) {
286+
assertEquals(EE_FEATURES.values().length, response.get("features").getAsJsonArray().size());
287+
} else {
288+
assertEquals(0, response.get("features").getAsJsonArray().size());
289+
}
287290
JsonObject usageStats = response.get("usageStats").getAsJsonObject();
288291
JsonArray mauArr = usageStats.get("maus").getAsJsonArray();
289292
assertEquals(1, usageStats.entrySet().size());
@@ -301,7 +304,11 @@ public void testDashboardUsageStats() throws Exception {
301304
null, 1000, 1000, null, Utils.getCdiVersionStringLatestForTests(), "");
302305
assertEquals(3, response.entrySet().size());
303306
assertEquals("OK", response.get("status").getAsString());
304-
assertEquals(0, response.get("features").getAsJsonArray().size());
307+
if (StorageLayer.isInMemDb(process.getProcess())) {
308+
assertEquals(EE_FEATURES.values().length, response.get("features").getAsJsonArray().size());
309+
} else {
310+
assertEquals(0, response.get("features").getAsJsonArray().size());
311+
}
305312
JsonObject usageStats = response.get("usageStats").getAsJsonObject();
306313
JsonArray mauArr = usageStats.get("maus").getAsJsonArray();
307314
assertEquals(1, usageStats.entrySet().size());
@@ -319,10 +326,15 @@ public void testDashboardUsageStats() throws Exception {
319326
null, 1000, 1000, null, Utils.getCdiVersionStringLatestForTests(), "");
320327
assertEquals(3, response.entrySet().size());
321328
assertEquals("OK", response.get("status").getAsString());
322-
assertEquals(1, response.get("features").getAsJsonArray().size());
329+
if (StorageLayer.isInMemDb(process.getProcess())) {
330+
assertEquals(EE_FEATURES.values().length, response.get("features").getAsJsonArray().size());
331+
} else {
332+
assertEquals(1, response.get("features").getAsJsonArray().size());
333+
}
323334
JsonArray featuresArray = response.get("features").getAsJsonArray();
324-
assertEquals(1, featuresArray.size());
325-
assertEquals(EE_FEATURES.DASHBOARD_LOGIN.toString(), featuresArray.get(0).getAsString());
335+
if (!StorageLayer.isInMemDb(process.getProcess())) {
336+
assertEquals(EE_FEATURES.DASHBOARD_LOGIN.toString(), featuresArray.get(0).getAsString());
337+
}
326338
JsonObject usageStats = response.get("usageStats").getAsJsonObject();
327339
JsonObject dashboardLoginObject = usageStats.get("dashboard_login").getAsJsonObject();
328340
assertEquals(2, usageStats.entrySet().size());
@@ -342,10 +354,15 @@ public void testDashboardUsageStats() throws Exception {
342354
null, 1000, 1000, null, Utils.getCdiVersionStringLatestForTests(), "");
343355
assertEquals(3, response.entrySet().size());
344356
assertEquals("OK", response.get("status").getAsString());
345-
assertEquals(1, response.get("features").getAsJsonArray().size());
357+
if (StorageLayer.isInMemDb(process.getProcess())) {
358+
assertEquals(EE_FEATURES.values().length, response.get("features").getAsJsonArray().size());
359+
} else {
360+
assertEquals(1, response.get("features").getAsJsonArray().size());
361+
}
346362
JsonArray featuresArray = response.get("features").getAsJsonArray();
347-
assertEquals(1, featuresArray.size());
348-
assertEquals(EE_FEATURES.DASHBOARD_LOGIN.toString(), featuresArray.get(0).getAsString());
363+
if (!StorageLayer.isInMemDb(process.getProcess())) {
364+
assertEquals(EE_FEATURES.DASHBOARD_LOGIN.toString(), featuresArray.get(0).getAsString());
365+
}
349366
JsonObject usageStats = response.get("usageStats").getAsJsonObject();
350367
JsonObject dashboardLoginObject = usageStats.get("dashboard_login").getAsJsonObject();
351368
assertEquals(2, usageStats.entrySet().size());

src/test/java/io/supertokens/test/dashboard/apis/CreateDashboardUserAPITests.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,6 @@
1616

1717
package io.supertokens.test.dashboard.apis;
1818

19-
import static org.junit.Assert.assertEquals;
20-
import static org.junit.Assert.assertNotNull;
21-
import static org.junit.Assert.assertTrue;
22-
23-
import io.supertokens.utils.SemVer;
24-
import org.junit.AfterClass;
25-
import org.junit.Before;
26-
import org.junit.Rule;
27-
import org.junit.Test;
28-
import org.junit.rules.TestRule;
29-
3019
import com.google.gson.JsonObject;
3120
import io.supertokens.ProcessState.PROCESS_STATE;
3221
import io.supertokens.dashboard.Dashboard;
@@ -37,6 +26,14 @@
3726
import io.supertokens.test.Utils;
3827
import io.supertokens.test.httpRequest.HttpRequestForTesting;
3928
import io.supertokens.test.httpRequest.HttpResponseException;
29+
import io.supertokens.utils.SemVer;
30+
import org.junit.AfterClass;
31+
import org.junit.Before;
32+
import org.junit.Rule;
33+
import org.junit.Test;
34+
import org.junit.rules.TestRule;
35+
36+
import static org.junit.Assert.*;
4037

4138
public class CreateDashboardUserAPITests {
4239
@Rule
@@ -388,8 +385,9 @@ public void testCreatingAUserAfterCrossingTheFreeUserThreshold() throws Exceptio
388385
HttpRequestForTesting.sendJsonPOSTRequest(process.getProcess(), "",
389386
"http://localhost:3567/recipe/dashboard/user", requestBody, 5000, 1000, null,
390387
SemVer.v2_18.get(), "dashboard");
391-
throw new Exception("Should never come here");
388+
assert StorageLayer.isInMemDb(process.main);
392389
} catch (HttpResponseException e) {
390+
assert !StorageLayer.isInMemDb(process.main);
393391
assertTrue(e.statusCode == 402 && e.getMessage().equals(
394392
"Http error. Status Code: 402. Message:"
395393
+

src/test/java/io/supertokens/test/dashboard/apis/SignInAPITest.java

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,6 @@
1616

1717
package io.supertokens.test.dashboard.apis;
1818

19-
import static org.junit.Assert.assertEquals;
20-
import static org.junit.Assert.assertNotNull;
21-
import static org.junit.Assert.assertTrue;
22-
23-
import io.supertokens.utils.SemVer;
24-
import org.junit.AfterClass;
25-
import org.junit.Before;
26-
import org.junit.Rule;
27-
import org.junit.Test;
28-
import org.junit.rules.TestRule;
29-
3019
import com.google.gson.JsonObject;
3120
import io.supertokens.ProcessState.PROCESS_STATE;
3221
import io.supertokens.dashboard.Dashboard;
@@ -39,6 +28,14 @@
3928
import io.supertokens.test.TestingProcessManager;
4029
import io.supertokens.test.Utils;
4130
import io.supertokens.test.httpRequest.HttpRequestForTesting;
31+
import io.supertokens.utils.SemVer;
32+
import org.junit.AfterClass;
33+
import org.junit.Before;
34+
import org.junit.Rule;
35+
import org.junit.Test;
36+
import org.junit.rules.TestRule;
37+
38+
import static org.junit.Assert.*;
4239

4340
public class SignInAPITest {
4441
@Rule
@@ -56,7 +53,7 @@ public void beforeEach() {
5653

5754
@Test
5855
public void testSigningInAUserAndVerifyingTheirSession() throws Exception {
59-
String[] args = { "../" };
56+
String[] args = {"../"};
6057

6158
TestingProcessManager.TestingProcess process = TestingProcessManager.start(args);
6259
assertNotNull(process.checkOrWaitForEvent(PROCESS_STATE.STARTED));
@@ -92,7 +89,7 @@ public void testSigningInAUserAndVerifyingTheirSession() throws Exception {
9289

9390
@Test
9491
public void testSigningInASuspendedUser() throws Exception {
95-
String[] args = { "../" };
92+
String[] args = {"../"};
9693

9794
TestingProcessManager.TestingProcess process = TestingProcessManager.start(args);
9895
assertNotNull(process.checkOrWaitForEvent(PROCESS_STATE.STARTED));
@@ -140,11 +137,16 @@ public void testSigningInASuspendedUser() throws Exception {
140137
"http://localhost:3567/recipe/dashboard/signin", requestBody, 1000, 1000, null,
141138
SemVer.v2_18.get(), "dashboard");
142139
assertEquals(2, response.entrySet().size());
143-
assertEquals("USER_SUSPENDED_ERROR", response.get("status").getAsString());
144-
assertEquals(
145-
"User is currently suspended, please sign in with another account, or reactivate the SuperTokens " +
146-
"core license key",
147-
response.get("message").getAsString());
140+
if (StorageLayer.isInMemDb(process.getProcess())) {
141+
assertEquals("OK", response.get("status").getAsString());
142+
} else {
143+
assertEquals("USER_SUSPENDED_ERROR", response.get("status").getAsString());
144+
assertEquals(
145+
"User is currently suspended, please sign in with another account, or reactivate the " +
146+
"SuperTokens " +
147+
"core license key",
148+
response.get("message").getAsString());
149+
}
148150
}
149151

150152
process.kill();

src/test/java/io/supertokens/test/multitenant/api/TestLicenseBehaviour.java

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,17 @@ public void testAllowLicenseRemovalForCoreWithMultitenancy() throws Exception {
9797
TestMultitenancyAPIHelper.removeLicense(process.getProcess());
9898

9999
// Sign up and get user info
100-
JsonObject userInfo = TestMultitenancyAPIHelper.epSignUp(new TenantIdentifier(null, "a1", "t1"), "[email protected]", "password", process.getProcess());
101-
JsonObject userInfo2 = TestMultitenancyAPIHelper.getEpUserById(new TenantIdentifier(null, "a1", "t1"), userInfo.get("id").getAsString(), process.getProcess());
100+
JsonObject userInfo = TestMultitenancyAPIHelper.epSignUp(new TenantIdentifier(null, "a1", "t1"),
101+
"[email protected]", "password", process.getProcess());
102+
JsonObject userInfo2 = TestMultitenancyAPIHelper.getEpUserById(new TenantIdentifier(null, "a1", "t1"),
103+
userInfo.get("id").getAsString(), process.getProcess());
102104
assertEquals(userInfo, userInfo2);
103105
}
104106

105107
@Test
106108
public void testThatCreationOfNewTenantIsNotAllowedAfterLicenseRemoval() throws Exception {
107-
if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) {
109+
if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL ||
110+
StorageLayer.isInMemDb(process.getProcess())) {
108111
return;
109112
}
110113

@@ -136,7 +139,10 @@ public void testThatCreationOfNewTenantIsNotAllowedAfterLicenseRemoval() throws
136139
coreConfig);
137140
fail();
138141
} catch (HttpResponseException e) {
139-
assertEquals("Http error. Status Code: 402. Message: Cannot use feature: multi_tenancy, because the license key is missing, or doesn't have this feature enabled.", e.getMessage());
142+
assertEquals(
143+
"Http error. Status Code: 402. Message: Cannot use feature: multi_tenancy, because the license " +
144+
"key is missing, or doesn't have this feature enabled.",
145+
e.getMessage());
140146
}
141147
}
142148

@@ -196,13 +202,17 @@ public void testThatCoreCanRestartWithAllTheTenantsWithoutLicenseKey() throws Ex
196202
coreConfig);
197203
fail();
198204
} catch (HttpResponseException e) {
199-
assertEquals("Http error. Status Code: 402. Message: Cannot use feature: multi_tenancy, because the license key is missing, or doesn't have this feature enabled.", e.getMessage());
205+
assertEquals(
206+
"Http error. Status Code: 402. Message: Cannot use feature: multi_tenancy, because the license " +
207+
"key is missing, or doesn't have this feature enabled.",
208+
e.getMessage());
200209
}
201210
}
202211

203212
@Test
204213
public void testThatAddingThirdPartyConfigIsNotAllowedAfterLicenseRemoval() throws Exception {
205-
if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) {
214+
if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL ||
215+
StorageLayer.isInMemDb(process.getProcess())) {
206216
return;
207217
}
208218

@@ -235,13 +245,17 @@ public void testThatAddingThirdPartyConfigIsNotAllowedAfterLicenseRemoval() thro
235245
process.getProcess());
236246
fail();
237247
} catch (HttpResponseException e) {
238-
assertEquals("Http error. Status Code: 402. Message: Cannot use feature: multi_tenancy, because the license key is missing, or doesn't have this feature enabled.", e.getMessage());
248+
assertEquals(
249+
"Http error. Status Code: 402. Message: Cannot use feature: multi_tenancy, because the license " +
250+
"key is missing, or doesn't have this feature enabled.",
251+
e.getMessage());
239252
}
240253
}
241254

242255
@Test
243256
public void testThatAssociationOfUserWithAnotherTenantIsNotAllowedAfterLicenseRemoval() throws Exception {
244-
if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) {
257+
if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL ||
258+
StorageLayer.isInMemDb(process.getProcess())) {
245259
return;
246260
}
247261

@@ -271,13 +285,18 @@ public void testThatAssociationOfUserWithAnotherTenantIsNotAllowedAfterLicenseRe
271285

272286
TestMultitenancyAPIHelper.removeLicense(process.getProcess());
273287

274-
JsonObject userInfo = TestMultitenancyAPIHelper.epSignUp(new TenantIdentifier(null, "a1", "t1"), "[email protected]", "password", process.getProcess());
288+
JsonObject userInfo = TestMultitenancyAPIHelper.epSignUp(new TenantIdentifier(null, "a1", "t1"),
289+
"[email protected]", "password", process.getProcess());
275290

276291
try {
277-
TestMultitenancyAPIHelper.associateUserToTenant(new TenantIdentifier(null, "a1", "t2"), userInfo.get("id").getAsString(), process.getProcess());
292+
TestMultitenancyAPIHelper.associateUserToTenant(new TenantIdentifier(null, "a1", "t2"),
293+
userInfo.get("id").getAsString(), process.getProcess());
278294
fail();
279295
} catch (HttpResponseException e) {
280-
assertEquals("Http error. Status Code: 402. Message: Cannot use feature: multi_tenancy, because the license key is missing, or doesn't have this feature enabled.", e.getMessage());
296+
assertEquals(
297+
"Http error. Status Code: 402. Message: Cannot use feature: multi_tenancy, because the license " +
298+
"key is missing, or doesn't have this feature enabled.",
299+
e.getMessage());
281300
}
282301
}
283302

@@ -308,7 +327,8 @@ public void testUpdationOfBaseTenantIsAllowedWithoutLicense() throws Exception {
308327
TestMultitenancyAPIHelper.removeLicense(process.getProcess());
309328

310329
JsonObject config = new JsonObject();
311-
TestMultitenancyAPIHelper.createConnectionUriDomain(process.main, new TenantIdentifier(null, null, null), null, true, true, true, new JsonObject() );
330+
TestMultitenancyAPIHelper.createConnectionUriDomain(process.main, new TenantIdentifier(null, null, null), null,
331+
true, true, true, new JsonObject());
312332
TestMultitenancyAPIHelper.addOrUpdateThirdPartyProviderConfig(
313333
new TenantIdentifier(null, null, null),
314334
new ThirdPartyConfig.Provider(

src/test/java/io/supertokens/test/totp/TotpLicenseTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ public void testTotpWithoutLicense() throws Exception {
8888
if (result == null) {
8989
return;
9090
}
91+
if (StorageLayer.isInMemDb(result.process.getProcess())) {
92+
return;
93+
}
9194
Main main = result.process.getProcess();
9295

9396
// Create device

0 commit comments

Comments
 (0)