Skip to content

Add support for bearer token auth #3401

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix tests to account for new jitter
  • Loading branch information
dagnir committed Sep 2, 2022
commit 85799cd900e7972fb2f7e076442da8e8b20e2739
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ public void token_is_retrieved_automatically_when_prefetch_time_is_set() throws
mockTokenManager.storeToken(cachedDiskToken);

when(ssoOidcClient.createToken(any(CreateTokenRequest.class)))
.thenReturn(getDefaultServiceResponse().accessToken("tokenGreaterThanStaleButLessThanPrefetch").expiresIn(200)
.thenReturn(getDefaultServiceResponse().accessToken("tokenGreaterThanStaleButLessThanPrefetch").expiresIn(1)
.build())
.thenReturn(getDefaultServiceResponse().accessToken("tokenVeryHighExpiry").expiresIn(20000).build());

Expand All @@ -424,14 +424,14 @@ public void token_is_retrieved_automatically_when_prefetch_time_is_set() throws
.build();

Thread.sleep(100);
verify(ssoOidcClient, times(1)).createToken(any(CreateTokenRequest.class));
SdkToken sdkToken = tokenProvider.resolveToken();
assertThat(sdkToken.token()).isEqualTo("tokenGreaterThanStaleButLessThanPrefetch");

Thread.sleep(100);
Thread.sleep(1000);
// Sleep to make sure Async prefetch thread gets picked up and it calls createToken to get new token.
verify(ssoOidcClient, times(2)).createToken(any(CreateTokenRequest.class));
verify(ssoOidcClient, times(1)).createToken(any(CreateTokenRequest.class));
SdkToken highExpiryDateToken = tokenProvider.resolveToken();
Thread.sleep(1000);
assertThat(highExpiryDateToken.token()).isEqualTo("tokenVeryHighExpiry");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void tokenReadFromService_And_DiscCacheUpdate_whenTokenInCacheIsExpired()
}

@Test
public void tokenProvider_with_customStaleTime_refreshes_token() throws IOException {
public void tokenProvider_with_customStaleTime_refreshes_token() throws IOException, InterruptedException {

// Creating a token and saving to disc
OnDiskTokenManager onDiskTokenManager = OnDiskTokenManager.create(testSessionName);
Expand All @@ -160,6 +160,7 @@ public void tokenProvider_with_customStaleTime_refreshes_token() throws IOExcept
assertThat(loadedFromDiscAfterSecondRefresh).hasValue(firstResolvedToken);

// Resolve second time
Thread.sleep(1000);
SsoOidcToken secondResolvedToken = (SsoOidcToken) awsTokenProvider.resolveToken();
assert_oldCachedToken_isNoSameAs_NewResolvedToken(firstResolvedToken, secondResolvedToken);
loadedFromDiscAfterSecondRefresh = onDiskTokenManager.loadToken();
Expand Down