Skip to content

Commit

Permalink
Additional test cases
Browse files Browse the repository at this point in the history
Signed-off-by: Max Cao <macao@redhat.com>
  • Loading branch information
maxcao13 committed Nov 5, 2024
1 parent 2f3d492 commit 67740fd
Showing 1 changed file with 95 additions and 1 deletion.
96 changes: 95 additions & 1 deletion pkg/scaling/resolver/scale_resolvers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,38 @@ func TestResolveAuthRef(t *testing.T) {
expected: map[string]string{"token": bsatData},
expectedPodIdentity: kedav1alpha1.AuthPodIdentity{Provider: kedav1alpha1.PodIdentityProviderNone},
},
{
name: "triggerauth exists bound service account token, but expiry invalid",
existing: []runtime.Object{
&kedav1alpha1.TriggerAuthentication{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: triggerAuthenticationName,
},
Spec: kedav1alpha1.TriggerAuthenticationSpec{
PodIdentity: &kedav1alpha1.AuthPodIdentity{
Provider: kedav1alpha1.PodIdentityProviderNone,
},
BoundServiceAccountToken: []kedav1alpha1.BoundServiceAccountToken{
{
Parameter: "token",
ServiceAccountName: bsatSAName,
Expiry: "10g",
},
},
},
},
&corev1.ServiceAccount{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: bsatSAName,
},
},
},
soar: &kedav1alpha1.AuthenticationRef{Name: triggerAuthenticationName},
expected: map[string]string{"token": ""},
expectedPodIdentity: kedav1alpha1.AuthPodIdentity{Provider: kedav1alpha1.PodIdentityProviderNone},
},
{
name: "clustertriggerauth exists, podidentity nil",
existing: []runtime.Object{
Expand Down Expand Up @@ -647,6 +679,68 @@ func TestResolveAuthRef(t *testing.T) {
expected: map[string]string{},
expectedPodIdentity: kedav1alpha1.AuthPodIdentity{Provider: kedav1alpha1.PodIdentityProviderGCP},
},
{
name: "clustertriggerauth exists bound service account token",
existing: []runtime.Object{
&kedav1alpha1.ClusterTriggerAuthentication{
ObjectMeta: metav1.ObjectMeta{
Name: triggerAuthenticationName,
},
Spec: kedav1alpha1.TriggerAuthenticationSpec{
PodIdentity: &kedav1alpha1.AuthPodIdentity{
Provider: kedav1alpha1.PodIdentityProviderNone,
},
BoundServiceAccountToken: []kedav1alpha1.BoundServiceAccountToken{
{
Parameter: "token",
ServiceAccountName: bsatSAName,
Expiry: bsatExpiry,
},
},
},
},
&corev1.ServiceAccount{
ObjectMeta: metav1.ObjectMeta{
Namespace: clusterNamespace,
Name: bsatSAName,
},
},
},
soar: &kedav1alpha1.AuthenticationRef{Name: triggerAuthenticationName, Kind: "ClusterTriggerAuthentication"},
expected: map[string]string{"token": bsatData},
expectedPodIdentity: kedav1alpha1.AuthPodIdentity{Provider: kedav1alpha1.PodIdentityProviderNone},
},
{
name: "clustertriggerauth exists bound service account token but service account in the wrong namespace",
existing: []runtime.Object{
&kedav1alpha1.ClusterTriggerAuthentication{
ObjectMeta: metav1.ObjectMeta{
Name: triggerAuthenticationName,
},
Spec: kedav1alpha1.TriggerAuthenticationSpec{
PodIdentity: &kedav1alpha1.AuthPodIdentity{
Provider: kedav1alpha1.PodIdentityProviderNone,
},
BoundServiceAccountToken: []kedav1alpha1.BoundServiceAccountToken{
{
Parameter: "token",
ServiceAccountName: bsatSAName,
Expiry: bsatExpiry,
},
},
},
},
&corev1.ServiceAccount{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: bsatSAName,
},
},
},
soar: &kedav1alpha1.AuthenticationRef{Name: triggerAuthenticationName, Kind: "ClusterTriggerAuthentication"},
expected: map[string]string{"token": ""},
expectedPodIdentity: kedav1alpha1.AuthPodIdentity{Provider: kedav1alpha1.PodIdentityProviderNone},
},
}
ctrl := gomock.NewController(t)
var secretsLister corev1listers.SecretLister
Expand All @@ -658,7 +752,7 @@ func TestResolveAuthRef(t *testing.T) {
Token: bsatData,
},
}
mockServiceAccountInterface.EXPECT().CreateToken(gomock.Any(), gomock.Eq(bsatSAName), gomock.Any(), gomock.Any()).Return(tokenRequest, nil)
mockServiceAccountInterface.EXPECT().CreateToken(gomock.Any(), gomock.Eq(bsatSAName), gomock.Any(), gomock.Any()).Return(tokenRequest, nil).AnyTimes()

for _, test := range tests {
test := test
Expand Down

0 comments on commit 67740fd

Please sign in to comment.