### Question:
BasicAuthHttpServiceFilter implements StreamingHttpServiceFilterFactory, HttpExecutionStrategyInfluencer { @Override public StreamingHttpServiceFilter create(final StreamingHttpService service) { return new BasicAuthStreamingHttpService<>(this, service); } private  BasicAuthHttpServiceFilter(final CredentialsVerifier<UserInfo> credentialsVerifier,
                                       final String realm,
                                       final boolean proxy,
                                       @Nullable final Key<UserInfo> userInfoKey,
                                       final boolean utf8); @Override StreamingHttpServiceFilter create(final StreamingHttpService service); @Override HttpExecutionStrategy influenceStrategy(final HttpExecutionStrategy strategy);  }### Answer:
@Test public void authenticatedWithoutUserInfo() throws Exception { StreamingHttpServiceFilter service = new BasicAuthHttpServiceFilter.Builder<>(CREDENTIALS_VERIFIER, REALM_VALUE) .buildServer() .create(HELLO_WORLD_SERVICE); StreamingHttpRequest request = reqRespFactory.get("/path"); request.headers().set(AUTHORIZATION, "Basic " + base64("userId:password")); StreamingHttpResponse response = awaitIndefinitelyNonNull(service.handle(CONN_CTX, request, reqRespFactory)); assertEquals(OK, response.status()); assertFalse(response.headers().contains(USER_ID_HEADER_NAME)); }
@Test public void utf8() throws Exception { final CredentialsVerifier<BasicUserInfo> utf8CredentialsVerifier = new CredentialsVerifier<BasicUserInfo>() { @Override public Single<BasicUserInfo> apply(final String userId, final String password) { if ("пароль".equals(password)) { return succeeded(new BasicUserInfo(userId)); } return failed(new AuthenticationException("Wrong password")); } @Override public Completable closeAsync() { return completed(); } }; StreamingHttpServiceFilter service = new BasicAuthHttpServiceFilter.Builder<>( utf8CredentialsVerifier, REALM_VALUE) .userInfoKey(USER_INFO_KEY) .setCharsetUtf8(true) .buildServer() .create(HELLO_WORLD_SERVICE); StreamingHttpResponse response = awaitIndefinitelyNonNull(service.handle(CONN_CTX, reqRespFactory.get("/path"), reqRespFactory)); assertEquals(UNAUTHORIZED, response.status()); assertEquals("Basic realm=\"" + REALM_VALUE + "\", charset=\"UTF-8\"", response.headers().get(WWW_AUTHENTICATE)); assertFalse(response.headers().contains(USER_ID_HEADER_NAME)); StreamingHttpRequest request = reqRespFactory.get("/path"); request.headers().set(AUTHORIZATION, "Basic " + base64("userId:пароль", UTF_8)); testAuthenticated(request, service); }
@Test public void closeAsync() throws Exception { AtomicBoolean credentialsVerifierClosed = new AtomicBoolean(); AtomicBoolean nextServiceClosed = new AtomicBoolean(); StreamingHttpServiceFilter service = new BasicAuthHttpServiceFilter.Builder<>( new CredentialsVerifier<BasicUserInfo>() { @Override public Single<BasicUserInfo> apply(final String userId, final String password) { return never(); } @Override public Completable closeAsync() { return completed().beforeOnComplete(() -> credentialsVerifierClosed.set(true)); } }, REALM_VALUE) .buildServer() .create(new StreamingHttpService() { @Override public Single<StreamingHttpResponse> handle(final HttpServiceContext ctx, final StreamingHttpRequest request, final StreamingHttpResponseFactory factory) { return never(); } @Override public Completable closeAsync() { return completed().beforeOnComplete(() -> nextServiceClosed.set(true)); } }); assertFalse(credentialsVerifierClosed.get()); assertFalse(nextServiceClosed.get()); service.closeAsync().toFuture().get(); assertTrue(credentialsVerifierClosed.get()); assertTrue(nextServiceClosed.get()); }