@@ -133,15 +133,43 @@ public void testNoConfig() {
133
133
assertNull (auth );
134
134
}
135
135
136
+ /**
137
+ * This class is a subclass of our authenticator factory and is
138
+ * simply a test to make sure that the subclass usecase works as expected.
139
+ */
140
+ public static class TestAuthFactorySubclass extends ConfigBasedAuthenticatorFactory {
141
+
142
+ public static Authenticator getAuthenticator (String serviceName ) {
143
+ // For testing purposes, just hard-code the service properties
144
+ // so we can simulate an alternate config source.
145
+ Map <String , String > authProps = new HashMap <>();
146
+ authProps .put (Authenticator .PROPNAME_AUTH_TYPE , "basic" );
147
+ authProps .put (Authenticator .PROPNAME_USERNAME , "myuser" );
148
+ authProps .put (Authenticator .PROPNAME_PASSWORD , "mypassword" );
149
+
150
+ Authenticator authenticator = createAuthenticator (authProps );
151
+
152
+ return authenticator ;
153
+ }
154
+ }
155
+
156
+ @ Test
157
+ public void testFactorySubclass () {
158
+
159
+ Authenticator auth = TestAuthFactorySubclass .getAuthenticator ("dont_care" );
160
+ assertNotNull (auth );
161
+ assertEquals (auth .authenticationType (), Authenticator .AUTHTYPE_BASIC );
162
+ }
163
+
136
164
@ Test
137
165
public void testFileCredentialsService1 () {
138
166
PowerMockito .spy (EnvironmentUtils .class );
139
167
PowerMockito .when (EnvironmentUtils .getenv ("IBM_CREDENTIALS_FILE" )).thenReturn (ALTERNATE_CRED_FILENAME );
140
- assertEquals (ALTERNATE_CRED_FILENAME , EnvironmentUtils .getenv ("IBM_CREDENTIALS_FILE" ));
168
+ assertEquals (EnvironmentUtils .getenv ("IBM_CREDENTIALS_FILE" ), ALTERNATE_CRED_FILENAME );
141
169
142
170
Authenticator auth = ConfigBasedAuthenticatorFactory .getAuthenticator ("service-1" );
143
171
assertNotNull (auth );
144
- assertEquals (Authenticator . AUTHTYPE_IAM , auth .authenticationType ());
172
+ assertEquals (auth .authenticationType (), Authenticator . AUTHTYPE_IAM );
145
173
}
146
174
147
175
@ Test
@@ -151,7 +179,7 @@ public void testFileCredentialsService2() {
151
179
152
180
Authenticator auth = ConfigBasedAuthenticatorFactory .getAuthenticator ("service2" );
153
181
assertNotNull (auth );
154
- assertEquals (Authenticator . AUTHTYPE_BASIC , auth .authenticationType ());
182
+ assertEquals (auth .authenticationType (), Authenticator . AUTHTYPE_BASIC );
155
183
}
156
184
157
185
@ Test
@@ -161,7 +189,7 @@ public void testFileCredentialsService3() {
161
189
162
190
Authenticator auth = ConfigBasedAuthenticatorFactory .getAuthenticator ("service3" );
163
191
assertNotNull (auth );
164
- assertEquals (Authenticator . AUTHTYPE_CP4D , auth .authenticationType ());
192
+ assertEquals (auth .authenticationType (), Authenticator . AUTHTYPE_CP4D );
165
193
}
166
194
167
195
@ Test
@@ -171,7 +199,7 @@ public void testFileCredentialsService4() {
171
199
172
200
Authenticator auth = ConfigBasedAuthenticatorFactory .getAuthenticator ("service4" );
173
201
assertNotNull (auth );
174
- assertEquals (Authenticator . AUTHTYPE_NOAUTH , auth .authenticationType ());
202
+ assertEquals (auth .authenticationType (), Authenticator . AUTHTYPE_NOAUTH );
175
203
}
176
204
177
205
@ Test
@@ -266,7 +294,7 @@ public void testFileCredentialsService5() {
266
294
267
295
Authenticator auth = ConfigBasedAuthenticatorFactory .getAuthenticator ("service5" );
268
296
assertNotNull (auth );
269
- assertEquals (Authenticator . AUTHTYPE_BEARER_TOKEN , auth .authenticationType ());
297
+ assertEquals (auth .authenticationType (), Authenticator . AUTHTYPE_BEARER_TOKEN );
270
298
}
271
299
272
300
@ Test (expectedExceptions = IllegalArgumentException .class )
@@ -304,11 +332,11 @@ public void testFileCredentialsError4() {
304
332
@ Test
305
333
public void testFileCredentialsSystemPropService1 () {
306
334
System .setProperty ("IBM_CREDENTIALS_FILE" , ALTERNATE_CRED_FILENAME );
307
- assertEquals (ALTERNATE_CRED_FILENAME , System .getProperty ("IBM_CREDENTIALS_FILE" ));
335
+ assertEquals (System .getProperty ("IBM_CREDENTIALS_FILE" ), ALTERNATE_CRED_FILENAME );
308
336
309
337
Authenticator auth = ConfigBasedAuthenticatorFactory .getAuthenticator ("service-1" );
310
338
assertNotNull (auth );
311
- assertEquals (Authenticator . AUTHTYPE_IAM , auth .authenticationType ());
339
+ assertEquals (auth .authenticationType (), Authenticator . AUTHTYPE_IAM );
312
340
System .clearProperty ("IBM_CREDENTIALS_FILE" );
313
341
}
314
342
@@ -319,7 +347,7 @@ public void testEnvCredentialsService1() {
319
347
320
348
Authenticator auth = ConfigBasedAuthenticatorFactory .getAuthenticator ("service-1" );
321
349
assertNotNull (auth );
322
- assertEquals (Authenticator . AUTHTYPE_IAM , auth .authenticationType ());
350
+ assertEquals (auth .authenticationType (), Authenticator . AUTHTYPE_IAM );
323
351
IamAuthenticator iamAuth = (IamAuthenticator ) auth ;
324
352
assertEquals (iamAuth .getApiKey (), "my-api-key" );
325
353
assertEquals (iamAuth .getClientId (), "my-client-id" );
@@ -335,7 +363,7 @@ public void testEnvCredentialsService6() {
335
363
336
364
Authenticator auth = ConfigBasedAuthenticatorFactory .getAuthenticator ("service6" );
337
365
assertNotNull (auth );
338
- assertEquals (Authenticator . AUTHTYPE_CP4D_SERVICE , auth .authenticationType ());
366
+ assertEquals (auth .authenticationType (), Authenticator . AUTHTYPE_CP4D_SERVICE );
339
367
CloudPakForDataServiceAuthenticator cp4dAuth = (CloudPakForDataServiceAuthenticator ) auth ;
340
368
assertEquals (cp4dAuth .getURL (), "https://service1/zen-data/internal" );
341
369
assertEquals (cp4dAuth .getServiceBrokerSecret (), "f8b7czjt701wy6253be5q8ad8f07kd08" );
@@ -349,7 +377,7 @@ public void testEnvCredentialsService7() {
349
377
350
378
Authenticator auth = ConfigBasedAuthenticatorFactory .getAuthenticator ("service7" );
351
379
assertNotNull (auth );
352
- assertEquals (Authenticator . AUTHTYPE_CONTAINER , auth .authenticationType ());
380
+ assertEquals (auth .authenticationType (), Authenticator . AUTHTYPE_CONTAINER );
353
381
ContainerAuthenticator containerAuth = (ContainerAuthenticator ) auth ;
354
382
assertEquals (containerAuth .getURL (), "https://iam.com/api" );
355
383
assertEquals (containerAuth .getCrTokenFilename (), "cr-token.txt" );
@@ -368,7 +396,7 @@ public void testEnvCredentialsService8() {
368
396
369
397
Authenticator auth = ConfigBasedAuthenticatorFactory .getAuthenticator ("service8" );
370
398
assertNotNull (auth );
371
- assertEquals (Authenticator . AUTHTYPE_VPC , auth .authenticationType ());
399
+ assertEquals (auth .authenticationType (), Authenticator . AUTHTYPE_VPC );
372
400
VpcInstanceAuthenticator containerAuth = (VpcInstanceAuthenticator ) auth ;
373
401
assertEquals (containerAuth .getIamProfileCrn (), "crn:iam-profile-1" );
374
402
assertNull (containerAuth .getIamProfileId ());
@@ -413,7 +441,7 @@ public void testVcapCredentialsDiscovery() {
413
441
414
442
Authenticator auth = ConfigBasedAuthenticatorFactory .getAuthenticator ("discovery" );
415
443
assertNotNull (auth );
416
- assertEquals (Authenticator . AUTHTYPE_BASIC , auth .authenticationType ());
444
+ assertEquals (auth .authenticationType (), Authenticator . AUTHTYPE_BASIC );
417
445
}
418
446
419
447
@ Test
@@ -422,6 +450,6 @@ public void testVcapCredentialsLT() {
422
450
423
451
Authenticator auth = ConfigBasedAuthenticatorFactory .getAuthenticator ("language_translator" );
424
452
assertNotNull (auth );
425
- assertEquals (Authenticator . AUTHTYPE_IAM , auth .authenticationType ());
453
+ assertEquals (auth .authenticationType (), Authenticator . AUTHTYPE_IAM );
426
454
}
427
455
}
0 commit comments