fix(deploy): report safe tenant discovery stages without changing services

This commit is contained in:
ex_tianzy
2026-11-17 11:54:52 +08:00
parent 3132c07256
commit 03d34f1d55
3 changed files with 109 additions and 12 deletions
+33 -1
View File
@@ -41,7 +41,13 @@ async def test_in_container_lookup_is_readonly_and_never_refreshes(env,monkeypat
output=capsys.readouterr().out;result=json.loads(output)
if failure is None:
assert result=={'status':'verified','tenant_key':'tenant_verified','app_id':'cli_test','environment':'test'}
else:assert result=={'status':'tenant_discovery_unavailable'}
else:
assert result['status']=='tenant_discovery_unavailable'
diagnostic=result['diagnostic']
if failure=='expired':assert diagnostic['expired_access']==1
elif failure=='wrong_user':assert diagnostic['user_mismatch']==1
elif failure=='missing_tenant':assert diagnostic['missing_tenant']==1
else:assert diagnostic['platform_rejected']==1
assert len(calls)==(0 if failure=='expired'else 1)
assert '\n'.join(env['store'].db.iterdump())==before
assert env['platform'].refreshes==0
@@ -72,3 +78,29 @@ def test_prepare_never_asks_user_for_tenant_or_prints_verification_token(tmp_pat
identity.main()
assert json.loads(output.read_text())=={'tenant_key':'tenant_verified','verification_token':'synthetic-private-verify'}
assert 'synthetic-private-verify'not in capsys.readouterr().out
def test_diagnostic_whitelist_drops_secrets_and_untrusted_strings():
assert identity.safe_diagnostic({'stage':'user_info','http_status':403,'platform_code':99991679,
'email':'private@example.test','access_token':'private-secret','error_class':'private-secret',
'matched_bindings':True,'expired_access':-1})=={'stage':'user_info','http_status':403,'platform_code':99991679}
def test_diagnose_does_not_prompt_or_write(tmp_path,monkeypatch,capsys):
monkeypatch.setattr(sys,'argv',['approval_identity.py','--diagnose'])
monkeypatch.setattr(identity.subprocess,'run',lambda *a,**kw:SimpleNamespace(returncode=0,stdout='[]'))
monkeypatch.setattr(identity,'discover_tenant',lambda *a:'tenant_verified')
def forbidden(*a):raise AssertionError('Diagnostic must not prompt')
monkeypatch.setattr(identity.getpass,'getpass',forbidden)
identity.main()
assert '"status": "verified"'in capsys.readouterr().out
assert not list(tmp_path.iterdir())
def test_failed_discovery_reports_only_safe_stage_counts(monkeypatch,capsys):
body={'status':'tenant_discovery_unavailable','diagnostic':{'stage':'user_info',
'expired_access':2,'network_errors':0,'access_token':'do-not-print','name':'do-not-print'}}
monkeypatch.setattr(identity.subprocess,'run',lambda *a,**kw:SimpleNamespace(returncode=0,stdout=json.dumps(body)))
with pytest.raises(ValueError):identity.discover_tenant('connector',{})
output=capsys.readouterr().out
assert '"expired_access": 2'in output and 'do-not-print'not in output