@Test public void test_BasicAuthentication_WithAuthenticationRemoved() throws Exception { startBasic(new EmptyServerHandler()); final AtomicReference<CountDownLatch> requests = new AtomicReference<>(new CountDownLatch(2)); Request.Listener.Empty requestListener = new Request.Listener.Empty() { @Override public void onSuccess(Request request) { requests.get().countDown(); } }; client.getRequestListeners().add(requestListener); AuthenticationStore authenticationStore = client.getAuthenticationStore(); URI uri = URI.create(scheme + "://localhost:" + connector.getLocalPort()); BasicAuthentication authentication = new BasicAuthentication(uri, realm, "basic", "basic"); authenticationStore.addAuthentication(authentication); Request request = client.newRequest("localhost", connector.getLocalPort()).scheme(scheme).path("/secure"); ContentResponse response = request.timeout(5, TimeUnit.SECONDS).send(); Assert.assertNotNull(response); Assert.assertEquals(200, response.getStatus()); Assert.assertTrue(requests.get().await(5, TimeUnit.SECONDS)); authenticationStore.removeAuthentication(authentication); requests.set(new CountDownLatch(1)); request = client.newRequest("localhost", connector.getLocalPort()).scheme(scheme).path("/secure"); response = request.timeout(5, TimeUnit.SECONDS).send(); Assert.assertNotNull(response); Assert.assertEquals(200, response.getStatus()); Assert.assertTrue(requests.get().await(5, TimeUnit.SECONDS)); Authentication.Result result = authenticationStore.findAuthenticationResult(request.getURI()); Assert.assertNotNull(result); authenticationStore.removeAuthenticationResult(result); requests.set(new CountDownLatch(1)); request = client.newRequest("localhost", connector.getLocalPort()).scheme(scheme).path("/secure"); response = request.timeout(5, TimeUnit.SECONDS).send(); Assert.assertNotNull(response); Assert.assertEquals(401, response.getStatus()); Assert.assertTrue(requests.get().await(5, TimeUnit.SECONDS)); }