2323)
2424
2525func TestConstants (t * testing.T ) {
26- assert .Equal (t , defaultAPIKeySelector , " api_key" )
26+ assert .Equal (t , defaultKeySelectorExpression , `[' api_key']` )
2727 assert .Equal (t , invalidApiKeyMsg , "the API Key provided is invalid" )
2828}
2929
@@ -32,13 +32,11 @@ func TestNewApiKeyIdentityAllNamespaces(t *testing.T) {
3232 defer ctrl .Finish ()
3333
3434 selector , _ := k8s_labels .Parse ("planet=coruscant" )
35- apiKey := NewApiKeyIdentity ("jedi" , selector , "" , [] string {} , mock_auth .NewMockAuthCredentials (ctrl ), testAPIKeyK8sClient , context .TODO ())
35+ apiKey := NewApiKeyIdentity ("jedi" , selector , "" , "" , mock_auth .NewMockAuthCredentials (ctrl ), testAPIKeyK8sClient , context .TODO ())
3636
3737 assert .Equal (t , apiKey .Name , "jedi" )
3838 assert .Equal (t , apiKey .LabelSelectors .String (), "planet=coruscant" )
3939 assert .Equal (t , apiKey .Namespace , "" )
40- assert .Equal (t , len (apiKey .KeySelectors ), 1 )
41- assert .Equal (t , apiKey .KeySelectors [0 ], defaultAPIKeySelector )
4240 assert .Equal (t , len (apiKey .secrets ), 2 )
4341 _ , exists := apiKey .secrets ["ObiWanKenobiLightSaber" ]
4442 assert .Check (t , exists )
@@ -53,13 +51,11 @@ func TestNewApiKeyIdentitySingleNamespace(t *testing.T) {
5351 defer ctrl .Finish ()
5452
5553 selector , _ := k8s_labels .Parse ("planet=coruscant" )
56- apiKey := NewApiKeyIdentity ("jedi" , selector , "ns1" , [] string {} , mock_auth .NewMockAuthCredentials (ctrl ), testAPIKeyK8sClient , context .TODO ())
54+ apiKey := NewApiKeyIdentity ("jedi" , selector , "ns1" , "" , mock_auth .NewMockAuthCredentials (ctrl ), testAPIKeyK8sClient , context .TODO ())
5755
5856 assert .Equal (t , apiKey .Name , "jedi" )
5957 assert .Equal (t , apiKey .LabelSelectors .String (), "planet=coruscant" )
6058 assert .Equal (t , apiKey .Namespace , "ns1" )
61- assert .Equal (t , len (apiKey .KeySelectors ), 1 )
62- assert .Equal (t , apiKey .KeySelectors [0 ], defaultAPIKeySelector )
6359 assert .Equal (t , len (apiKey .secrets ), 1 )
6460 _ , exists := apiKey .secrets ["ObiWanKenobiLightSaber" ]
6561 assert .Check (t , exists )
@@ -74,14 +70,11 @@ func TestNewApiKeyIdentityMultipleKeySelectors(t *testing.T) {
7470 defer ctrl .Finish ()
7571
7672 selector , _ := k8s_labels .Parse ("planet=coruscant" )
77- apiKey := NewApiKeyIdentity ("jedi" , selector , "ns1" , [] string { " no_op" , " api_key_2" } , mock_auth .NewMockAuthCredentials (ctrl ), testAPIKeyK8sClient , context .TODO ())
73+ apiKey := NewApiKeyIdentity ("jedi" , selector , "ns1" , "[' no_op',' api_key_2']" , mock_auth .NewMockAuthCredentials (ctrl ), testAPIKeyK8sClient , context .TODO ())
7874
7975 assert .Equal (t , apiKey .Name , "jedi" )
8076 assert .Equal (t , apiKey .LabelSelectors .String (), "planet=coruscant" )
8177 assert .Equal (t , apiKey .Namespace , "ns1" )
82- assert .Equal (t , len (apiKey .KeySelectors ), 2 )
83- assert .Equal (t , apiKey .KeySelectors [0 ], "no_op" )
84- assert .Equal (t , apiKey .KeySelectors [1 ], "api_key_2" )
8578 assert .Equal (t , len (apiKey .secrets ), 1 )
8679 _ , exists := apiKey .secrets ["ObiWanKenobiLightSaber" ]
8780 assert .Check (t , ! exists )
@@ -102,7 +95,7 @@ func TestCallSuccess(t *testing.T) {
10295 authCredMock .EXPECT ().GetCredentialsFromReq (gomock .Any ()).Return ("ObiWanKenobiLightSaber" , nil )
10396
10497 selector , _ := k8s_labels .Parse ("planet=coruscant" )
105- apiKey := NewApiKeyIdentity ("jedi" , selector , "" , [] string {} , authCredMock , testAPIKeyK8sClient , context .TODO ())
98+ apiKey := NewApiKeyIdentity ("jedi" , selector , "" , "" , authCredMock , testAPIKeyK8sClient , context .TODO ())
10699 auth , err := apiKey .Call (pipelineMock , context .TODO ())
107100
108101 assert .NilError (t , err )
@@ -118,7 +111,7 @@ func TestCallNoApiKeyFail(t *testing.T) {
118111 authCredMock .EXPECT ().GetCredentialsFromReq (gomock .Any ()).Return ("" , fmt .Errorf ("something went wrong getting the API Key" ))
119112
120113 selector , _ := k8s_labels .Parse ("planet=coruscant" )
121- apiKey := NewApiKeyIdentity ("jedi" , selector , "" , [] string {} , authCredMock , testAPIKeyK8sClient , context .TODO ())
114+ apiKey := NewApiKeyIdentity ("jedi" , selector , "" , "" , authCredMock , testAPIKeyK8sClient , context .TODO ())
122115
123116 _ , err := apiKey .Call (pipelineMock , context .TODO ())
124117
@@ -134,15 +127,15 @@ func TestCallInvalidApiKeyFail(t *testing.T) {
134127 authCredMock .EXPECT ().GetCredentialsFromReq (gomock .Any ()).Return ("ASithLightSaber" , nil )
135128
136129 selector , _ := k8s_labels .Parse ("planet=coruscant" )
137- apiKey := NewApiKeyIdentity ("jedi" , selector , "" , [] string {} , authCredMock , testAPIKeyK8sClient , context .TODO ())
130+ apiKey := NewApiKeyIdentity ("jedi" , selector , "" , "" , authCredMock , testAPIKeyK8sClient , context .TODO ())
138131 _ , err := apiKey .Call (pipelineMock , context .TODO ())
139132
140133 assert .Error (t , err , "the API Key provided is invalid" )
141134}
142135
143136func TestLoadSecretsSuccess (t * testing.T ) {
144137 selector , _ := k8s_labels .Parse ("planet=coruscant" )
145- apiKey := NewApiKeyIdentity ("X-API-KEY" , selector , "" , [] string {} , nil , testAPIKeyK8sClient , nil )
138+ apiKey := NewApiKeyIdentity ("X-API-KEY" , selector , "" , "" , nil , testAPIKeyK8sClient , nil )
146139
147140 err := apiKey .loadSecrets (context .TODO ())
148141 assert .NilError (t , err )
@@ -159,7 +152,7 @@ func TestLoadSecretsSuccess(t *testing.T) {
159152
160153func TestLoadSecretsFail (t * testing.T ) {
161154 selector , _ := k8s_labels .Parse ("planet=coruscant" )
162- apiKey := NewApiKeyIdentity ("X-API-KEY" , selector , "" , [] string {} , nil , & flawedAPIkeyK8sClient {}, context .TODO ())
155+ apiKey := NewApiKeyIdentity ("X-API-KEY" , selector , "" , "" , nil , & flawedAPIkeyK8sClient {}, context .TODO ())
163156
164157 err := apiKey .loadSecrets (context .TODO ())
165158 assert .Error (t , err , "something terribly wrong happened" )
@@ -173,7 +166,7 @@ func BenchmarkAPIKeyAuthn(b *testing.B) {
173166 authCredMock := mock_auth .NewMockAuthCredentials (ctrl )
174167 authCredMock .EXPECT ().GetCredentialsFromReq (gomock .Any ()).Return ("ObiWanKenobiLightSaber" , nil ).MinTimes (1 )
175168 selector , _ := k8s_labels .Parse ("planet=coruscant" )
176- apiKey := NewApiKeyIdentity ("jedi" , selector , "" , [] string {} , authCredMock , testAPIKeyK8sClient , context .TODO ())
169+ apiKey := NewApiKeyIdentity ("jedi" , selector , "" , "" , authCredMock , testAPIKeyK8sClient , context .TODO ())
177170
178171 var err error
179172 b .ResetTimer ()
0 commit comments