Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixes storage handling for non-auth recipes #203

Merged
merged 7 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ public static String getQueryToCreateUserRolesTable(Start start) {
+ "role VARCHAR(255) NOT NULL,"
rishabhpoddar marked this conversation as resolved.
Show resolved Hide resolved
+ "CONSTRAINT " + Utils.getConstraintName(schema, tableName, null, "pkey")
+ " PRIMARY KEY(app_id, tenant_id, user_id, role),"
+ "CONSTRAINT " + Utils.getConstraintName(schema, tableName, "role", "fkey")
+ " FOREIGN KEY(app_id, role)"
+ " REFERENCES " + getConfig(start).getRolesTable() + "(app_id, role) ON DELETE CASCADE,"
+ "CONSTRAINT " + Utils.getConstraintName(schema, tableName, "tenant_id", "fkey")
rishabhpoddar marked this conversation as resolved.
Show resolved Hide resolved
+ " FOREIGN KEY (app_id, tenant_id)"
+ " REFERENCES " + Config.getConfig(start).getTenantsTable() + "(app_id, tenant_id) ON DELETE CASCADE"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void canLinkFailsIfTryingToLinkUsersAcrossDifferentStorageLayers() throws
AuthRecipe.createPrimaryUser(process.main, user1.getSupertokensUserId());

AuthRecipeUserInfo user2 = EmailPassword.signUp(
tenantIdentifier.withStorage(StorageLayer.getStorage(tenantIdentifier, process.main)),
tenantIdentifier, (StorageLayer.getStorage(tenantIdentifier, process.main)),
process.getProcess(), "[email protected]", "abcd1234");

try {
Expand Down Expand Up @@ -135,7 +135,7 @@ public void canLinkFailsIfTryingToLinkUsersAcrossDifferentStorageLayers() throws
);

AuthRecipeUserInfo user3 = EmailPassword.signUp(
tenantIdentifier.withStorage(StorageLayer.getStorage(tenantIdentifier, process.main)),
tenantIdentifier, (StorageLayer.getStorage(tenantIdentifier, process.main)),
process.getProcess(), "[email protected]", "abcd1234");

Map<String, String> params = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

import io.supertokens.pluginInterface.Storage;
import io.supertokens.pluginInterface.multitenancy.*;
import org.junit.AfterClass;
import org.junit.Before;
Expand Down Expand Up @@ -152,8 +153,8 @@ public void testDownTimeWhenChangingConnectionPoolSize() throws Exception {
es.execute(() -> {
try {
TenantIdentifier t1 = new TenantIdentifier(null, null, "t1");
TenantIdentifierWithStorage t1WithStorage = t1.withStorage(StorageLayer.getStorage(t1, process.getProcess()));
ThirdParty.signInUp(t1WithStorage, process.getProcess(), "google", "googleid"+ finalI, "user" +
Storage t1WithStorage = (StorageLayer.getStorage(t1, process.getProcess()));
ThirdParty.signInUp(t1, t1WithStorage, process.getProcess(), "google", "googleid"+ finalI, "user" +
finalI + "@example.com");

if (firstErrorTime.get() != -1 && successAfterErrorTime.get() == -1) {
Expand Down Expand Up @@ -353,8 +354,8 @@ public void testIdleConnectionTimeout() throws Exception {
es.execute(() -> {
try {
TenantIdentifier t1 = new TenantIdentifier(null, null, "t1");
TenantIdentifierWithStorage t1WithStorage = t1.withStorage(StorageLayer.getStorage(t1, process.getProcess()));
ThirdParty.signInUp(t1WithStorage, process.getProcess(), "google", "googleid"+ finalI, "user" +
Storage t1WithStorage = (StorageLayer.getStorage(t1, process.getProcess()));
ThirdParty.signInUp(t1, t1WithStorage, process.getProcess(), "google", "googleid"+ finalI, "user" +
finalI + "@example.com");

} catch (StorageQueryException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ public void testTenantCreationAndThenDbDownDbThrowsErrorInRecipesAndDoesntAffect
MultitenancyHelper.getInstance(process.getProcess()).refreshTenantsInCoreBasedOnChangesInCoreConfigOrIfTenantListChanged(true);

try {
EmailPassword.signIn(tid.withStorage(StorageLayer.getStorage(tid, process.getProcess())),
EmailPassword.signIn(tid, (StorageLayer.getStorage(tid, process.getProcess())),
process.getProcess(), "", "");
fail();
} catch (StorageQueryException e) {
Expand All @@ -801,7 +801,7 @@ public void testTenantCreationAndThenDbDownDbThrowsErrorInRecipesAndDoesntAffect
// we do this again just to check that if this function is called again, it fails again and there is no
// side effect of calling the above function
try {
EmailPassword.signIn(tid.withStorage(StorageLayer.getStorage(tid, process.getProcess())),
EmailPassword.signIn(tid, (StorageLayer.getStorage(tid, process.getProcess())),
process.getProcess(), "", "");
fail();
} catch (StorageQueryException e) {
Expand Down Expand Up @@ -830,7 +830,7 @@ public void testTenantCreationAndThenDbDownDbThrowsErrorInRecipesAndDoesntAffect

TenantIdentifier tid = new TenantIdentifier("abc", null, null);
try {
EmailPassword.signIn(tid.withStorage(StorageLayer.getStorage(tid, process.getProcess())),
EmailPassword.signIn(tid, (StorageLayer.getStorage(tid, process.getProcess())),
process.getProcess(), "", "");
fail();
} catch (StorageQueryException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.supertokens.multitenancy.Multitenancy;
import io.supertokens.multitenancy.exception.BadPermissionException;
import io.supertokens.multitenancy.exception.CannotModifyBaseConfigException;
import io.supertokens.pluginInterface.Storage;
import io.supertokens.pluginInterface.authRecipe.AuthRecipeUserInfo;
import io.supertokens.pluginInterface.exceptions.InvalidConfigException;
import io.supertokens.pluginInterface.exceptions.StorageQueryException;
Expand Down Expand Up @@ -86,13 +87,13 @@ public void testUsersWorkAfterUserPoolIdChanges() throws Exception {
coreConfig
), false);

TenantIdentifierWithStorage tenantIdentifierWithStorage = tenantIdentifier.withStorage(
Storage tenantIdentifierWithStorage = (
StorageLayer.getStorage(tenantIdentifier, process.getProcess()));

String userPoolId = tenantIdentifierWithStorage.getStorage().getUserPoolId();
String userPoolId = tenantIdentifierWithStorage.getUserPoolId();

AuthRecipeUserInfo userInfo = EmailPassword.signUp(
tenantIdentifierWithStorage, process.getProcess(), "[email protected]", "password");
tenantIdentifier, tenantIdentifierWithStorage, process.getProcess(), "[email protected]", "password");

coreConfig.addProperty("postgresql_host", "127.0.0.1");
Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig(
Expand All @@ -103,12 +104,13 @@ public void testUsersWorkAfterUserPoolIdChanges() throws Exception {
coreConfig
), false);

tenantIdentifierWithStorage = tenantIdentifier.withStorage(
tenantIdentifierWithStorage = (
StorageLayer.getStorage(tenantIdentifier, process.getProcess()));
String userPoolId2 = tenantIdentifierWithStorage.getStorage().getUserPoolId();
String userPoolId2 = tenantIdentifierWithStorage.getUserPoolId();
assertNotEquals(userPoolId, userPoolId2);

AuthRecipeUserInfo user2 = EmailPassword.signIn(tenantIdentifierWithStorage, process.getProcess(),
AuthRecipeUserInfo user2 = EmailPassword.signIn(
tenantIdentifier, tenantIdentifierWithStorage, process.getProcess(),
"[email protected]", "password");

assertEquals(userInfo, user2);
Expand All @@ -130,13 +132,13 @@ public void testUsersWorkAfterUserPoolIdChangesAndServerRestart() throws Excepti
coreConfig
), false);

TenantIdentifierWithStorage tenantIdentifierWithStorage = tenantIdentifier.withStorage(
Storage tenantIdentifierWithStorage = (
StorageLayer.getStorage(tenantIdentifier, process.getProcess()));

String userPoolId = tenantIdentifierWithStorage.getStorage().getUserPoolId();
String userPoolId = tenantIdentifierWithStorage.getUserPoolId();

AuthRecipeUserInfo userInfo = EmailPassword.signUp(
tenantIdentifierWithStorage, process.getProcess(), "[email protected]", "password");
tenantIdentifier, tenantIdentifierWithStorage, process.getProcess(), "[email protected]", "password");

coreConfig.addProperty("postgresql_host", "127.0.0.1");
Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig(
Expand All @@ -153,12 +155,13 @@ public void testUsersWorkAfterUserPoolIdChangesAndServerRestart() throws Excepti
this.process = TestingProcessManager.start(args);
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED));

tenantIdentifierWithStorage = tenantIdentifier.withStorage(
tenantIdentifierWithStorage = (
rishabhpoddar marked this conversation as resolved.
Show resolved Hide resolved
StorageLayer.getStorage(tenantIdentifier, process.getProcess()));
String userPoolId2 = tenantIdentifierWithStorage.getStorage().getUserPoolId();
String userPoolId2 = tenantIdentifierWithStorage.getUserPoolId();
assertNotEquals(userPoolId, userPoolId2);

AuthRecipeUserInfo user2 = EmailPassword.signIn(tenantIdentifierWithStorage, process.getProcess(),
AuthRecipeUserInfo user2 = EmailPassword.signIn(
tenantIdentifier, tenantIdentifierWithStorage, process.getProcess(),
"[email protected]",
"password");

Expand Down
Loading