test_identity_lifecycle.py
1 """E2E tests for the core identity lifecycle.""" 2 3 import json 4 5 import pytest 6 7 from helpers.assertions import assert_did_format 8 from helpers.cli import run_auths 9 10 11 @pytest.mark.requires_binary 12 class TestIdentityLifecycle: 13 def test_init_developer_profile(self, auths_bin, isolated_env): 14 result = run_auths( 15 auths_bin, 16 ["init", "--profile", "developer", "--non-interactive", "--skip-registration"], 17 env=isolated_env, 18 ) 19 result.assert_success() 20 21 status = run_auths(auths_bin, ["status", "--json"], env=isolated_env) 22 # status may or may not support --json yet 23 assert status.returncode == 0 24 25 def test_init_ci_profile(self, auths_bin, isolated_env): 26 result = run_auths( 27 auths_bin, 28 ["init", "--profile", "ci", "--non-interactive", "--skip-registration"], 29 env=isolated_env, 30 ) 31 result.assert_success() 32 33 def test_init_agent_profile(self, auths_bin, isolated_env): 34 result = run_auths( 35 auths_bin, 36 ["init", "--profile", "agent", "--non-interactive", "--skip-registration"], 37 env=isolated_env, 38 ) 39 result.assert_success() 40 41 def test_init_already_initialized(self, auths_bin, isolated_env): 42 run_auths( 43 auths_bin, 44 ["init", "--profile", "developer", "--non-interactive", "--skip-registration"], 45 env=isolated_env, 46 ).assert_success() 47 48 second = run_auths( 49 auths_bin, 50 ["init", "--profile", "developer", "--non-interactive", "--skip-registration"], 51 env=isolated_env, 52 ) 53 # Second init should either fail or warn 54 # GAP: unclear if this produces non-zero exit or just warns 55 assert second.returncode in (0, 1) 56 57 def test_status_json_output(self, auths_bin, init_identity): 58 result = run_auths(auths_bin, ["status", "--json"], env=init_identity) 59 if result.returncode == 0 and result.stdout.strip().startswith("{"): 60 data = json.loads(result.stdout) 61 # GAP: validate expected fields once --json is confirmed 62 assert isinstance(data, dict) 63 else: 64 # GAP: `auths status --json` may not be implemented 65 pytest.skip("auths status --json not supported") 66 67 def test_id_show_json(self, auths_bin, init_identity): 68 result = run_auths(auths_bin, ["id", "show", "--json"], env=init_identity) 69 if result.returncode == 0 and result.stdout.strip().startswith("{"): 70 data = json.loads(result.stdout) 71 controller_did = data.get("data", {}).get("controller_did") 72 if controller_did: 73 assert_did_format(controller_did) 74 else: 75 pytest.skip("auths id show --json not supported") 76 77 def test_id_export_bundle(self, auths_bin, init_identity, tmp_path): 78 bundle_path = tmp_path / "bundle.json" 79 result = run_auths( 80 auths_bin, 81 [ 82 "id", 83 "export-bundle", 84 "--alias", 85 "main", 86 "--output", 87 str(bundle_path), 88 "--max-age-secs", 89 "3600", 90 ], 91 env=init_identity, 92 ) 93 if result.returncode == 0: 94 assert bundle_path.exists() 95 data = json.loads(bundle_path.read_text()) 96 assert isinstance(data, dict) 97 else: 98 pytest.skip("auths id export-bundle not supported") 99 100 @pytest.mark.slow 101 def test_full_lifecycle(self, auths_bin, isolated_env, tmp_path): 102 # Init 103 run_auths( 104 auths_bin, 105 ["init", "--profile", "developer", "--non-interactive", "--skip-registration"], 106 env=isolated_env, 107 ).assert_success() 108 109 # Status 110 status = run_auths(auths_bin, ["status"], env=isolated_env) 111 status.assert_success() 112 113 # Id show 114 id_show = run_auths(auths_bin, ["id", "show"], env=isolated_env) 115 id_show.assert_success() 116 117 # Export bundle 118 bundle_path = tmp_path / "bundle.json" 119 export = run_auths( 120 auths_bin, 121 [ 122 "id", 123 "export-bundle", 124 "--alias", 125 "main", 126 "--output", 127 str(bundle_path), 128 "--max-age-secs", 129 "3600", 130 ], 131 env=isolated_env, 132 ) 133 if export.returncode != 0: 134 pytest.skip("export-bundle not available")