use of co.cask.cdap.security.authentication.client.AccessToken in project cdap-ingest by caskdata.
the class RestStreamClientTest method testNotAuthorizedEmptyTokenTruncate.
@Test
public void testNotAuthorizedEmptyTokenTruncate() throws IOException {
AuthenticationClient authClient = Mockito.mock(AuthenticationClient.class);
AccessToken accessToken = Mockito.mock(AccessToken.class);
Mockito.when(authClient.getAccessToken()).thenReturn(accessToken);
Mockito.when(accessToken.getValue()).thenReturn(StringUtils.EMPTY);
Mockito.when(accessToken.getTokenType()).thenReturn("Bearer");
createClient(authClient);
try {
streamClient.truncate(TestUtils.AUTH_STREAM_NAME);
Assert.fail("Expected HttpFailureException");
} catch (HttpFailureException e) {
Assert.assertEquals(HttpURLConnection.HTTP_UNAUTHORIZED, e.getStatusCode());
}
}
use of co.cask.cdap.security.authentication.client.AccessToken in project cdap-ingest by caskdata.
the class RestStreamWriterTest method testSuccessAuthorizedStringWrite.
@Test
public void testSuccessAuthorizedStringWrite() throws IOException, InterruptedException, ExecutionException {
AuthenticationClient authClient = Mockito.mock(AuthenticationClient.class);
AccessToken accessToken = Mockito.mock(AccessToken.class);
Mockito.when(authClient.getAccessToken()).thenReturn(accessToken);
Mockito.when(authClient.isAuthEnabled()).thenReturn(true);
Mockito.when(accessToken.getValue()).thenReturn(RestTest.AUTH_TOKEN);
Mockito.when(accessToken.getTokenType()).thenReturn("Bearer");
createClient(authClient);
streamWriter = streamClient.createWriter(TestUtils.AUTH_STREAM_NAME + TestUtils.WRITER_TEST_STREAM_NAME_POSTFIX);
streamWriter.write(RestTest.EXPECTED_WRITER_CONTENT, Charsets.UTF_8).get();
}
use of co.cask.cdap.security.authentication.client.AccessToken in project cdap-ingest by caskdata.
the class RestStreamClientTest method testSuccessAuthSetTTL.
@Test
public void testSuccessAuthSetTTL() throws IOException {
AuthenticationClient authClient = Mockito.mock(AuthenticationClient.class);
AccessToken accessToken = Mockito.mock(AccessToken.class);
Mockito.when(authClient.getAccessToken()).thenReturn(accessToken);
Mockito.when(accessToken.getValue()).thenReturn(AUTH_TOKEN);
Mockito.when(accessToken.getTokenType()).thenReturn("Bearer");
createClient(authClient);
streamClient.setTTL(TestUtils.SUCCESS_STREAM_NAME, STREAM_TTL);
}
use of co.cask.cdap.security.authentication.client.AccessToken in project cdap-ingest by caskdata.
the class RestStreamClientTest method testNotAuthorizedEmptyTokenCreate.
@Test
public void testNotAuthorizedEmptyTokenCreate() throws IOException {
AuthenticationClient authClient = Mockito.mock(AuthenticationClient.class);
AccessToken accessToken = Mockito.mock(AccessToken.class);
Mockito.when(authClient.getAccessToken()).thenReturn(accessToken);
Mockito.when(accessToken.getValue()).thenReturn(StringUtils.EMPTY);
Mockito.when(accessToken.getTokenType()).thenReturn("Bearer");
createClient(authClient);
try {
streamClient.create(TestUtils.AUTH_STREAM_NAME);
Assert.fail("Expected HttpFailureException");
} catch (HttpFailureException e) {
Assert.assertEquals(HttpURLConnection.HTTP_UNAUTHORIZED, e.getStatusCode());
}
}
use of co.cask.cdap.security.authentication.client.AccessToken in project cdap-ingest by caskdata.
the class RestStreamClientTest method testSuccessAuthCreate.
@Test
public void testSuccessAuthCreate() throws IOException {
AuthenticationClient authClient = Mockito.mock(AuthenticationClient.class);
AccessToken accessToken = Mockito.mock(AccessToken.class);
Mockito.when(authClient.getAccessToken()).thenReturn(accessToken);
Mockito.when(accessToken.getValue()).thenReturn(AUTH_TOKEN);
Mockito.when(accessToken.getTokenType()).thenReturn("Bearer");
createClient(authClient);
streamClient.create(TestUtils.SUCCESS_STREAM_NAME);
}
Aggregations