Skip to content

Commit

Permalink
fixes #394 Add a test case for invalid token for UnifiedSecurityHandl…
Browse files Browse the repository at this point in the history
…er (#395)
  • Loading branch information
stevehu authored Aug 22, 2024
1 parent 4c73b07 commit 4428949
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -564,4 +564,37 @@ public void testH2CDisabledRequest() throws Exception {
}
}

@Test
public void testInvalidToken() throws Exception {
final Http2Client client = Http2Client.getInstance();
final CountDownLatch latch = new CountDownLatch(1);
final ClientConnection connection;
try {
connection = client.connect(new URI("http://localhost:7081"), Http2Client.WORKER, Http2Client.SSL, Http2Client.BUFFER_POOL, OptionMap.EMPTY).get();
} catch (Exception e) {
throw new ClientException(e);
}
final AtomicReference<ClientResponse> reference = new AtomicReference<>();
try {
ClientRequest request = new ClientRequest().setPath("/v1/pets/111").setMethod(Methods.GET);
request.getRequestHeaders().put(Headers.HOST, "localhost");
request.getRequestHeaders().put(Headers.AUTHORIZATION, "abc");
connection.sendRequest(request, client.createClientCallback(reference, latch));
latch.await();
} catch (Exception e) {
logger.error("Exception: ", e);
throw new ClientException(e);
} finally {
IoUtils.safeClose(connection);
}
int statusCode = reference.get().getResponseCode();
String responseBody = reference.get().getAttachment(Http2Client.RESPONSE_BODY);
Assert.assertEquals(401, statusCode);
if (statusCode == 401) {
Status status = Config.getInstance().getMapper().readValue(responseBody, Status.class);
Assert.assertNotNull(status);
Assert.assertEquals("ERR12003", status.getCode());
}
}

}

0 comments on commit 4428949

Please sign in to comment.