com.github.tomakehurst.wiremock.client.BasicCredentials Java Examples

The following examples show how to use com.github.tomakehurst.wiremock.client.BasicCredentials. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpSenderCompatibilityKit.java    From micrometer with Apache License 2.0 6 votes vote down vote up
@ParameterizedTest
@EnumSource(HttpSender.Method.class)
void basicAuth(HttpSender.Method method, @WiremockResolver.Wiremock WireMockServer server) throws Throwable {
    server.stubFor(any(urlEqualTo("/metrics"))
            .willReturn(unauthorized()));

    HttpSender.Response response = httpSender.newRequest(server.baseUrl() + "/metrics")
            .withMethod(method)
            .withBasicAuthentication("superuser", "superpassword")
            .send();

    assertThat(response.code()).isEqualTo(401);

    server.verify(WireMock.requestMadeFor(request ->
            MatchResult.aggregate(
                    MatchResult.of(request.getMethod().getName().equals(method.name())),
                    MatchResult.of(request.getUrl().equals("/metrics"))
            ))
            .withBasicAuth(new BasicCredentials("superuser", "superpassword")));
}
 
Example #2
Source File: HttpHandlerTest.java    From data-highway with Apache License 2.0 5 votes vote down vote up
@Test
public void authenticated() throws Exception {
  stubFor(get(urlEqualTo("/foo")).willReturn(aResponse().withStatus(HttpStatus.SC_OK).withBody("bar")));

  try (HttpHandler handler = new HttpHandler(url, options.withUsername("user").withPassword("pass"))) {
    handler.get("foo");
  }

  verify(getRequestedFor(urlEqualTo("/foo")).withBasicAuth(new BasicCredentials("user", "pass")));
}
 
Example #3
Source File: TestDriveClientTest.java    From data-highway with Apache License 2.0 5 votes vote down vote up
@Test
public void getMessages() throws Exception {
  stubFor(get(urlEqualTo("/testdrive/v1/roads/road/messages")).withBasicAuth("user", "pass").willReturn(
      ok("[{\"foo\":\"bar\"}]").withHeader("Content-Type", "application/json")));
  List<JsonNode> messages = underTest.getMessages("road");
  assertThat(messages, is(singletonList(new ObjectMapper().createObjectNode().put("foo", "bar"))));
  verify(getRequestedFor(urlEqualTo("/testdrive/v1/roads/road/messages"))
      .withBasicAuth(new BasicCredentials("user", "pass")));
}
 
Example #4
Source File: TestDriveClientTest.java    From data-highway with Apache License 2.0 5 votes vote down vote up
@Test
public void deleteRoad() throws Exception {
  stubFor(delete(urlEqualTo("/testdrive/v1/roads/road")).withBasicAuth("user", "pass").willReturn(ok()));
  underTest.deleteRoad("road");
  verify(
      deleteRequestedFor(urlEqualTo("/testdrive/v1/roads/road")).withBasicAuth(new BasicCredentials("user", "pass")));
}
 
Example #5
Source File: TestDriveClientTest.java    From data-highway with Apache License 2.0 5 votes vote down vote up
@Test
public void deleteMessages() throws Exception {
  stubFor(delete(urlEqualTo("/testdrive/v1/roads/road/messages")).withBasicAuth("user", "pass").willReturn(ok()));
  underTest.deleteMessages("road");
  verify(deleteRequestedFor(urlEqualTo("/testdrive/v1/roads/road/messages"))
      .withBasicAuth(new BasicCredentials("user", "pass")));
}
 
Example #6
Source File: TestDriveClientTest.java    From data-highway with Apache License 2.0 5 votes vote down vote up
@Test
public void deleteCommits() throws Exception {
  stubFor(
      delete(urlEqualTo("/testdrive/v1/roads/road/streams/stream/messages")).withBasicAuth("user", "pass").willReturn(
          ok()));
  underTest.deleteCommits("road", "stream");
  verify(deleteRequestedFor(urlEqualTo("/testdrive/v1/roads/road/streams/stream/messages"))
      .withBasicAuth(new BasicCredentials("user", "pass")));
}
 
Example #7
Source File: RestSwaggerConnectorIntegrationTest.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldPassBasicAuthorizationHeader() throws Exception {
    wiremock.givenThat(get("/v2/user/logout")
        .withBasicAuth("luser", "supersecret")
        .willReturn(ok()));

    assertThat(context.createProducerTemplate().requestBody("direct:basicAuth", null, String.class))
        .isEqualTo("");

    wiremock.verify(getRequestedFor(urlEqualTo("/v2/user/logout"))
        .withBasicAuth(new BasicCredentials("luser", "supersecret"))
        .withRequestBody(WireMock.equalTo("")));
}
 
Example #8
Source File: CloudianClientTest.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
@Test
public void testBasicAuth() {
    wireMockRule.stubFor(get(urlEqualTo("/group/list"))
            .willReturn(aResponse()
                    .withStatus(200)
                    .withBody("[]")));
    client.listGroups();
    verify(getRequestedFor(urlEqualTo("/group/list"))
            .withBasicAuth(new BasicCredentials(adminUsername, adminPassword)));
}
 
Example #9
Source File: TestDriveClientTest.java    From data-highway with Apache License 2.0 4 votes vote down vote up
@Test
public void deleteAll() throws Exception {
  stubFor(delete(urlEqualTo("/testdrive/v1/roads")).withBasicAuth("user", "pass").willReturn(ok()));
  underTest.deleteAll();
  verify(deleteRequestedFor(urlEqualTo("/testdrive/v1/roads")).withBasicAuth(new BasicCredentials("user", "pass")));
}
 
Example #10
Source File: BasicAuthIntegrationTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Override
protected void verifyWireMock(WireMockRule wiremock) {
    wiremock.verify(postRequestedFor(urlEqualTo("/"))
        .withBasicAuth(new BasicCredentials(TEST_USER, TEST_PASSWORD)));
}
 
Example #11
Source File: BasicMappingBuilder.java    From spring-cloud-contract with Apache License 2.0 4 votes vote down vote up
@Override
public BasicMappingBuilder withBasicAuth(String username, String password) {
	this.requestPatternBuilder
			.withBasicAuth(new BasicCredentials(username, password));
	return this;
}
 
Example #12
Source File: VeeamClientTest.java    From cloudstack with Apache License 2.0 4 votes vote down vote up
@Test
public void testBasicAuth() {
    verify(postRequestedFor(urlMatching(".*/sessionMngr/.*"))
            .withBasicAuth(new BasicCredentials(adminUsername, adminPassword)));
}