use of org.projectnessie.client.http.RequestContext in project nessie by projectnessie.
the class TestAwsAuthProvider method checkAuth.
void checkAuth(NessieAuthentication authentication, String expectedRegion, String expectedKeyId) {
assertThat(authentication).isInstanceOf(HttpAuthentication.class);
HttpAuthentication httpAuthentication = (HttpAuthentication) authentication;
// Intercept the call to HttpClient.register(RequestFilter) and extract the RequestFilter for
// our test
RequestFilter[] authFilter = new RequestFilter[1];
HttpClient.Builder client = Mockito.mock(HttpClient.Builder.class);
Mockito.doAnswer(invocationOnMock -> {
Object[] args = invocationOnMock.getArguments();
if (args.length == 1 && args[0] instanceof RequestFilter && args[0].getClass().getSimpleName().equalsIgnoreCase("AwsHttpAuthenticationFilter")) {
authFilter[0] = (RequestFilter) args[0];
}
return null;
}).when(client).addRequestFilter(Mockito.any());
httpAuthentication.applyToHttpClient(client);
// Check that the registered RequestFilter works as expected (sets the right HTTP headers)
assertThat(authFilter[0]).isInstanceOf(RequestFilter.class);
HttpHeaders headers = new HttpHeaders();
RequestContext context = new RequestContext(headers, URI.create("http://localhost/"), Method.GET, null);
authFilter[0].filter(context);
assertThat(headers.asMap()).containsKey("Authorization").containsKey("X-Amz-Date").extracting("Authorization", InstanceOfAssertFactories.iterable(String.class)).first(InstanceOfAssertFactories.STRING).containsSequence(expectedRegion).containsSequence(expectedKeyId).containsSequence("Signature=").containsSequence("Credential=");
}
use of org.projectnessie.client.http.RequestContext in project nessie by projectnessie.
the class TestBearerAuthenticationProvider method checkAuth.
void checkAuth(NessieAuthentication authentication) {
assertThat(authentication).isInstanceOf(HttpAuthentication.class);
HttpAuthentication httpAuthentication = (HttpAuthentication) authentication;
// Intercept the call to HttpClient.register(RequestFilter) and extract the RequestFilter for
// our test
RequestFilter[] authFilter = new RequestFilter[1];
HttpClient.Builder client = Mockito.mock(HttpClient.Builder.class);
Mockito.doAnswer(invocationOnMock -> {
Object[] args = invocationOnMock.getArguments();
if (args.length == 1 && args[0] instanceof RequestFilter) {
authFilter[0] = (RequestFilter) args[0];
}
return null;
}).when(client).addRequestFilter(Mockito.any());
httpAuthentication.applyToHttpClient(client);
// Check that the registered RequestFilter works as expected (sets the right HTTP header)
assertThat(authFilter[0]).isInstanceOf(RequestFilter.class);
HttpHeaders headers = new HttpHeaders();
RequestContext context = new RequestContext(headers, null, null, null);
authFilter[0].filter(context);
assertThat(headers.asMap()).containsKey("Authorization").extracting("Authorization", InstanceOfAssertFactories.iterable(String.class)).containsExactly("Bearer token123");
}
use of org.projectnessie.client.http.RequestContext in project nessie by projectnessie.
the class TestBasicAuthProvider method checkAuth.
void checkAuth(NessieAuthentication authentication) {
assertThat(authentication).isInstanceOf(HttpAuthentication.class);
HttpAuthentication httpAuthentication = (HttpAuthentication) authentication;
// Intercept the call to HttpClient.register(RequestFilter) and extract the RequestFilter for
// our test
RequestFilter[] authFilter = new RequestFilter[1];
HttpClient.Builder client = Mockito.mock(HttpClient.Builder.class);
Mockito.doAnswer(invocationOnMock -> {
Object[] args = invocationOnMock.getArguments();
if (args.length == 1 && args[0] instanceof RequestFilter) {
authFilter[0] = (RequestFilter) args[0];
}
return null;
}).when(client).addRequestFilter(Mockito.any());
httpAuthentication.applyToHttpClient(client);
// Check that the registered RequestFilter works as expected (sets the right HTTP header)
assertThat(authFilter[0]).isInstanceOf(RequestFilter.class);
HttpHeaders headers = new HttpHeaders();
RequestContext context = new RequestContext(headers, null, null, null);
authFilter[0].filter(context);
assertThat(headers.asMap()).containsKey("Authorization").extracting("Authorization", InstanceOfAssertFactories.iterable(String.class)).containsExactly("Basic QWxhZGRpbjpPcGVuU2VzYW1l");
}
Aggregations