Skip to content

Commit

Permalink
Fix other kube tests
Browse files Browse the repository at this point in the history
  • Loading branch information
strideynet committed Jan 3, 2025
1 parent ae737c0 commit d9aadb0
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion lib/kube/token/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ func TestIDTokenValidator_Validate(t *testing.T) {
review *v1.TokenReview
kubeVersion *version.Info
wantResult *ValidationResult
wantAttrs *workloadidentityv1pb.JoinAttrsKubernetes
clusterAudiences []string
expectedAudiences []string
expectedError error
Expand Down Expand Up @@ -200,6 +201,16 @@ func TestIDTokenValidator_Validate(t *testing.T) {
Username: "system:serviceaccount:namespace:my-service-account",
// Raw will be filled in during test run to value of review
},
wantAttrs: &workloadidentityv1pb.JoinAttrsKubernetes{
Subject: "system:serviceaccount:namespace:my-service-account",
Pod: &workloadidentityv1pb.JoinAttrsKubernetesPod{
Name: "podA",
},
ServiceAccount: &workloadidentityv1pb.JoinAttrsKubernetesServiceAccount{
Name: "my-service-account",
Namespace: "namespace",
},
},
kubeVersion: &boundTokenKubernetesVersion,
expectedError: nil,
// As the cluster doesn't have default audiences, we should not set
Expand Down Expand Up @@ -230,6 +241,16 @@ func TestIDTokenValidator_Validate(t *testing.T) {
Username: "system:serviceaccount:namespace:my-service-account",
// Raw will be filled in during test run to value of review
},
wantAttrs: &workloadidentityv1pb.JoinAttrsKubernetes{
Subject: "system:serviceaccount:namespace:my-service-account",
Pod: &workloadidentityv1pb.JoinAttrsKubernetesPod{
Name: "podA",
},
ServiceAccount: &workloadidentityv1pb.JoinAttrsKubernetesServiceAccount{
Name: "my-service-account",
Namespace: "namespace",
},
},
kubeVersion: &boundTokenKubernetesVersion,
expectedError: nil,
clusterAudiences: defaultKubeAudiences,
Expand Down Expand Up @@ -257,6 +278,13 @@ func TestIDTokenValidator_Validate(t *testing.T) {
Username: "system:serviceaccount:namespace:my-service-account",
// Raw will be filled in during test run to value of review
},
wantAttrs: &workloadidentityv1pb.JoinAttrsKubernetes{
Subject: "system:serviceaccount:namespace:my-service-account",
ServiceAccount: &workloadidentityv1pb.JoinAttrsKubernetesServiceAccount{
Name: "my-service-account",
Namespace: "namespace",
},
},
kubeVersion: &legacyTokenKubernetesVersion,
expectedError: nil,
},
Expand Down Expand Up @@ -356,7 +384,19 @@ func TestIDTokenValidator_Validate(t *testing.T) {
return
}
require.NoError(t, err)
require.Equal(t, tt.wantResult, result)
require.Empty(t, cmp.Diff(
tt.wantResult,
result,
cmpopts.IgnoreUnexported(ValidationResult{}),
))
if tt.wantAttrs != nil {
gotAttrs := result.JoinAttrs()
require.Empty(t, cmp.Diff(
tt.wantAttrs,
gotAttrs,
protocmp.Transform(),
))
}
})
}
}
Expand Down

0 comments on commit d9aadb0

Please sign in to comment.