|
81 | 81 | import static java.time.Clock.systemUTC;
|
82 | 82 | import static org.elasticsearch.repositories.ESBlobStoreTestCase.randomBytes;
|
83 | 83 | import static org.hamcrest.Matchers.containsString;
|
| 84 | +import static org.hamcrest.Matchers.equalTo; |
84 | 85 | import static org.hamcrest.Matchers.notNullValue;
|
85 | 86 | import static org.hamcrest.Matchers.nullValue;
|
86 | 87 | import static org.mockito.Matchers.any;
|
@@ -496,6 +497,29 @@ public void testComputeSecretKeyIsConsistent() throws Exception {
|
496 | 497 | assertArrayEquals(key.getEncoded(), key2.getEncoded());
|
497 | 498 | }
|
498 | 499 |
|
| 500 | + public void testTokenExpiryConfig() { |
| 501 | + TimeValue expiration = TokenService.TOKEN_EXPIRATION.get(tokenServiceEnabledSettings); |
| 502 | + assertThat(expiration, equalTo(TimeValue.timeValueMinutes(20L))); |
| 503 | + // Configure Minimum expiration |
| 504 | + tokenServiceEnabledSettings = Settings.builder().put(TokenService.TOKEN_EXPIRATION.getKey(), "1s").build(); |
| 505 | + expiration = TokenService.TOKEN_EXPIRATION.get(tokenServiceEnabledSettings); |
| 506 | + assertThat(expiration, equalTo(TimeValue.timeValueSeconds(1L))); |
| 507 | + // Configure Maximum expiration |
| 508 | + tokenServiceEnabledSettings = Settings.builder().put(TokenService.TOKEN_EXPIRATION.getKey(), "60m").build(); |
| 509 | + expiration = TokenService.TOKEN_EXPIRATION.get(tokenServiceEnabledSettings); |
| 510 | + assertThat(expiration, equalTo(TimeValue.timeValueHours(1L))); |
| 511 | + // Outside range should fail |
| 512 | + tokenServiceEnabledSettings = Settings.builder().put(TokenService.TOKEN_EXPIRATION.getKey(), "1ms").build(); |
| 513 | + IllegalArgumentException ile = expectThrows(IllegalArgumentException.class, |
| 514 | + () -> TokenService.TOKEN_EXPIRATION.get(tokenServiceEnabledSettings)); |
| 515 | + assertThat(ile.getMessage(), |
| 516 | + containsString("failed to parse value [1ms] for setting [xpack.security.authc.token.timeout], must be >= [1s]")); |
| 517 | + tokenServiceEnabledSettings = Settings.builder().put(TokenService.TOKEN_EXPIRATION.getKey(), "120m").build(); |
| 518 | + ile = expectThrows(IllegalArgumentException.class, () -> TokenService.TOKEN_EXPIRATION.get(tokenServiceEnabledSettings)); |
| 519 | + assertThat(ile.getMessage(), |
| 520 | + containsString("failed to parse value [120m] for setting [xpack.security.authc.token.timeout], must be <= [1h]")); |
| 521 | + } |
| 522 | + |
499 | 523 | public void testTokenExpiry() throws Exception {
|
500 | 524 | ClockMock clock = ClockMock.frozen();
|
501 | 525 | TokenService tokenService = new TokenService(tokenServiceEnabledSettings, clock, client, securityIndex, clusterService);
|
|
0 commit comments