28
28
import org .elasticsearch .test .MockLogAppender ;
29
29
import org .elasticsearch .transport .Transport ;
30
30
import org .elasticsearch .xpack .core .security .authc .Authentication ;
31
+ import org .elasticsearch .xpack .core .security .authc .service .ServiceAccountSettings ;
31
32
import org .elasticsearch .xpack .core .security .authz .RoleDescriptor ;
32
33
import org .elasticsearch .xpack .core .security .support .ValidationTests ;
33
34
import org .elasticsearch .xpack .core .security .user .User ;
@@ -86,28 +87,6 @@ public void init() throws UnknownHostException {
86
87
new HttpTlsRuntimeCheck (builder .build (), new SetOnce <>(transport )));
87
88
}
88
89
89
- public void testIsServiceAccount () {
90
- final User user =
91
- new User (randomAlphaOfLengthBetween (3 , 8 ), randomArray (0 , 3 , String []::new , () -> randomAlphaOfLengthBetween (3 , 8 )));
92
- final Authentication .RealmRef authRealm ;
93
- final boolean authRealmIsForServiceAccount = randomBoolean ();
94
- if (authRealmIsForServiceAccount ) {
95
- authRealm = new Authentication .RealmRef (ServiceAccountService .REALM_NAME ,
96
- ServiceAccountService .REALM_TYPE ,
97
- randomAlphaOfLengthBetween (3 , 8 ));
98
- } else {
99
- authRealm = randomRealmRef ();
100
- }
101
- final Authentication .RealmRef lookupRealm = randomFrom (randomRealmRef (), null );
102
- final Authentication authentication = new Authentication (user , authRealm , lookupRealm );
103
-
104
- if (authRealmIsForServiceAccount && lookupRealm == null ) {
105
- assertThat (ServiceAccountService .isServiceAccount (authentication ), is (true ));
106
- } else {
107
- assertThat (ServiceAccountService .isServiceAccount (authentication ), is (false ));
108
- }
109
- }
110
-
111
90
public void testGetServiceAccountPrincipals () {
112
91
assertThat (ServiceAccountService .getServiceAccountPrincipals (),
113
92
equalTo (org .elasticsearch .common .collect .Set .of ("elastic/fleet-server" )));
@@ -266,12 +245,6 @@ public void testTryParseToken() throws IOException, IllegalAccessException {
266
245
}
267
246
}
268
247
269
- private Authentication .RealmRef randomRealmRef () {
270
- return new Authentication .RealmRef (randomAlphaOfLengthBetween (3 , 8 ),
271
- randomAlphaOfLengthBetween (3 , 8 ),
272
- randomAlphaOfLengthBetween (3 , 8 ));
273
- }
274
-
275
248
public void testTryAuthenticateBearerToken () throws ExecutionException , InterruptedException {
276
249
// Valid token
277
250
final PlainActionFuture <Authentication > future5 = new PlainActionFuture <>();
@@ -290,7 +263,7 @@ public void testTryAuthenticateBearerToken() throws ExecutionException, Interrup
290
263
new Authentication (
291
264
new User ("elastic/fleet-server" , Strings .EMPTY_ARRAY , "Service account - elastic/fleet-server" , null ,
292
265
org .elasticsearch .common .collect .Map .of ("_elastic_service_account" , true ), true ),
293
- new Authentication .RealmRef (ServiceAccountService .REALM_NAME , ServiceAccountService .REALM_TYPE , nodeName ),
266
+ new Authentication .RealmRef (ServiceAccountSettings .REALM_NAME , ServiceAccountSettings .REALM_TYPE , nodeName ),
294
267
null , Version .CURRENT , Authentication .AuthenticationType .TOKEN ,
295
268
org .elasticsearch .common .collect .Map .of ("_token_name" , "token1" )
296
269
)
@@ -369,7 +342,7 @@ public void testAuthenticateWithToken() throws ExecutionException, InterruptedEx
369
342
"Service account - elastic/fleet-server" , null ,
370
343
org .elasticsearch .common .collect .Map .of ("_elastic_service_account" , true ),
371
344
true ),
372
- new Authentication .RealmRef (ServiceAccountService .REALM_NAME , ServiceAccountService .REALM_TYPE , nodeName ),
345
+ new Authentication .RealmRef (ServiceAccountSettings .REALM_NAME , ServiceAccountSettings .REALM_TYPE , nodeName ),
373
346
null , Version .CURRENT , Authentication .AuthenticationType .TOKEN ,
374
347
org .elasticsearch .common .collect .Map .of ("_token_name" , token3 .getTokenName ())
375
348
)));
@@ -402,7 +375,7 @@ public void testGetRoleDescriptor() throws ExecutionException, InterruptedExcept
402
375
org .elasticsearch .common .collect .Map .of ("_elastic_service_account" , true ),
403
376
true ),
404
377
new Authentication .RealmRef (
405
- ServiceAccountService .REALM_NAME , ServiceAccountService .REALM_TYPE , randomAlphaOfLengthBetween (3 , 8 )),
378
+ ServiceAccountSettings .REALM_NAME , ServiceAccountSettings .REALM_TYPE , randomAlphaOfLengthBetween (3 , 8 )),
406
379
null ,
407
380
Version .CURRENT ,
408
381
Authentication .AuthenticationType .TOKEN ,
@@ -420,7 +393,7 @@ ServiceAccountService.REALM_NAME, ServiceAccountService.REALM_TYPE, randomAlphaO
420
393
new User (username , Strings .EMPTY_ARRAY , "Service account - " + username , null ,
421
394
org .elasticsearch .common .collect .Map .of ("_elastic_service_account" , true ), true ),
422
395
new Authentication .RealmRef (
423
- ServiceAccountService .REALM_NAME , ServiceAccountService .REALM_TYPE , randomAlphaOfLengthBetween (3 , 8 )),
396
+ ServiceAccountSettings .REALM_NAME , ServiceAccountSettings .REALM_TYPE , randomAlphaOfLengthBetween (3 , 8 )),
424
397
null ,
425
398
Version .CURRENT ,
426
399
Authentication .AuthenticationType .TOKEN ,
@@ -450,7 +423,8 @@ public void testTlsRequired() {
450
423
451
424
final PlainActionFuture <RoleDescriptor > future2 = new PlainActionFuture <>();
452
425
final Authentication authentication = new Authentication (mock (User .class ),
453
- new Authentication .RealmRef (ServiceAccountService .REALM_NAME , ServiceAccountService .REALM_TYPE ,
426
+ new Authentication .RealmRef (
427
+ ServiceAccountSettings .REALM_NAME , ServiceAccountSettings .REALM_TYPE ,
454
428
randomAlphaOfLengthBetween (3 , 8 )),
455
429
null );
456
430
service .getRoleDescriptor (authentication , future2 );
0 commit comments