-
Notifications
You must be signed in to change notification settings - Fork 415
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: allow registration via invite link if ALLOW_REGISTRATION_WITHOUT…
…_INVITE is False (#2731)
- Loading branch information
1 parent
33e7c17
commit 73705d5
Showing
4 changed files
with
65 additions
and
5 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
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,13 +4,16 @@ | |
from django.contrib.auth import get_user_model | ||
from django.test import RequestFactory | ||
from django.utils import timezone | ||
from pytest_django.fixtures import SettingsWrapper | ||
from pytest_mock import MockerFixture | ||
from rest_framework.authtoken.models import Token | ||
|
||
from custom_auth.oauth.serializers import ( | ||
GithubLoginSerializer, | ||
GoogleLoginSerializer, | ||
OAuthLoginSerializer, | ||
) | ||
from users.models import SignUpType | ||
|
||
UserModel = get_user_model() | ||
|
||
|
@@ -131,3 +134,31 @@ def test_OAuthLoginSerializer_calls_is_authentication_method_valid_correctly_if_ | |
email=user_email, | ||
raise_exception=True, | ||
) | ||
|
||
|
||
def test_OAuthLoginSerializer_allows_registration_if_sign_up_type_is_invite_link( | ||
settings: SettingsWrapper, rf: RequestFactory, mocker: MockerFixture, db: None | ||
): | ||
# Given | ||
settings.ALLOW_REGISTRATION_WITHOUT_INVITE = False | ||
|
||
request = rf.post("/api/v1/auth/users/") | ||
user_email = "[email protected]" | ||
|
||
serializer = OAuthLoginSerializer( | ||
data={ | ||
"access_token": "some_token", | ||
"sign_up_type": SignUpType.INVITE_LINK.value, | ||
}, | ||
context={"request": request}, | ||
) | ||
# monkey patch the get_user_info method to return the mock user data | ||
serializer.get_user_info = lambda: {"email": user_email} | ||
|
||
serializer.is_valid(raise_exception=True) | ||
|
||
# When | ||
user = serializer.save() | ||
|
||
# Then | ||
assert user |
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 |
---|---|---|
@@ -1,5 +1,8 @@ | ||
from django.test import RequestFactory | ||
from pytest_django.fixtures import SettingsWrapper | ||
|
||
from custom_auth.serializers import CustomUserCreateSerializer | ||
from users.models import FFAdminUser | ||
from users.models import FFAdminUser, SignUpType | ||
|
||
user_dict = { | ||
"email": "[email protected]", | ||
|
@@ -53,3 +56,28 @@ def test_CustomUserCreateSerializer_calls_is_authentication_method_valid_correct | |
email=user_dict["email"], | ||
raise_exception=True, | ||
) | ||
|
||
|
||
def test_CustomUserCreateSerializer_allows_registration_if_sign_up_type_is_invite_link( | ||
db: None, | ||
settings: SettingsWrapper, | ||
rf: RequestFactory, | ||
) -> None: | ||
# Given | ||
settings.ALLOW_REGISTRATION_WITHOUT_INVITE = False | ||
|
||
data = { | ||
**user_dict, | ||
"sign_up_type": SignUpType.INVITE_LINK.value, | ||
} | ||
|
||
serializer = CustomUserCreateSerializer( | ||
data=data, context={"request": rf.post("/v1/auth/users/")} | ||
) | ||
assert serializer.is_valid() | ||
|
||
# When | ||
user = serializer.save() | ||
|
||
# Then | ||
assert user |
73705d5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
flagsmith-frontend-preview – ./frontend
flagsmith-frontend-production-native.vercel.app
flagsmith-frontend-preview-flagsmith.vercel.app
flagsmith-frontend-preview-git-main-flagsmith.vercel.app
73705d5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
docs – ./docs
docs-git-main-flagsmith.vercel.app
docs.bullet-train.io
docs-flagsmith.vercel.app
docs.flagsmith.com
73705d5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
flagsmith-frontend-staging – ./frontend
flagsmith-staging-frontend.vercel.app
flagsmith-frontend-staging-flagsmith.vercel.app
staging.flagsmith.com
flagsmith-frontend-staging-git-main-flagsmith.vercel.app