diff options
Diffstat (limited to 'packages/meshbay-common/tests')
| -rw-r--r-- | packages/meshbay-common/tests/test_handshake.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/packages/meshbay-common/tests/test_handshake.py b/packages/meshbay-common/tests/test_handshake.py index 8f385bb..f42d597 100644 --- a/packages/meshbay-common/tests/test_handshake.py +++ b/packages/meshbay-common/tests/test_handshake.py @@ -120,6 +120,27 @@ def test_a_token_with_no_audience_is_refused(hub_key): authorize_token(no_aud, pk_pem, group_id=GROUP) +def test_a_token_bound_to_another_node_is_refused(hub_key): + """E10: a token names the node it is for. A member's token captured by one + node's operator cannot be replayed to a second node the member also uses.""" + sk_pem, pk_pem = hub_key + token_for_A = _token(sk_pem, node="node-A-pk") + # Node B (its own key is 'node-B-pk') refuses it. + with pytest.raises(HandshakeError, match="this node"): + authorize_token(token_for_A, pk_pem, group_id=GROUP, node_pk_b64="node-B-pk") + # Node A accepts it. + peer = authorize_token(token_for_A, pk_pem, group_id=GROUP, node_pk_b64="node-A-pk") + assert peer.user_id == "user-1" + + +def test_a_token_naming_no_node_is_still_accepted(hub_key): + """Lenient by design: the hub mints an unbound token only for the requester, + so it grants nothing across accounts, and older callers keep working.""" + sk_pem, pk_pem = hub_key + peer = authorize_token(_token(sk_pem), pk_pem, group_id=GROUP, node_pk_b64="node-B-pk") + assert peer.group_id == GROUP + + def test_unhosted_group_refused(hub_key): sk_pem, pk_pem = hub_key with pytest.raises(HandshakeError, match="not hosted"): |