Skip to content

The agent that grows with you

test(profiles): prove registry single use against a profile that stays served

Teknium4fe7ca4d71eb
diff --git a/gateway/run_turn_runner.py b/gateway/run_turn_runner.py
index 4b8f1874211..407c94fdd1d 100644
--- a/gateway/run_turn_runner.py
+++ b/gateway/run_turn_runner.py
@@ -1146,10 +1146,9 @@ class TurnRunner(GatewayTurnProgressMixin, GatewaySessionAgentMixin):
return final_response + "\n" + "\n".join(unique_tags)
def run_sync(self):
- from gateway.session_policy import policy_for_source, policy_scope
+ from gateway.session_policy import bind_turn_workspace, policy_for_source, policy_scope
from gateway.session_api_turn import api_policy_scope
from gateway.session_authorities import active_authority
- from gateway.session_policy import bind_turn_workspace
policy = policy_for_source(self._runner, self._ctx.source)
with policy_scope(policy, authority=active_authority(self._runner)), api_policy_scope():
bind_turn_workspace(policy, self._ctx.session_id)
diff --git a/hermes_cli/dashboard_auth/native_http.py b/hermes_cli/dashboard_auth/native_http.py
index 57e15edafad..20209b503e5 100644
--- a/hermes_cli/dashboard_auth/native_http.py
+++ b/hermes_cli/dashboard_auth/native_http.py
@@ -158,22 +158,21 @@ def _check_registry_scope(request, profile_id, launch_home):
def _redeem_http_ticket(store, ticket, request):
+ from gateway.runtime_bootstrap import _PURPOSE_CAPABILITIES
try:
grant = store.redeem(ticket, profile_id=None, purpose='native-http')
- expected = frozenset({'http:owner'})
except PermissionError:
# Only these host-management operations accept a dedicated same-user grant.
# Wrong-purpose redemption does not consume a ticket; ordinary profile grants
# still reach _check_profile_scope and remain unable to create, move or delete profiles.
if request.method == 'POST' and request.url.path.rstrip('/') == '/api/profiles':
grant = store.redeem(ticket, profile_id=None, purpose='native-profile-create')
- expected = frozenset({'profiles:create'})
elif _registry_target(request) is not None:
grant = store.redeem(ticket, profile_id=None, purpose='native-profile-registry')
- expected = frozenset({'profiles:registry'})
else:
raise
- if grant['capabilities'] != expected:
+ # The issuer's own purpose -> capability table, not a second copy of it.
+ if grant['capabilities'] != _PURPOSE_CAPABILITIES[grant['purpose']]:
raise PermissionError('invalid native grant')
return grant
diff --git a/tests/gateway/test_native_profile_registry_grant.py b/tests/gateway/test_native_profile_registry_grant.py
index b9f9a7b2877..c6d6e3a9e06 100644
--- a/tests/gateway/test_native_profile_registry_grant.py
+++ b/tests/gateway/test_native_profile_registry_grant.py
@@ -105,20 +105,24 @@ def test_registry_grant_renames_and_deletes_only_its_own_served_profile(tmp_path
response = client.delete('/api/profiles/beta', headers=grant('beta', registry))
assert response.status_code == 200, response.text
assert not (home / 'profiles' / 'beta').exists()
- # Single use: the same ticket never authorizes a second write.
- once = grant('keep', registry)
ready()
- assert client.delete('/api/profiles/keep', headers=once).status_code == 200
- assert client.patch('/api/profiles/delta', json={'new_name': 'again'},
- headers=once).status_code == 401
-
+ assert client.delete('/api/profiles/keep', headers=grant('keep', registry)).status_code == 200
# The launch (default) home never moves: rename is its presentation-only display name.
served = ready()
assert home_of('default') in {p['profile_id'] for p in served['served_profiles']}
+ once = grant('default', registry)
+ response = client.patch('/api/profiles/default', json={'new_name': 'Main'}, headers=once)
+ assert response.status_code == 200, response.text
+ assert (response.json()['name'], response.json()['display_name']) == ('default', 'Main')
+ # Single use, against a profile that stays served (a display-name rename never moves
+ # the default home): the same ticket's identical second PATCH is refused, while a
+ # fresh ticket's identical PATCH succeeds, so only the reuse explains the 401.
+ ready()
+ assert client.patch('/api/profiles/default', json={'new_name': 'Main'},
+ headers=once).status_code == 401
response = client.patch('/api/profiles/default', json={'new_name': 'Main'},
headers=grant('default', registry))
assert response.status_code == 200, response.text
- assert (response.json()['name'], response.json()['display_name']) == ('default', 'Main')
response = client.delete('/api/profiles/default', headers=grant('default', registry))
assert response.status_code == 403, response.text
assert (home / 'config.yaml').is_file()