Search in sources :

Example 1 with ClientAndServer

use of org.mockserver.integration.ClientAndServer in project hadoop by apache.

the class TestRefreshTokenTimeBasedTokenRefresher method refreshUrlIsCorrect.

@Test
public void refreshUrlIsCorrect() throws IOException {
    final int PORT = 7552;
    final String REFRESH_ADDRESS = "http://localhost:" + PORT + "/refresh";
    long tokenExpires = 0;
    Configuration conf = buildConf("refresh token key", Long.toString(tokenExpires), "joebob", REFRESH_ADDRESS);
    Timer mockTimer = mock(Timer.class);
    when(mockTimer.now()).thenReturn(tokenExpires + 1000l);
    AccessTokenProvider tokenProvider = new ConfRefreshTokenBasedAccessTokenProvider(mockTimer);
    tokenProvider.setConf(conf);
    // Build mock server to receive refresh request
    ClientAndServer mockServer = startClientAndServer(PORT);
    HttpRequest expectedRequest = request().withMethod("POST").withPath("/refresh").withBody(ParameterBody.params(Parameter.param(CLIENT_ID, "joebob"), Parameter.param(GRANT_TYPE, REFRESH_TOKEN), Parameter.param(REFRESH_TOKEN, "refresh token key")));
    MockServerClient mockServerClient = new MockServerClient("localhost", PORT);
    // https://tools.ietf.org/html/rfc6749#section-5.1
    Map<String, Object> map = new TreeMap<>();
    map.put(EXPIRES_IN, "0987654321");
    map.put(TOKEN_TYPE, BEARER);
    map.put(ACCESS_TOKEN, "new access token");
    ObjectMapper mapper = new ObjectMapper();
    HttpResponse resp = response().withStatusCode(HttpStatus.SC_OK).withHeaders(CONTENT_TYPE_APPLICATION_JSON).withBody(mapper.writeValueAsString(map));
    mockServerClient.when(expectedRequest, exactly(1)).respond(resp);
    assertEquals("new access token", tokenProvider.getAccessToken());
    mockServerClient.verify(expectedRequest);
    mockServerClient.clear(expectedRequest);
    mockServer.stop();
}
Also used : HttpRequest(org.mockserver.model.HttpRequest) Configuration(org.apache.hadoop.conf.Configuration) HttpResponse(org.mockserver.model.HttpResponse) MockServerClient(org.mockserver.client.server.MockServerClient) TreeMap(java.util.TreeMap) Timer(org.apache.hadoop.util.Timer) ClientAndServer(org.mockserver.integration.ClientAndServer) ClientAndServer.startClientAndServer(org.mockserver.integration.ClientAndServer.startClientAndServer) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 2 with ClientAndServer

use of org.mockserver.integration.ClientAndServer in project POL-POM-5 by PhoenicisOrg.

the class DownloaderTest method setUp.

@BeforeClass
public static void setUp() throws MalformedURLException {
    mockServer = new ClientAndServer(MOCKSERVER_PORT);
    mockServerURL = new URL("http://localhost:" + MOCKSERVER_PORT + "/test.txt");
    mockServerURLFile2 = new URL("http://localhost:" + MOCKSERVER_PORT + "/test2.txt");
}
Also used : ClientAndServer(org.mockserver.integration.ClientAndServer) URL(java.net.URL) BeforeClass(org.junit.BeforeClass)

Example 3 with ClientAndServer

use of org.mockserver.integration.ClientAndServer in project phoenicis by PhoenicisOrg.

the class DownloaderTest method setUp.

@BeforeClass
public static void setUp() throws MalformedURLException {
    mockServer = new ClientAndServer(MOCKSERVER_PORT);
    mockServerURL = new URL("http://localhost:" + MOCKSERVER_PORT + "/test.txt");
    mockServerURLFile2 = new URL("http://localhost:" + MOCKSERVER_PORT + "/test2.txt");
}
Also used : ClientAndServer(org.mockserver.integration.ClientAndServer) URL(java.net.URL) BeforeClass(org.junit.BeforeClass)

Example 4 with ClientAndServer

use of org.mockserver.integration.ClientAndServer in project wildfly by wildfly.

the class TestingOcspServer method start.

public void start() throws Exception {
    Assert.assertNull("OCSP server already started", ocspServer);
    ocspServer = new OcspServer();
    ocspServer.setConfFile(TestingOcspServer.class.getResource("ocsp-responder.xml").getFile());
    securityFactory.setSignerFactoryRegister(new SignerFactoryRegisterImpl());
    ocspServer.setSecurityFactory(securityFactory);
    ocspServer.init();
    HttpOcspServlet servlet = new HttpOcspServlet();
    servlet.setServer(ocspServer);
    server = new ClientAndServer(port);
    server.when(request().withMethod("POST").withPath("/ocsp"), Times.unlimited()).respond(request -> getHttpResponse(request, servlet));
    server.when(request().withMethod("GET").withPath("/ocsp/.*"), Times.unlimited()).respond(request -> getHttpResponse(request, servlet));
}
Also used : HttpOcspServlet(org.xipki.ocsp.server.impl.HttpOcspServlet) SignerFactoryRegisterImpl(org.xipki.security.SignerFactoryRegisterImpl) ClientAndServer(org.mockserver.integration.ClientAndServer) OcspServer(org.xipki.ocsp.server.impl.OcspServer)

Example 5 with ClientAndServer

use of org.mockserver.integration.ClientAndServer in project POL-POM-5 by PlayOnLinux.

the class DownloaderTest method setUp.

@BeforeClass
public static void setUp() throws MalformedURLException {
    mockServer = new ClientAndServer(MOCKSERVER_PORT);
    mockServerURL = new URL("http://localhost:" + MOCKSERVER_PORT + "/test.txt");
    mockServerURLFile2 = new URL("http://localhost:" + MOCKSERVER_PORT + "/test2.txt");
}
Also used : ClientAndServer(org.mockserver.integration.ClientAndServer) URL(java.net.URL) BeforeClass(org.junit.BeforeClass)

Aggregations

ClientAndServer (org.mockserver.integration.ClientAndServer)6 URL (java.net.URL)3 BeforeClass (org.junit.BeforeClass)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 TreeMap (java.util.TreeMap)2 Configuration (org.apache.hadoop.conf.Configuration)2 Timer (org.apache.hadoop.util.Timer)2 Test (org.junit.Test)2 MockServerClient (org.mockserver.client.server.MockServerClient)2 ClientAndServer.startClientAndServer (org.mockserver.integration.ClientAndServer.startClientAndServer)2 HttpRequest (org.mockserver.model.HttpRequest)2 HttpResponse (org.mockserver.model.HttpResponse)2 HttpOcspServlet (org.xipki.ocsp.server.impl.HttpOcspServlet)1 OcspServer (org.xipki.ocsp.server.impl.OcspServer)1 SignerFactoryRegisterImpl (org.xipki.security.SignerFactoryRegisterImpl)1