Files
seaweedfs/weed/s3api/sts_packed_policy_test.go
T
Chris Lu f9dfc0ea37 feat(iam): STS web-identity AWS-fidelity polish
- OIDC discovery via .well-known/openid-configuration; falls back to
  /.well-known/jwks.json when discovery is absent. Reject discovery docs
  whose issuer claim does not match the configured issuer to defend
  against issuer-substitution.
- ComputeParentUser derives a stable per-identity hash from (sub, iss).
  Surface as aws:userid in the request context and as a parent_user
  claim in the session JWT so per-user state survives token rotation.
- Per-role MaxSessionDuration (3600..43200) clamps requested
  DurationSeconds before the STS service applies its own caps.
- Tighten RoleSessionName to the AWS contract: 2..64 chars from
  [\w+=,.@-].
- Populate PackedPolicySize in AssumeRole / AssumeRoleWithWebIdentity /
  AssumeRoleWithLDAPIdentity responses as a percentage of the 2048-byte
  inline session policy budget.
2026-05-04 22:06:19 -07:00

35 lines
877 B
Go

package s3api
import "testing"
func TestComputePackedPolicySize(t *testing.T) {
cases := []struct {
name string
policyLen int
empty bool
want int64
}{
{"empty -> nil", 0, true, 0},
{"tiny policy -> 0%", 10, false, 0},
{"half budget -> 50%", sessionPolicyBudgetBytes / 2, false, 50},
{"full budget -> 100%", sessionPolicyBudgetBytes, false, 100},
{"oversized -> capped at 100", sessionPolicyBudgetBytes * 3, false, 100},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
policy := repeat('a', tc.policyLen)
got := computePackedPolicySize(policy)
switch {
case tc.empty:
if got != nil {
t.Fatalf("expected nil for empty input, got %d", *got)
}
case got == nil:
t.Fatalf("expected non-nil result, got nil")
case *got != tc.want:
t.Fatalf("got=%d want=%d", *got, tc.want)
}
})
}
}