Search in sources :

Example 1 with AbstractOidcClient

use of com.redhat.service.smartevents.infra.auth.AbstractOidcClient in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class WebhookActionInvokerTest method testBearerToken.

@Test
void testBearerToken() throws InterruptedException {
    wireMockServer.stubFor(post(urlEqualTo(TEST_WEBHOOK_PATH)).willReturn(aResponse().withStatus(200)));
    CountDownLatch latch = new CountDownLatch(1);
    addUpdateRequestListener(TEST_WEBHOOK_PATH, RequestMethod.POST, latch);
    String testSinkEndpoint = webhookSinkUrl + TEST_WEBHOOK_PATH;
    AbstractOidcClient abstractOidcClient = mock(AbstractOidcClient.class);
    when(abstractOidcClient.getToken()).thenReturn("token");
    WebhookActionInvoker invoker = new WebhookActionInvoker(testSinkEndpoint, WebClient.create(vertx), abstractOidcClient);
    invoker.onEvent(TEST_EVENT, TEST_HEADERS);
    assertThat(latch.await(30, TimeUnit.SECONDS)).isTrue();
    RequestPatternBuilder requestPatternBuilder = postRequestedFor(urlEqualTo(TEST_WEBHOOK_PATH)).withRequestBody(equalToJson(TEST_EVENT, true, true)).withHeader("Content-Type", equalTo("application/json")).withHeader("Authorization", equalTo("Bearer token"));
    for (Map.Entry<String, String> testHeader : TEST_HEADERS.entrySet()) {
        requestPatternBuilder = requestPatternBuilder.withHeader("x-" + testHeader.getKey(), equalTo(testHeader.getValue()));
    }
    wireMockServer.verify(requestPatternBuilder);
}
Also used : AbstractOidcClient(com.redhat.service.smartevents.infra.auth.AbstractOidcClient) CountDownLatch(java.util.concurrent.CountDownLatch) RequestPatternBuilder(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder) Map(java.util.Map) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) AbstractWireMockTest(com.redhat.service.smartevents.test.wiremock.AbstractWireMockTest)

Aggregations

RequestPatternBuilder (com.github.tomakehurst.wiremock.matching.RequestPatternBuilder)1 AbstractOidcClient (com.redhat.service.smartevents.infra.auth.AbstractOidcClient)1 AbstractWireMockTest (com.redhat.service.smartevents.test.wiremock.AbstractWireMockTest)1 QuarkusTest (io.quarkus.test.junit.QuarkusTest)1 Map (java.util.Map)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.jupiter.api.Test)1