@@ -433,3 +433,65 @@ async def test_deactivate_users_mode(client):
433433 r2 = await client .post ("/deactivate" , json = {"license_id" : lid , "app_id" : "*" , "user_principal" : "bob@co.com" })
434434 assert r2 .status_code == 404
435435 assert "Active activation not found" in r2 .json ()["detail" ]
436+
437+
438+ @pytest .mark .asyncio
439+ async def test_activate_reactivates_after_deactivate (client ):
440+ """Re-activating a previously-released identity reuses (un-revokes) its row."""
441+ lid = (await _issue_license (client , restriction = "activations" , activation_limit = 1 ))["license_id" ]
442+ assert (await _activate (client , lid , machine_id = "m1" )).status_code == 200
443+
444+ deact = await client .post ("/deactivate" , json = {"license_id" : lid , "app_id" : "*" , "machine_id" : "m1" })
445+ assert deact .status_code == 204
446+
447+ r = await _activate (client , lid , machine_id = "m1" )
448+ assert r .status_code == 200
449+ assert r .json ()["active_count" ] == 1
450+
451+
452+ # ---------------------------------------------------------------------------
453+ # Admin auth + not-found branches
454+ # ---------------------------------------------------------------------------
455+
456+
457+ @pytest .mark .asyncio
458+ async def test_admin_requires_configured_key (client ):
459+ """With a bearer token but no admin key configured server-side → 503."""
460+ from locksmith .core .config import settings
461+
462+ original = settings .admin_api_key
463+ settings .admin_api_key = ""
464+ try :
465+ resp = await client .post ("/licenses" , json = {}, headers = {"Authorization" : "Bearer anything" })
466+ assert resp .status_code == 503
467+ assert "not configured" in resp .json ()["detail" ].lower ()
468+ finally :
469+ settings .admin_api_key = original
470+
471+
472+ @pytest .mark .asyncio
473+ async def test_get_unknown_license_returns_404 (client ):
474+ from locksmith .core .config import settings
475+
476+ original = settings .admin_api_key
477+ settings .admin_api_key = "testkey123"
478+ try :
479+ resp = await client .get ("/licenses/no-such-id" , headers = {"Authorization" : "Bearer testkey123" })
480+ assert resp .status_code == 404
481+ assert "not found" in resp .json ()["detail" ].lower ()
482+ finally :
483+ settings .admin_api_key = original
484+
485+
486+ @pytest .mark .asyncio
487+ async def test_revoke_unknown_license_returns_404 (client ):
488+ from locksmith .core .config import settings
489+
490+ original = settings .admin_api_key
491+ settings .admin_api_key = "testkey123"
492+ try :
493+ resp = await client .delete ("/licenses/no-such-id" , headers = {"Authorization" : "Bearer testkey123" })
494+ assert resp .status_code == 404
495+ assert "not found" in resp .json ()["detail" ].lower ()
496+ finally :
497+ settings .admin_api_key = original
0 commit comments