use of com.tonyodev.fetch2.Request in project keywhiz by square.
the class XsrfServletFilterIntegrationTest method xsrfNotRequiredForLogout.
@Test
public void xsrfNotRequiredForLogout() throws Exception {
Request request = new Request.Builder().post(RequestBody.create(MediaType.parse("text/plain"), "")).url(testUrl("/admin/logout")).build();
Response response = client.newCall(request).execute();
assertThat(response.code()).isNotEqualTo(401);
}
use of com.tonyodev.fetch2.Request in project keywhiz by square.
the class XsrfServletFilterIntegrationTest method allowsForAdminUrlWithXsrf.
@Test
public void allowsForAdminUrlWithXsrf() throws Exception {
client.newCall(buildLoginPost(DbSeedCommand.defaultUser, DbSeedCommand.defaultPassword)).execute();
Request request = new Request.Builder().url(testUrl("/admin/clients")).get().build();
Response response = client.newCall(request).execute();
assertThat(response.code()).isNotEqualTo(401);
}
use of com.tonyodev.fetch2.Request in project keywhiz by square.
the class SecretResourceTest method listExpiringV3.
List<SanitizedSecretWithGroups> listExpiringV3(Long time, String groupName) throws IOException {
String requestURL = "/automation/v2/secrets/expiring/v3/";
if (time != null && time > 0) {
requestURL += time.toString() + "/";
}
if (groupName != null && groupName.length() > 0) {
requestURL += groupName;
}
Request get = clientRequest(requestURL).get().build();
Response httpResponse = mutualSslClient.newCall(get).execute();
assertThat(httpResponse.code()).isEqualTo(200);
return mapper.readValue(httpResponse.body().byteStream(), new TypeReference<List<SanitizedSecretWithGroups>>() {
});
}
use of com.tonyodev.fetch2.Request in project okhttp by square.
the class MockWebServer method handleWebSocketUpgrade.
private void handleWebSocketUpgrade(Socket socket, BufferedSource source, BufferedSink sink, RecordedRequest request, MockResponse response) throws IOException {
String key = request.getHeader("Sec-WebSocket-Key");
response.setHeader("Sec-WebSocket-Accept", WebSocketProtocol.acceptHeader(key));
writeHttpResponse(socket, sink, response);
// Adapt the request and response into our Request and Response domain model.
String scheme = request.getTlsVersion() != null ? "https" : "http";
// Has host and port.
String authority = request.getHeader("Host");
final Request fancyRequest = new Request.Builder().url(scheme + "://" + authority + "/").headers(request.getHeaders()).build();
final Response fancyResponse = new Response.Builder().code(Integer.parseInt(response.getStatus().split(" ")[1])).message(response.getStatus().split(" ", 3)[2]).headers(response.getHeaders()).request(fancyRequest).protocol(Protocol.HTTP_1_1).build();
final CountDownLatch connectionClose = new CountDownLatch(1);
RealWebSocket.Streams streams = new RealWebSocket.Streams(false, source, sink) {
@Override
public void close() {
connectionClose.countDown();
}
};
RealWebSocket webSocket = new RealWebSocket(fancyRequest, response.getWebSocketListener(), new SecureRandom());
response.getWebSocketListener().onOpen(webSocket, fancyResponse);
String name = "MockWebServer WebSocket " + request.getPath();
webSocket.initReaderAndWriter(name, 0, streams);
try {
webSocket.loopReader();
// Even if messages are no longer being read we need to wait for the connection close signal.
try {
connectionClose.await();
} catch (InterruptedException ignored) {
}
} catch (IOException e) {
webSocket.failWebSocket(e, null);
} finally {
closeQuietly(sink);
closeQuietly(source);
}
}
use of com.tonyodev.fetch2.Request in project okhttp by square.
the class JavaApiConverterTest method createOkRequest_nonNullRequestHeaders.
@Test
public void createOkRequest_nonNullRequestHeaders() throws Exception {
URI uri = new URI("https://foo/bar");
Map<String, List<String>> javaRequestHeaders = new LinkedHashMap<>();
javaRequestHeaders.put("Foo", Arrays.asList("Bar"));
Request request = JavaApiConverter.createOkRequest(uri, "POST", javaRequestHeaders);
assertTrue(request.isHttps());
assertEquals(uri, request.url().uri());
Headers okRequestHeaders = request.headers();
assertEquals(1, okRequestHeaders.size());
assertEquals("Bar", okRequestHeaders.get("Foo"));
assertEquals("POST", request.method());
}
Aggregations