diff --git a/collectives/routes/auth/signup.py b/collectives/routes/auth/signup.py index f857b0df..9f629a57 100644 --- a/collectives/routes/auth/signup.py +++ b/collectives/routes/auth/signup.py @@ -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 = ( diff --git a/tests/test_extranet.py b/tests/test_extranet.py index 1d403fbb..686790ed 100644 --- a/tests/test_extranet.py +++ b/tests/test_extranet.py @@ -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") @@ -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": "test@example.com", + "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": "test@example.com", + "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