fix: look up old key_id via hub instead of recomputing it (musehub#221 follow-up)
Found running the migration for real against localhost, staging, and production: old-key deregistration 404'd on all three ("could not deregister old key ... HTTP Error 404: Not Found"). The code computed old_key_id = sha256(identity_id, public_key_b64) locally and assumed it would match what the hub stored -- but the hub computed that same hash from whatever public_key_b64 *encoding* the account's original registration request used, which can predate conventions the current client uses (e.g. an unprefixed vs. canonically-prefixed base64url string). Recomputing it client-side is fragile by construction: it's only correct if the encoding history is reproduced exactly.
Added `_hub_get()` (auth.py, mirrors `_hub_delete()`) and use it to fetch the account's key list via the already-existing `GET /api/auth/keys/{handle}` endpoint, matching the old key by its *fingerprint* (which we already know authoritatively -- it's what's in identity.toml) rather than recomputing its key_id. This sidesteps the encoding-history problem entirely: the hub tells us the real key_id, we don't have to reconstruct it.
Both the lookup and the delete remain non-fatal on failure, matching `muse auth rotate`'s behavior -- the new key is already registered regardless of whether old-key cleanup succeeds.
Rewrote test_deregisters_old_key_after_successful_add to assert the delete targets the key_id returned by the (mocked) hub lookup -- using a key_id that deliberately does NOT match what the old recompute-based logic would have derived, so the test only passes under the new lookup-based implementation. Added tests for: old fingerprint missing from the hub's key list (skip delete, still non-fatal), and the lookup call itself failing (non-fatal). Updated the two existing tests that reach the deregistration path to mock the new _hub_get call.
Tests: 53/53 in test_migrate_hub_scoping.py, 149/149 across the full migrate/rotate/register targeted set.
Semantic Changes
11 symbols
Files Changed
~3
1195 in snapshot
0 comments
muse hub commit comment sha256:bfd014ea21257cca982f8e389be81f60616acc78fb3d84f767601fea6d35a7f5 --body "your comment"
No comments yet. Be the first to start the discussion.