Sync public tree to 7aeb51f
Source commit: 7aeb51ff791bd445afc2d51757239b6e306db015 Public tree identity: sha256:c0ab7127634af6502afe357d48a0336bf2f5777be43877097e395df73ef3c5a9
This commit is contained in:
parent
81942fa2ad
commit
8c11db913e
5 changed files with 357 additions and 25 deletions
|
|
@ -1007,6 +1007,7 @@ fn auth_status_report(args: AuthStatusArgs, cwd: PathBuf) -> Result<Value> {
|
|||
"checked": false,
|
||||
"reason": "no project or session coordinator configured",
|
||||
"suspension_known": false,
|
||||
"account_state_known": false,
|
||||
"account_status": "unknown",
|
||||
"private_moderation_details_exposed": false,
|
||||
"signup_failure_details_exposed": false,
|
||||
|
|
@ -1040,6 +1041,7 @@ fn coordinator_auth_status_summary(
|
|||
"source": "public_coordinator_api",
|
||||
"account_status": "unknown",
|
||||
"suspension_known": false,
|
||||
"account_state_known": false,
|
||||
"private_moderation_details_exposed": false,
|
||||
"signup_failure_details_exposed": false,
|
||||
"machine_error": cli_error_summary(&message),
|
||||
|
|
@ -1064,6 +1066,7 @@ fn coordinator_auth_status_summary(
|
|||
"source": "public_coordinator_api",
|
||||
"account_status": "unknown",
|
||||
"suspension_known": false,
|
||||
"account_state_known": false,
|
||||
"private_moderation_details_exposed": false,
|
||||
"signup_failure_details_exposed": false,
|
||||
"machine_error": cli_error_summary(&message),
|
||||
|
|
@ -1085,6 +1088,7 @@ fn coordinator_auth_status_summary(
|
|||
"source": "public_coordinator_api",
|
||||
"account_status": "unknown",
|
||||
"suspension_known": false,
|
||||
"account_state_known": false,
|
||||
"private_moderation_details_exposed": false,
|
||||
"signup_failure_details_exposed": false,
|
||||
"machine_error": cli_error_summary(message),
|
||||
|
|
@ -1101,15 +1105,27 @@ fn coordinator_auth_status_summary(
|
|||
.get("disabled")
|
||||
.and_then(Value::as_bool)
|
||||
.unwrap_or(false);
|
||||
let deleted = response
|
||||
.get("deleted")
|
||||
.and_then(Value::as_bool)
|
||||
.unwrap_or(false);
|
||||
let manual_review = response
|
||||
.get("manual_review")
|
||||
.and_then(Value::as_bool)
|
||||
.unwrap_or(false);
|
||||
let account_status = response
|
||||
.get("account_status")
|
||||
.and_then(Value::as_str)
|
||||
.map(str::to_owned)
|
||||
.unwrap_or_else(|| {
|
||||
if suspended {
|
||||
"suspended"
|
||||
if deleted {
|
||||
"deleted"
|
||||
} else if disabled {
|
||||
"disabled"
|
||||
} else if suspended {
|
||||
"suspended"
|
||||
} else if manual_review {
|
||||
"manual_review"
|
||||
} else {
|
||||
"active"
|
||||
}
|
||||
|
|
@ -1130,8 +1146,11 @@ fn coordinator_auth_status_summary(
|
|||
"source": "public_coordinator_api",
|
||||
"account_status": account_status,
|
||||
"suspension_known": true,
|
||||
"account_state_known": true,
|
||||
"suspended": suspended,
|
||||
"disabled": disabled,
|
||||
"deleted": deleted,
|
||||
"manual_review": manual_review,
|
||||
"sanitized_reason": sanitized_reason,
|
||||
"next_actions": next_actions,
|
||||
"private_moderation_details_exposed": false,
|
||||
|
|
@ -2887,6 +2906,12 @@ fn human_report(value: &Value) -> String {
|
|||
if let Some(disabled) = account.get("disabled").and_then(Value::as_bool) {
|
||||
lines.push(format!("account disabled: {disabled}"));
|
||||
}
|
||||
if let Some(deleted) = account.get("deleted").and_then(Value::as_bool) {
|
||||
lines.push(format!("account deleted: {deleted}"));
|
||||
}
|
||||
if let Some(manual_review) = account.get("manual_review").and_then(Value::as_bool) {
|
||||
lines.push(format!("account manual review: {manual_review}"));
|
||||
}
|
||||
push_nested_string_field(&mut lines, account, "sanitized_reason", "account reason");
|
||||
if let Some(exposed) = account
|
||||
.get("private_moderation_details_exposed")
|
||||
|
|
@ -7842,6 +7867,117 @@ mod tests {
|
|||
assert!(!rendered.contains("private moderation note"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn auth_status_reports_disabled_deleted_and_manual_review_safely() {
|
||||
let listener = TcpListener::bind("127.0.0.1:0").unwrap();
|
||||
let addr = listener.local_addr().unwrap().to_string();
|
||||
let server = std::thread::spawn(move || {
|
||||
for (tenant, status, reason, flags) in [
|
||||
(
|
||||
"tenant-disabled",
|
||||
"disabled",
|
||||
"account or tenant is disabled by hosted policy",
|
||||
(false, true, false, false),
|
||||
),
|
||||
(
|
||||
"tenant-deleted",
|
||||
"deleted",
|
||||
"account or tenant is no longer active",
|
||||
(false, false, true, false),
|
||||
),
|
||||
(
|
||||
"tenant-review",
|
||||
"manual_review",
|
||||
"account or tenant is pending hosted review",
|
||||
(false, false, false, true),
|
||||
),
|
||||
] {
|
||||
let (mut stream, _) = listener.accept().unwrap();
|
||||
let mut reader = BufReader::new(stream.try_clone().unwrap());
|
||||
let mut line = String::new();
|
||||
reader.read_line(&mut line).unwrap();
|
||||
assert!(line.contains(r#""type":"auth_status""#));
|
||||
assert!(line.contains(&format!(r#""tenant":"{tenant}""#)));
|
||||
let (suspended, disabled, deleted, manual_review) = flags;
|
||||
writeln!(
|
||||
stream,
|
||||
"{}",
|
||||
json!({
|
||||
"type": "auth_status",
|
||||
"tenant": tenant,
|
||||
"project": "project-live",
|
||||
"actor": "user-live",
|
||||
"authenticated": true,
|
||||
"account_status": status,
|
||||
"suspended": suspended,
|
||||
"disabled": disabled,
|
||||
"deleted": deleted,
|
||||
"manual_review": manual_review,
|
||||
"sanitized_reason": reason,
|
||||
"next_actions": ["contact the hosted operator"],
|
||||
"private_moderation_details_exposed": false,
|
||||
"signup_failure_details_exposed": false,
|
||||
"abuse_score": 99,
|
||||
"moderation_notes": "private moderation note",
|
||||
"signup_policy_trace": "private signup trace",
|
||||
})
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
});
|
||||
|
||||
for (tenant, status, rendered_marker) in [
|
||||
("tenant-disabled", "disabled", "account disabled: true"),
|
||||
("tenant-deleted", "deleted", "account deleted: true"),
|
||||
(
|
||||
"tenant-review",
|
||||
"manual_review",
|
||||
"account manual review: true",
|
||||
),
|
||||
] {
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
let report = auth_status_report(
|
||||
AuthStatusArgs {
|
||||
scope: CliScopeArgs {
|
||||
coordinator: Some(addr.clone()),
|
||||
tenant: tenant.to_owned(),
|
||||
project: "project-live".to_owned(),
|
||||
user: "user-live".to_owned(),
|
||||
json: false,
|
||||
},
|
||||
},
|
||||
temp.path().to_path_buf(),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
report["coordinator_account_status"]["account_status"],
|
||||
status
|
||||
);
|
||||
assert_eq!(
|
||||
report["coordinator_account_status"]["account_state_known"],
|
||||
true
|
||||
);
|
||||
assert_eq!(
|
||||
report["coordinator_account_status"]["private_moderation_details_exposed"],
|
||||
false
|
||||
);
|
||||
assert_eq!(
|
||||
report["coordinator_account_status"]["signup_failure_details_exposed"],
|
||||
false
|
||||
);
|
||||
let serialized = serde_json::to_string(&report).unwrap();
|
||||
assert!(!serialized.contains("abuse_score"));
|
||||
assert!(!serialized.contains("moderation_notes"));
|
||||
assert!(!serialized.contains("signup_policy_trace"));
|
||||
assert!(!serialized.contains("private moderation note"));
|
||||
let rendered = human_report(&report);
|
||||
assert!(rendered.contains(&format!("account status: {status}")));
|
||||
assert!(rendered.contains(rendered_marker));
|
||||
assert!(!rendered.contains("private moderation note"));
|
||||
}
|
||||
server.join().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cli_first_mvp_command_surface_parses() {
|
||||
for args in [
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue