use of io.fabric8.openshift.api.model.OAuthAccessTokenList in project cryostat by cryostatio.
the class OpenShiftAuthManagerTest method shouldReturnLogoutRedirectUrl.
@Test
void shouldReturnLogoutRedirectUrl() throws Exception {
Mockito.when(fs.readFile(Paths.get(Config.KUBERNETES_SERVICE_ACCOUNT_TOKEN_PATH))).thenReturn(new BufferedReader(new StringReader(SERVICE_ACCOUNT_TOKEN)));
Resource<OAuthAccessToken> token = Mockito.mock(Resource.class);
NonNamespaceOperation<OAuthAccessToken, OAuthAccessTokenList, Resource<OAuthAccessToken>> tokens = Mockito.mock(NonNamespaceOperation.class);
Mockito.when(client.oAuthAccessTokens()).thenReturn(tokens);
Mockito.when(tokens.withName(Mockito.anyString())).thenReturn(token);
Mockito.when(token.delete()).thenReturn(true);
HttpRequest<Buffer> req = Mockito.mock(HttpRequest.class);
HttpResponse<Buffer> resp = Mockito.mock(HttpResponse.class);
Mockito.when(webClient.get(Mockito.anyInt(), Mockito.anyString(), Mockito.anyString())).thenReturn(req);
Mockito.when(req.putHeader(Mockito.anyString(), Mockito.anyString())).thenReturn(req);
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock args) throws Throwable {
AsyncResult<HttpResponse<Buffer>> asyncResult = Mockito.mock(AsyncResult.class);
Mockito.when(asyncResult.result()).thenReturn(resp);
Mockito.when(resp.bodyAsJsonObject()).thenReturn(OAUTH_METADATA);
((Handler<AsyncResult<HttpResponse<Buffer>>>) args.getArgument(0)).handle(asyncResult);
return null;
}
}).when(req).send(Mockito.any());
String logoutRedirectUrl = mgr.logout(() -> "Bearer myToken").get();
MatcherAssert.assertThat(logoutRedirectUrl, Matchers.equalTo(EXPECTED_LOGOUT_REDIRECT_URL));
}
use of io.fabric8.openshift.api.model.OAuthAccessTokenList in project cryostat by cryostatio.
the class OpenShiftAuthManagerTest method shouldReturnLogoutRedirectUrl.
@Test
void shouldReturnLogoutRedirectUrl() throws Exception {
Resource<OAuthAccessToken> token = Mockito.mock(Resource.class);
NonNamespaceOperation<OAuthAccessToken, OAuthAccessTokenList, Resource<OAuthAccessToken>> tokens = Mockito.mock(NonNamespaceOperation.class);
Mockito.when(client.oAuthAccessTokens()).thenReturn(tokens);
Mockito.when(tokens.withName(Mockito.anyString())).thenReturn(token);
Mockito.when(token.delete()).thenReturn(true);
Mockito.when(client.adapt(OkHttpClient.class)).thenReturn(httpClient);
Mockito.when(client.getMasterUrl()).thenReturn(new URL("https://example.com"));
Response resp = Mockito.mock(Response.class);
ResponseBody body = Mockito.mock(ResponseBody.class);
Mockito.when(body.string()).thenReturn(OAUTH_METADATA);
Mockito.when(resp.body()).thenReturn(body);
Call call = Mockito.mock(Call.class);
Mockito.when(httpClient.newCall(Mockito.any(Request.class))).thenReturn(call);
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock args) throws Throwable {
Callback callback = args.getArgument(0);
callback.onResponse(call, resp);
return null;
}
}).when(call).enqueue(Mockito.any(Callback.class));
String logoutRedirectUrl = mgr.logout(() -> "Bearer myToken").get();
MatcherAssert.assertThat(logoutRedirectUrl, Matchers.equalTo(EXPECTED_LOGOUT_REDIRECT_URL));
}
use of io.fabric8.openshift.api.model.OAuthAccessTokenList in project cryostat by cryostatio.
the class OpenShiftAuthManagerTest method shouldThrowWhenTokenDeletionFailsOnLogout.
@ParameterizedTest
@NullSource
@ValueSource(booleans = { false })
void shouldThrowWhenTokenDeletionFailsOnLogout(Boolean deletionFailure) throws Exception {
Mockito.when(fs.readFile(Paths.get(Config.KUBERNETES_SERVICE_ACCOUNT_TOKEN_PATH))).thenReturn(new BufferedReader(new StringReader(SERVICE_ACCOUNT_TOKEN)));
Resource<OAuthAccessToken> token = Mockito.mock(Resource.class);
NonNamespaceOperation<OAuthAccessToken, OAuthAccessTokenList, Resource<OAuthAccessToken>> tokens = Mockito.mock(NonNamespaceOperation.class);
Mockito.when(client.oAuthAccessTokens()).thenReturn(tokens);
Mockito.when(tokens.withName(Mockito.anyString())).thenReturn(token);
Mockito.when(token.delete()).thenReturn(deletionFailure);
Assertions.assertThrows(TokenNotFoundException.class, () -> mgr.logout(() -> "Bearer myToken").get());
}
Aggregations