iam: cover the managed-provider jti replay flag end to end

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
user.emailandDevin committed 2026-10-25 08:02:09 -07:00
1 parent e655ce9057
commit c2ea089519
2 files changed
+96

No files matched your search

@@ -649,3 +649,62 @@ func TestSameIssuerRecordsShareOneProvider(t *testing.T) {
"a changed record kept the shared provider")
assert.True(t, stsKnowsIssuerForAccount(t, mgr, persistTestAPIIssuer, "222222222222"))
}
// The replay flag is part of what a provider is built from: two records that
// differ only in it must not share a provider, and flipping it on a record
// must rebuild.
func TestOIDCProviderFingerprintsSeparateReplayFlag(t *testing.T) {
disabled := false
base := &OIDCProviderRecord{
ARN: "arn:aws:iam::111111111111:oidc-provider/issuer.example", URL: "https://issuer.example",
ClientIDs: []string{"aud"},
}
off := *base
off.JTIReplayProtectionEnabled = &disabled
assert.NotEqual(t, oidcProviderConfigFingerprint(base), oidcProviderConfigFingerprint(&off),
"records differing only in the replay flag share a config fingerprint")
assert.NotEqual(t, oidcProviderFingerprint(base), oidcProviderFingerprint(&off),
"a flipped replay flag does not rebuild the provider")
}
// A config-file provider's jtiReplayProtectionEnabled rides the record into
// the runtime build path, so a mirrored static provider keeps the flag the
// provider factory would have applied.
func TestStaticOIDCProviderRecordsCarryJTIReplayFlag(t *testing.T) {
records := staticOIDCProviderRecords(&sts.STSConfig{
AccountId: "111111111111",
Providers: []*sts.ProviderConfig{
{
Name: "k8s", Type: sts.ProviderTypeOIDC, Enabled: true,
Config: map[string]interface{}{
"issuer": "https://k8s.example",
"clientId": "sts.amazonaws.com",
"jtiReplayProtectionEnabled": false,
},
},
{
Name: "plain", Type: sts.ProviderTypeOIDC, Enabled: true,
Config: map[string]interface{}{
"issuer": "https://issuer.example",
"clientId": "sts.amazonaws.com",
},
},
},
})
require.Len(t, records, 2)
var flagged, plain *OIDCProviderRecord
for _, rec := range records {
if rec.URL == "https://k8s.example" {
flagged = rec
} else {
plain = rec
}
}
require.NotNil(t, flagged)
require.NotNil(t, flagged.JTIReplayProtectionEnabled)
assert.False(t, *flagged.JTIReplayProtectionEnabled)
require.NotNil(t, plain)
assert.Nil(t, plain.JTIReplayProtectionEnabled)
}
@@ -497,3 +497,40 @@ func TestIamGrpc_DeleteOIDCProviderDoesNotDeleteAProviderReplacedMeanwhile(t *te
require.NoError(t, err, "the replacement record was deleted")
assert.Equal(t, []string{"new"}, rec.ClientIDs)
}
// The flag rides PutOIDCProvider into the record, is reported back by Get, and
// a Put that does not carry it keeps the stored value.
func TestIamGrpc_PutOIDCProviderJTIReplayProtectionFlag(t *testing.T) {
s, ctx, providers, _ := newSTSTestServer(t)
disabled, enabled := false, true
put, err := s.PutOIDCProvider(ctx, &iam_pb.PutOIDCProviderRequest{
IssuerUrl: "https://oidc.example", ClientIds: []string{"aud"},
JtiReplayProtectionEnabled: &disabled,
})
require.NoError(t, err)
got, err := s.GetOIDCProvider(ctx, &iam_pb.GetOIDCProviderRequest{IssuerUrl: "https://oidc.example"})
require.NoError(t, err)
require.NotNil(t, got.Provider.JtiReplayProtectionEnabled)
assert.False(t, *got.Provider.JtiReplayProtectionEnabled)
_, err = s.PutOIDCProvider(ctx, &iam_pb.PutOIDCProviderRequest{
IssuerUrl: "https://oidc.example", ClientIds: []string{"aud2"},
})
require.NoError(t, err)
rec, err := providers.GetProviderByARN(context.Background(), "", put.Arn)
require.NoError(t, err)
require.NotNil(t, rec.JTIReplayProtectionEnabled)
assert.False(t, *rec.JTIReplayProtectionEnabled)
_, err = s.PutOIDCProvider(ctx, &iam_pb.PutOIDCProviderRequest{
IssuerUrl: "https://oidc.example", ClientIds: []string{"aud"},
JtiReplayProtectionEnabled: &enabled,
})
require.NoError(t, err)
rec, err = providers.GetProviderByARN(context.Background(), "", put.Arn)
require.NoError(t, err)
require.NotNil(t, rec.JTIReplayProtectionEnabled)
assert.True(t, *rec.JTIReplayProtectionEnabled)
}