From 8a501846f4451aca6d8de5439b86480effb95004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=89=E6=AD=A3=E8=B6=85?= Date: Tue, 12 May 2026 18:39:53 +0800 Subject: [PATCH] test(iam): cover mixed STS claim policy names (#2932) --- crates/iam/src/sys.rs | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/crates/iam/src/sys.rs b/crates/iam/src/sys.rs index 3edb7d1d0..f900ac7f3 100644 --- a/crates/iam/src/sys.rs +++ b/crates/iam/src/sys.rs @@ -1975,6 +1975,50 @@ mod tests { ); } + #[tokio::test] + async fn test_sts_claim_policy_ignores_unsafe_and_missing_policy_names() { + let store = StsTestMockStore { empty_policies: true }; + let cache_manager = IamCache::new(store).await.unwrap(); + let iam_sys = IamSys::new(cache_manager); + + let parent_user = "sts-empty-parent-policy-test"; + let sts_access_key = "sts-mixed-claim-policy-test-user"; + let sts_user = UserIdentity::from(Credentials { + access_key: sts_access_key.to_string(), + secret_key: "longenoughsecret".to_string(), + session_token: "sts-token".to_string(), + status: ACCOUNT_ON.to_string(), + parent_user: parent_user.to_string(), + ..Default::default() + }); + Cache::add_or_update(&iam_sys.store.cache.sts_accounts, sts_access_key, &sts_user, OffsetDateTime::now_utc()); + + let mut claims = HashMap::new(); + claims.insert( + POLICYNAME.to_string(), + Value::String(format!("unsafe/policy, missing-sts-claim-policy, {CUSTOM_STS_CLAIM_POLICY}")), + ); + let groups: Option> = None; + let args = Args { + account: sts_access_key, + groups: &groups, + action: Action::S3Action(S3Action::GetObjectAction), + bucket: CUSTOM_STS_CLAIM_BUCKET, + conditions: &HashMap::new(), + is_owner: false, + object: "allowed/object.txt", + claims: &claims, + deny_only: false, + }; + + let prepared = iam_sys.prepare_sts_auth(&args, parent_user).await; + assert!(matches!(prepared.mode, PreparedIamMode::Sts { .. })); + assert!( + iam_sys.eval_prepared(&prepared, &args).await, + "STS policy claims should ignore unsafe or unresolved names without dropping a resolvable canned policy" + ); + } + #[tokio::test] async fn test_sts_claim_policy_custom_canned_policy_does_not_grant_other_actions() { let store = StsTestMockStore { empty_policies: true };