From d01893f577ededdcd16f9db17cc2f096481c908c Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Wed, 4 Feb 2026 14:04:25 +0200 Subject: [PATCH] test: one time code --- tests/api/test_auth.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/api/test_auth.py b/tests/api/test_auth.py index 90d11a9fc..aea787cff 100644 --- a/tests/api/test_auth.py +++ b/tests/api/test_auth.py @@ -398,6 +398,47 @@ async def test_register_reusable_activation_code( assert response.json().get("access_token") is not None +@pytest.mark.anyio +async def test_register_one_time_activation_code( + http_client: AsyncClient, settings: Settings +): + settings.lnbits_require_user_activation = True + settings.lnbits_user_activation_by_invitation_code = True + settings.lnbits_register_reusable_activation_code = "foo" + settings.lnbits_register_one_time_activation_codes = ["baz", "qux"] + + tiny_id = shortuuid.uuid()[:8] + response = await http_client.post( + "/api/v1/auth/register", + json={ + "username": f"u21.{tiny_id}", + "password": "secret1234", + "password_repeat": "secret1234", + "email": f"u21.{tiny_id}@lnbits.com", + "invitation_code": "baz", + }, + ) + + assert response.status_code == 200, "User created with one-time code." + assert response.json().get("access_token") is not None + + # Register again with the same code + tiny_id = shortuuid.uuid()[:8] + response = await http_client.post( + "/api/v1/auth/register", + json={ + "username": f"u21.{tiny_id}", + "password": "secret1234", + "password_repeat": "secret1234", + "email": f"u21.{tiny_id}@lnbits.com", + "invitation_code": "baz", + }, + ) + + assert response.status_code == 400, "Invalid invitation code." + assert response.json().get("detail") == "Invalid invitation code." + + @pytest.mark.anyio async def test_register_email_twice(http_client: AsyncClient): tiny_id = shortuuid.uuid()[:8]