Refresh tests: pin the denied-status split and the session and account custody checks
Mutation survivors of the first cut: the status comparison inside invoke (now refuse_denied, tested directly) and the session-or-account custody check (a receipt for another session, or another account, revokes). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
af7e544830
commit
1b31bfc399
2 changed files with 47 additions and 9 deletions
|
|
@ -644,12 +644,7 @@ impl HeimdallClient {
|
|||
else {
|
||||
bail!("Heimdall returned a non-operation response");
|
||||
};
|
||||
if status == "denied" {
|
||||
return Err(HeimdallDenied {
|
||||
diagnostics: diagnostics.join("; "),
|
||||
}
|
||||
.into());
|
||||
}
|
||||
refuse_denied(&status, &diagnostics)?;
|
||||
if payload_schema != PRIVATE_ENVELOPE_SCHEMA || payload_encoding != "messagepack-base64" {
|
||||
bail!("Heimdall returned the wrong private response contract");
|
||||
}
|
||||
|
|
@ -659,6 +654,18 @@ impl HeimdallClient {
|
|||
}
|
||||
}
|
||||
|
||||
/// A response with status denied is Heimdall's answer, not a transport
|
||||
/// failure: it becomes the typed `HeimdallDenied`.
|
||||
fn refuse_denied(status: &str, diagnostics: &[String]) -> anyhow::Result<()> {
|
||||
if status == "denied" {
|
||||
return Err(HeimdallDenied {
|
||||
diagnostics: diagnostics.join("; "),
|
||||
}
|
||||
.into());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn validate_private_response_binding(
|
||||
envelope: &PrivateEnvelope,
|
||||
operation: &str,
|
||||
|
|
@ -1104,6 +1111,15 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_denied_status_is_the_typed_denial_and_any_other_status_passes() {
|
||||
let diagnostics = vec!["Idempotency key was reused".to_owned()];
|
||||
let denial = refuse_denied("denied", &diagnostics).unwrap_err();
|
||||
assert!(denial.downcast_ref::<HeimdallDenied>().is_some());
|
||||
assert!(denial.to_string().contains("Idempotency key was reused"));
|
||||
refuse_denied("accepted", &diagnostics).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn private_responses_are_bound_to_the_exact_app_and_request() {
|
||||
let secret = "fixture-shared-secret";
|
||||
|
|
|
|||
|
|
@ -6403,6 +6403,10 @@ mod refresh_loop_tests {
|
|||
Deny,
|
||||
Timeout,
|
||||
Receipt { revision: u64, claim: &'static str },
|
||||
/// A receipt for the same claim but another Heimdall session.
|
||||
OtherSession,
|
||||
/// A receipt for the same claim but another account.
|
||||
OtherAccount,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
|
|
@ -6442,10 +6446,18 @@ mod refresh_loop_tests {
|
|||
}
|
||||
.into()),
|
||||
Reply::Timeout => bail!("Heimdall private command timed out"),
|
||||
Reply::Receipt { revision, claim } => {
|
||||
reply @ (Reply::Receipt { .. } | Reply::OtherSession | Reply::OtherAccount) => {
|
||||
let (account, session, revision, claim) = match reply {
|
||||
Reply::OtherSession => ("operator-account", "other-session", 1, "claim-1"),
|
||||
Reply::OtherAccount => ("other-account", "heimdall-session", 1, "claim-1"),
|
||||
Reply::Receipt { revision, claim } => {
|
||||
("operator-account", "heimdall-session", revision, claim)
|
||||
}
|
||||
_ => unreachable!("matched above"),
|
||||
};
|
||||
*self.pending.lock().unwrap() = Some(VerifiedSessionRefresh::fixture(
|
||||
"operator-account",
|
||||
"heimdall-session",
|
||||
account,
|
||||
session,
|
||||
revision,
|
||||
Utc::now() + chrono::Duration::seconds(90),
|
||||
Utc::now() + chrono::Duration::days(1),
|
||||
|
|
@ -6579,6 +6591,16 @@ mod refresh_loop_tests {
|
|||
assert_eq!(heimdall.calls().len(), 1, "a revoked session is not offered again");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_receipt_for_another_session_or_account_revokes_the_local_session() {
|
||||
for reply in [Reply::OtherSession, Reply::OtherAccount] {
|
||||
let (_directory, sessions, cookie) = due_session(1);
|
||||
let heimdall = ScriptedHeimdall::answering(vec![reply]);
|
||||
refresh_due_sessions(&sessions, &heimdall).await.unwrap();
|
||||
assert!(!is_live(&sessions, &cookie).await);
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_heimdall_denial_revokes_the_session_and_it_is_not_offered_again() {
|
||||
let (_directory, sessions, cookie) = due_session(1);
|
||||
|
|
|
|||
Loading…
Reference in a new issue