diff options
Diffstat (limited to 'packages/meshbay-hub/tests/test_password_change.py')
| -rw-r--r-- | packages/meshbay-hub/tests/test_password_change.py | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/packages/meshbay-hub/tests/test_password_change.py b/packages/meshbay-hub/tests/test_password_change.py index aba2d9a..4d2f303 100644 --- a/packages/meshbay-hub/tests/test_password_change.py +++ b/packages/meshbay-hub/tests/test_password_change.py @@ -37,44 +37,44 @@ async def _register(client, username, password="the-first-passphrase"): @pytest.mark.asyncio async def test_change_then_sign_in_with_the_new_passphrase(client): old, new = "the-first-passphrase", "a-second-passphrase-entirely" - session = await _register(client, "alice", old) + session = await _register(client, "alice_test", old) r = await client.post("/v1/users/password", json={ - "old_auth_key": _auth_key(old, "alice"), - "new_auth_key": _auth_key(new, "alice"), + "old_auth_key": _auth_key(old, "alice_test"), + "new_auth_key": _auth_key(new, "alice_test"), }, headers={"Authorization": f"Bearer {session['access_token']}"}) assert r.status_code == 200, r.text assert r.json()["status"] == "changed" assert (await client.post("/v1/users/login", json={ - "username": "alice", "auth_key": _auth_key(old, "alice")})).status_code == 401 + "username": "alice_test", "auth_key": _auth_key(old, "alice_test")})).status_code == 401 assert (await client.post("/v1/users/login", json={ - "username": "alice", "auth_key": _auth_key(new, "alice")})).status_code == 200 + "username": "alice_test", "auth_key": _auth_key(new, "alice_test")})).status_code == 200 @pytest.mark.asyncio async def test_wrong_current_passphrase_is_refused_and_changes_nothing(client): old = "the-first-passphrase" - session = await _register(client, "bob", old) + session = await _register(client, "bob_test", old) r = await client.post("/v1/users/password", json={ - "old_auth_key": _auth_key("not the passphrase", "bob"), - "new_auth_key": _auth_key("some-new-passphrase", "bob"), + "old_auth_key": _auth_key("not the passphrase", "bob_test"), + "new_auth_key": _auth_key("some-new-passphrase", "bob_test"), }, headers={"Authorization": f"Bearer {session['access_token']}"}) assert r.status_code == 403 assert (await client.post("/v1/users/login", json={ - "username": "bob", "auth_key": _auth_key(old, "bob")})).status_code == 200 + "username": "bob_test", "auth_key": _auth_key(old, "bob_test")})).status_code == 200 @pytest.mark.asyncio async def test_new_must_differ_from_old(client): old = "the-first-passphrase" - session = await _register(client, "carol", old) + session = await _register(client, "carol_test", old) r = await client.post("/v1/users/password", json={ - "old_auth_key": _auth_key(old, "carol"), - "new_auth_key": _auth_key(old, "carol"), + "old_auth_key": _auth_key(old, "carol_test"), + "new_auth_key": _auth_key(old, "carol_test"), }, headers={"Authorization": f"Bearer {session['access_token']}"}) assert r.status_code == 400 @@ -82,10 +82,10 @@ async def test_new_must_differ_from_old(client): @pytest.mark.asyncio async def test_unauthenticated_call_is_rejected(client): """A session is required — the current passphrase alone is not a credential.""" - await _register(client, "dave", "the-first-passphrase") + await _register(client, "dave_test", "the-first-passphrase") r = await client.post("/v1/users/password", json={ - "old_auth_key": _auth_key("the-first-passphrase", "dave"), - "new_auth_key": _auth_key("a-new-one", "dave"), + "old_auth_key": _auth_key("the-first-passphrase", "dave_test"), + "new_auth_key": _auth_key("a-new-one", "dave_test"), }) assert r.status_code in (401, 403, 422) @@ -94,14 +94,14 @@ async def test_unauthenticated_call_is_rejected(client): async def test_other_sessions_are_invalidated_and_the_caller_keeps_one( client, db_session): old, new = "the-first-passphrase", "a-second-passphrase-entirely" - first = await _register(client, "erin", old) + first = await _register(client, "erin_test", old) # A second browser signs in before the change. second = (await client.post("/v1/users/login", json={ - "username": "erin", "auth_key": _auth_key(old, "erin")})).json() + "username": "erin_test", "auth_key": _auth_key(old, "erin_test")})).json() r = await client.post("/v1/users/password", json={ - "old_auth_key": _auth_key(old, "erin"), - "new_auth_key": _auth_key(new, "erin"), + "old_auth_key": _auth_key(old, "erin_test"), + "new_auth_key": _auth_key(new, "erin_test"), }, headers={"Authorization": f"Bearer {first['access_token']}"}) assert r.status_code == 200, r.text @@ -116,7 +116,7 @@ async def test_other_sessions_are_invalidated_and_the_caller_keeps_one( assert fresh.status_code == 200, fresh.text uid = (await db_session.execute( - select(User.id).where(User.username == "erin"))).scalar_one() + select(User.id).where(User.username == "erin_test"))).scalar_one() live = (await db_session.execute( select(RefreshToken).where(RefreshToken.user_id == uid, RefreshToken.revoked.is_(False)))).scalars().all() @@ -127,14 +127,14 @@ async def test_other_sessions_are_invalidated_and_the_caller_keeps_one( @pytest.mark.asyncio async def test_the_change_is_logged(client, db_session): old, new = "the-first-passphrase", "a-second-passphrase-entirely" - session = await _register(client, "frank", old) + session = await _register(client, "frank_test", old) await client.post("/v1/users/password", json={ - "old_auth_key": _auth_key(old, "frank"), - "new_auth_key": _auth_key(new, "frank"), + "old_auth_key": _auth_key(old, "frank_test"), + "new_auth_key": _auth_key(new, "frank_test"), }, headers={"Authorization": f"Bearer {session['access_token']}"}) uid = (await db_session.execute( - select(User.id).where(User.username == "frank"))).scalar_one() + select(User.id).where(User.username == "frank_test"))).scalar_one() events = {e.event for e in (await db_session.execute( select(IPLog).where(IPLog.user_id == uid))).scalars().all()} assert "password_change" in events |