Skip to content

Commit

Permalink
[FIX] Check license club before signup
Browse files Browse the repository at this point in the history
  • Loading branch information
jnguiot committed Dec 7, 2024
1 parent df49f03 commit 76d23a4
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
8 changes: 8 additions & 0 deletions collectives/routes/auth/signup.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,14 @@ def check_user_validity(form):
:returns: True if license is valid, False if not, None if there is an error"""
license_number = form.license.data
try:
if Configuration.CLUB_PREFIX:
if not license_number.startswith(Configuration.CLUB_PREFIX):
form.generic_error = (
f"La license n'est pas active pour {Configuration.CLUB_NAME}. Merci d'indiquer "
f"un numéro de licence débutant par {Configuration.CLUB_PREFIX}."
)
return False

license_info = extranet.api.check_license(license_number)
if not license_info.is_valid_at_time(current_time()):
form.generic_error = (
Expand Down
42 changes: 42 additions & 0 deletions tests/test_extranet.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def test_create_account(client, extranet_monkeypatch):

# Setup conf as extranet account creation
Configuration.EXTRANET_ACCOUNT_ID = "XXX"
Configuration.CLUB_PREFIX = "7400"

# First signup stage
response = client.get("/auth/signup")
Expand Down Expand Up @@ -196,3 +197,44 @@ def test_user_resync_account(user1_client, user2, extranet_monkeypatch):
)
assert response.status_code == 200
assert "error message" in response.text


def test_signup_licence_nocheck(client, extranet_monkeypatch):
"""Test the licence check during signup without club licence check"""

# Setup conf as extranet account creation
Configuration.EXTRANET_ACCOUNT_ID = "XXX"
Configuration.CLUB_PREFIX = ""

# First signup stage
response = client.get("/auth/signup")
assert response.status_code == 200
data = {
"mail": "[email protected]",
"license": mock.extranet.VALID_LICENSE,
"date_of_birth": "2022-10-04",
}
response = client.post("/auth/signup", data=data)
assert response.status_code == 302
assert "flash-error" not in response.text
assert mock.extranet.STORED_TOKEN is not None


def test_signup_licence_check_wrong_club(client, extranet_monkeypatch):
"""Test the not valdi licence during signup with club licence check"""

# Setup conf as extranet account creation
Configuration.EXTRANET_ACCOUNT_ID = "XXX"
Configuration.CLUB_PREFIX = "9900"

# First signup stage
response = client.get("/auth/signup")
assert response.status_code == 200
data = {
"mail": "[email protected]",
"license": mock.extranet.VALID_LICENSE,
"date_of_birth": "2022-10-04",
}
response = client.post("/auth/signup", data=data)
assert response.status_code == 200
assert "flash-error" in response.text

0 comments on commit 76d23a4

Please sign in to comment.