use of org.projectnessie.client.http.RequestFilter 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.RequestFilter 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.RequestFilter in project nessie by projectnessie.
the class TestJerseyRestNaiveClientInMemory method init.
@Override
protected void init(NessieApiV1 api, @Nullable HttpClient.Builder httpClient, URI uri) {
assumeThat(httpClient).isNotNull();
// Intentionally remove the `Accept` header from requests.
// Service endpoints should declare the content type for their return values,
// which should allow the Web Container to properly format output even in the absence
// of `Accept` HTTP headers.
RequestFilter noAcceptFilter = context -> context.removeHeader(HEADER_ACCEPT);
httpClient.addRequestFilter(noAcceptFilter);
api = HttpClientBuilder.builder().withAuthentication((HttpAuthentication) client -> client.addRequestFilter(noAcceptFilter)).withUri(httpClient.getBaseUri()).build(NessieApiV1.class);
super.init(api, httpClient, uri);
}
use of org.projectnessie.client.http.RequestFilter 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