|
21 | 21 | import io.supertokens.emailpassword.EmailPassword;
|
22 | 22 | import io.supertokens.featureflag.EE_FEATURES;
|
23 | 23 | import io.supertokens.featureflag.FeatureFlagTestContent;
|
| 24 | +import io.supertokens.passwordless.Passwordless; |
24 | 25 | import io.supertokens.pluginInterface.STORAGE_TYPE;
|
25 | 26 | import io.supertokens.pluginInterface.authRecipe.AuthRecipeUserInfo;
|
26 | 27 | import io.supertokens.pluginInterface.emailpassword.exceptions.UnknownUserIdException;
|
@@ -83,4 +84,70 @@ public void testUpdatePasswordWithDifferentValidUserId() throws Exception {
|
83 | 84 | process.kill();
|
84 | 85 | assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STOPPED));
|
85 | 86 | }
|
| 87 | + |
| 88 | + @Test |
| 89 | + public void testPasswordlessUserWithSameEmail() throws Exception { |
| 90 | + String[] args = {"../"}; |
| 91 | + TestingProcessManager.TestingProcess process = TestingProcessManager.start(args, false); |
| 92 | + FeatureFlagTestContent.getInstance(process.getProcess()) |
| 93 | + .setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[]{ |
| 94 | + EE_FEATURES.ACCOUNT_LINKING, EE_FEATURES.MULTI_TENANCY}); |
| 95 | + process.startProcess(); |
| 96 | + assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED)); |
| 97 | + |
| 98 | + if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) { |
| 99 | + return; |
| 100 | + } |
| 101 | + |
| 102 | + AuthRecipeUserInfo user1 = EmailPassword. signUp( process. getProcess(), "[email protected]", "password"); |
| 103 | + Passwordless.CreateCodeResponse code = Passwordless.createCode(process.getProcess(), null, "+919876543210", |
| 104 | + null, null); |
| 105 | + AuthRecipeUserInfo user2 = Passwordless.consumeCode(process.getProcess(), code.deviceId, code.deviceIdHash, code.userInputCode, null).user; |
| 106 | + |
| 107 | + AuthRecipe.createPrimaryUser(process.getProcess(), user1.getSupertokensUserId()); |
| 108 | + AuthRecipe.linkAccounts(process.getProcess(), user2.getSupertokensUserId(), user1.getSupertokensUserId()); |
| 109 | + |
| 110 | + Passwordless. CreateCodeResponse code1 = Passwordless. createCode( process. getProcess(), "[email protected]", null, |
| 111 | + null, null); |
| 112 | + AuthRecipeUserInfo user3 = Passwordless.consumeCode(process.getProcess(), code1.deviceId, code1.deviceIdHash, code1.userInputCode, null).user; |
| 113 | + |
| 114 | + process.kill(); |
| 115 | + assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STOPPED)); |
| 116 | + } |
| 117 | + |
| 118 | + @Test |
| 119 | + public void testPasswordlessUsersLinked() throws Exception { |
| 120 | + String[] args = {"../"}; |
| 121 | + TestingProcessManager.TestingProcess process = TestingProcessManager.start(args, false); |
| 122 | + FeatureFlagTestContent.getInstance(process.getProcess()) |
| 123 | + .setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[]{ |
| 124 | + EE_FEATURES.ACCOUNT_LINKING, EE_FEATURES.MULTI_TENANCY}); |
| 125 | + process.startProcess(); |
| 126 | + assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED)); |
| 127 | + |
| 128 | + if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) { |
| 129 | + return; |
| 130 | + } |
| 131 | + |
| 132 | + Passwordless. CreateCodeResponse code1 = Passwordless. createCode( process. getProcess(), "[email protected]", null, |
| 133 | + null, null); |
| 134 | + AuthRecipeUserInfo user1 = Passwordless.consumeCode(process.getProcess(), code1.deviceId, code1.deviceIdHash, code1.userInputCode, null).user; |
| 135 | + |
| 136 | + Thread.sleep(50); |
| 137 | + |
| 138 | + Passwordless.CreateCodeResponse code2 = Passwordless.createCode(process.getProcess(), null, "+919876543210", |
| 139 | + null, null); |
| 140 | + AuthRecipeUserInfo user2 = Passwordless.consumeCode(process.getProcess(), code2.deviceId, code2.deviceIdHash, code2.userInputCode, null).user; |
| 141 | + |
| 142 | + AuthRecipe.createPrimaryUser(process.getProcess(), user1.getSupertokensUserId()); |
| 143 | + AuthRecipe.linkAccounts(process.getProcess(), user2.getSupertokensUserId(), user1.getSupertokensUserId()); |
| 144 | + |
| 145 | + Passwordless.CreateCodeResponse code3 = Passwordless.createCode(process.getProcess(), null, "+919876543210", |
| 146 | + null, null); |
| 147 | + AuthRecipeUserInfo user3 = Passwordless.consumeCode(process.getProcess(), code3.deviceId, code3.deviceIdHash, code3.userInputCode, null).user; |
| 148 | + |
| 149 | + process.kill(); |
| 150 | + assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STOPPED)); |
| 151 | + |
| 152 | + } |
86 | 153 | }
|
0 commit comments