Skip to content

Commit a6fa132

Browse files
committed
fix: handle 'marked for deletion' as not-found, retry in list test
Secrets deleted without force_delete enter a recovery window where get() returns InvalidRequestException("marked for deletion") instead of ResourceNotFoundException. Treat both as not-found. ListSecrets is eventually consistent — newly created secrets may not appear immediately. Add a brief retry loop in the list test.
1 parent 13603d6 commit a6fa132

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

  • crates/zerolease-store-aws-sm/src

crates/zerolease-store-aws-sm/src/store.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,14 @@ impl AwsSecretsManagerStore {
205205
serde_json::from_str(s).map_err(|e| Error::Storage(format!("payload deserialization failed: {e}")))
206206
}
207207

208-
/// Check if an AWS SDK error message indicates a not-found condition.
208+
/// Check if an AWS SDK error indicates the secret doesn't exist.
209+
///
210+
/// Matches both `ResourceNotFoundException` (never existed) and
211+
/// `InvalidRequestException` with "marked for deletion" (deleted
212+
/// without force, still in recovery window).
209213
fn is_not_found(err_debug: &str) -> bool {
210214
err_debug.contains("ResourceNotFoundException")
215+
|| err_debug.contains("marked for deletion")
211216
}
212217

213218
/// Strip our prefix from an SM secret name to recover the zerolease name.
@@ -703,10 +708,21 @@ mod tests {
703708
.await
704709
.expect("put should create second secret for list test");
705710

706-
let list = store.list().await.expect("list should return stored secrets");
711+
// ListSecrets is eventually consistent — retry briefly if
712+
// not all secrets are visible yet.
713+
let mut list = Vec::new();
714+
for attempt in 0..5 {
715+
list = store.list().await.expect("list should return stored secrets");
716+
if list.len() >= 2 {
717+
break;
718+
}
719+
if attempt < 4 {
720+
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
721+
}
722+
}
707723
assert!(
708724
list.len() >= 2,
709-
"expected at least 2 secrets in list, got {}",
725+
"expected at least 2 secrets in list after retries, got {}",
710726
list.len()
711727
);
712728

0 commit comments

Comments
 (0)