-
Notifications
You must be signed in to change notification settings - Fork 539
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
4 changed files
with
129 additions
and
6 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
20 changes: 20 additions & 0 deletions
20
...ain/java/io/supertokens/passwordless/exceptions/PhoneNumberChangeNotAllowedException.java
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright (c) 2023, VRAI Labs and/or its affiliates. All rights reserved. | ||
* | ||
* This software is licensed under the Apache License, Version 2.0 (the | ||
* "License") as published by the Apache Software Foundation. | ||
* | ||
* You may not use this file except in compliance with the License. You may | ||
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package io.supertokens.passwordless.exceptions; | ||
|
||
public class PhoneNumberChangeNotAllowedException extends Exception { | ||
} |
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
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 |
---|---|---|
|
@@ -23,13 +23,13 @@ | |
import io.supertokens.authRecipe.exception.AccountInfoAlreadyAssociatedWithAnotherPrimaryUserIdException; | ||
import io.supertokens.emailpassword.EmailPassword; | ||
import io.supertokens.emailpassword.exceptions.EmailChangeNotAllowedException; | ||
import io.supertokens.emailpassword.exceptions.WrongCredentialsException; | ||
import io.supertokens.featureflag.EE_FEATURES; | ||
import io.supertokens.featureflag.FeatureFlagTestContent; | ||
import io.supertokens.featureflag.exceptions.FeatureNotEnabledException; | ||
import io.supertokens.multitenancy.Multitenancy; | ||
import io.supertokens.multitenancy.exception.*; | ||
import io.supertokens.passwordless.Passwordless; | ||
import io.supertokens.passwordless.exceptions.PhoneNumberChangeNotAllowedException; | ||
import io.supertokens.pluginInterface.authRecipe.AuthRecipeUserInfo; | ||
import io.supertokens.pluginInterface.emailpassword.exceptions.DuplicateEmailException; | ||
import io.supertokens.pluginInterface.exceptions.InvalidConfigException; | ||
|
@@ -52,7 +52,6 @@ | |
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.function.Function; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
|
@@ -287,6 +286,46 @@ public void testVariousCases() throws Exception { | |
new UpdatePlessUserEmail(t1, 1, "[email protected]").expect(new EmailChangeNotAllowedException()), | ||
}), | ||
|
||
new TestCase(new TestCaseStep[]{ | ||
new CreatePlessUserWithPhone(t1, "+1000001"), | ||
new CreatePlessUserWithPhone(t1, "+1000003"), | ||
new CreatePlessUserWithPhone(t2, "+1000002"), | ||
new MakePrimaryUser(t1, 0), | ||
new LinkAccounts(t1, 0, 2), | ||
new MakePrimaryUser(t2, 1), | ||
new UpdatePlessUserPhone(t1, 0, "+1000003").expect(new PhoneNumberChangeNotAllowedException()), | ||
}), | ||
|
||
new TestCase(new TestCaseStep[]{ | ||
new CreatePlessUserWithPhone(t1, "+1000001"), | ||
new CreatePlessUserWithPhone(t1, "+1000003"), | ||
new CreatePlessUserWithPhone(t2, "+1000002"), | ||
new MakePrimaryUser(t1, 0), | ||
new LinkAccounts(t1, 0, 2), | ||
new MakePrimaryUser(t2, 1), | ||
new UpdatePlessUserPhone(t1, 1, "+1000001").expect(new PhoneNumberChangeNotAllowedException()), | ||
}), | ||
|
||
new TestCase(new TestCaseStep[]{ | ||
new CreateEmailPasswordUser(t1, "[email protected]"), | ||
new CreateEmailPasswordUser(t1, "[email protected]"), | ||
new CreateEmailPasswordUser(t2, "[email protected]"), | ||
new MakePrimaryUser(t1, 0), | ||
new LinkAccounts(t1, 0, 2), | ||
new MakePrimaryUser(t2, 1), | ||
new UpdateEmailPasswordUserEmail(t1, 0, "[email protected]").expect(new EmailChangeNotAllowedException()), | ||
}), | ||
|
||
new TestCase(new TestCaseStep[]{ | ||
new CreateEmailPasswordUser(t1, "[email protected]"), | ||
new CreateEmailPasswordUser(t1, "[email protected]"), | ||
new CreateEmailPasswordUser(t2, "[email protected]"), | ||
new MakePrimaryUser(t1, 0), | ||
new LinkAccounts(t1, 0, 2), | ||
new MakePrimaryUser(t2, 1), | ||
new UpdateEmailPasswordUserEmail(t1, 1, "[email protected]").expect(new EmailChangeNotAllowedException()), | ||
}), | ||
|
||
new TestCase(new TestCaseStep[]{ | ||
new CreateEmailPasswordUser(t1, "[email protected]"), | ||
new CreateThirdPartyUser(t2, "google", "googleid", "[email protected]"), | ||
|
@@ -606,6 +645,24 @@ public void execute(Main main) throws Exception { | |
} | ||
} | ||
|
||
private static class UpdateEmailPasswordUserEmail extends TestCaseStep { | ||
TenantIdentifier tenantIdentifier; | ||
int userIndex; | ||
String email; | ||
|
||
public UpdateEmailPasswordUserEmail(TenantIdentifier tenantIdentifier, int userIndex, String email) { | ||
this.tenantIdentifier = tenantIdentifier; | ||
this.userIndex = userIndex; | ||
this.email = email; | ||
} | ||
|
||
@Override | ||
public void execute(Main main) throws Exception { | ||
TenantIdentifierWithStorage tenantIdentifierWithStorage = tenantIdentifier.withStorage(StorageLayer.getStorage(tenantIdentifier, main)); | ||
EmailPassword.updateUsersEmailOrPassword(tenantIdentifierWithStorage.toAppIdentifierWithStorage(), main, TestCase.users.get(userIndex).getSupertokensUserId(), email, null); | ||
} | ||
} | ||
|
||
private static class UpdatePlessUserEmail extends TestCaseStep { | ||
TenantIdentifier tenantIdentifier; | ||
int userIndex; | ||
|
@@ -623,4 +680,22 @@ public void execute(Main main) throws Exception { | |
Passwordless.updateUser(tenantIdentifierWithStorage.toAppIdentifierWithStorage(), TestCase.users.get(userIndex).getSupertokensUserId(), new Passwordless.FieldUpdate(email), null); | ||
} | ||
} | ||
|
||
private static class UpdatePlessUserPhone extends TestCaseStep { | ||
TenantIdentifier tenantIdentifier; | ||
int userIndex; | ||
String phoneNumber; | ||
|
||
public UpdatePlessUserPhone(TenantIdentifier tenantIdentifier, int userIndex, String phoneNumber) { | ||
this.tenantIdentifier = tenantIdentifier; | ||
this.userIndex = userIndex; | ||
this.phoneNumber = phoneNumber; | ||
} | ||
|
||
@Override | ||
public void execute(Main main) throws Exception { | ||
TenantIdentifierWithStorage tenantIdentifierWithStorage = tenantIdentifier.withStorage(StorageLayer.getStorage(tenantIdentifier, main)); | ||
Passwordless.updateUser(tenantIdentifierWithStorage.toAppIdentifierWithStorage(), TestCase.users.get(userIndex).getSupertokensUserId(), null, new Passwordless.FieldUpdate(phoneNumber)); | ||
} | ||
} | ||
} |