Search in sources :

Example 66 with Response

use of org.openclinica.ns.response.v31.Response in project keywhiz by square.

the class SecretResourceTest method createSecret_successUnVersioned.

//---------------------------------------------------------------------------------------
// createSecret
//---------------------------------------------------------------------------------------
@Test
public void createSecret_successUnVersioned() throws Exception {
    CreateSecretRequestV2 request = CreateSecretRequestV2.builder().name("secret1").content(encoder.encodeToString("supa secret".getBytes(UTF_8))).description("desc").metadata(ImmutableMap.of("owner", "root", "mode", "0440")).type("password").build();
    Response httpResponse = create(request);
    assertThat(httpResponse.code()).isEqualTo(201);
    URI location = URI.create(httpResponse.header(LOCATION));
    assertThat(location.getPath()).isEqualTo("/automation/v2/secrets/secret1");
}
Also used : Response(okhttp3.Response) CreateSecretRequestV2(keywhiz.api.automation.v2.CreateSecretRequestV2) URI(java.net.URI) Test(org.junit.Test)

Example 67 with Response

use of org.openclinica.ns.response.v31.Response in project keywhiz by square.

the class SecretResourceTest method listExpiring.

List<String> listExpiring(Long time, String groupName) throws IOException {
    String requestURL = "/automation/v2/secrets/expiring/";
    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<String>>() {
    });
}
Also used : Response(okhttp3.Response) Request(okhttp3.Request) TestClients.clientRequest(keywhiz.TestClients.clientRequest) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList)

Example 68 with Response

use of org.openclinica.ns.response.v31.Response in project keywhiz by square.

the class SecretResourceTest method backfillExpirationTest.

//---------------------------------------------------------------------------------------
// backfillExpiration
//---------------------------------------------------------------------------------------
@Test
public void backfillExpirationTest() throws Exception {
    byte[] certs = Resources.toByteArray(Resources.getResource("fixtures/expiring-certificates.crt"));
    byte[] pubring = Resources.toByteArray(Resources.getResource("fixtures/expiring-pubring.gpg"));
    byte[] p12 = Resources.toByteArray(Resources.getResource("fixtures/expiring-keystore.p12"));
    byte[] jceks = Resources.toByteArray(Resources.getResource("fixtures/expiring-keystore.jceks"));
    create(CreateSecretRequestV2.builder().name("certificate-chain.crt").content(encoder.encodeToString(certs)).build());
    create(CreateSecretRequestV2.builder().name("public-keyring.gpg").content(encoder.encodeToString(pubring)).build());
    create(CreateSecretRequestV2.builder().name("keystore.p12").content(encoder.encodeToString(p12)).build());
    create(CreateSecretRequestV2.builder().name("keystore.jceks").content(encoder.encodeToString(jceks)).build());
    Response response = backfillExpiration("certificate-chain.crt", ImmutableList.of());
    assertThat(response.isSuccessful()).isTrue();
    response = backfillExpiration("public-keyring.gpg", ImmutableList.of());
    assertThat(response.isSuccessful()).isTrue();
    response = backfillExpiration("keystore.p12", ImmutableList.of("password"));
    assertThat(response.isSuccessful()).isTrue();
    response = backfillExpiration("keystore.jceks", ImmutableList.of("password"));
    assertThat(response.isSuccessful()).isTrue();
    SecretDetailResponseV2 details = lookup("certificate-chain.crt");
    assertThat(details.expiry()).isEqualTo(1501533950);
    details = lookup("public-keyring.gpg");
    assertThat(details.expiry()).isEqualTo(1536442365);
    details = lookup("keystore.p12");
    assertThat(details.expiry()).isEqualTo(1681596851);
    details = lookup("keystore.jceks");
    assertThat(details.expiry()).isEqualTo(1681596851);
}
Also used : Response(okhttp3.Response) SecretDetailResponseV2(keywhiz.api.automation.v2.SecretDetailResponseV2) Test(org.junit.Test)

Example 69 with Response

use of org.openclinica.ns.response.v31.Response 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>>() {
    });
}
Also used : Response(okhttp3.Response) Request(okhttp3.Request) TestClients.clientRequest(keywhiz.TestClients.clientRequest) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList)

Example 70 with Response

use of org.openclinica.ns.response.v31.Response in project keywhiz by square.

the class SecretResourceTest method secretListingBatch_failure.

@Test
public void secretListingBatch_failure() throws Exception {
    // check that negative inputs fail
    Request get = clientRequest(String.format("/automation/v2/secrets?idx=%d&num=%d&newestFirst=%s", -1, 3, false)).get().build();
    Response httpResponse = mutualSslClient.newCall(get).execute();
    assertThat(httpResponse.code()).isEqualTo(400);
    get = clientRequest(String.format("/automation/v2/secrets?idx=%d&num=%d&newestFirst=%s", 0, -3, true)).get().build();
    httpResponse = mutualSslClient.newCall(get).execute();
    assertThat(httpResponse.code()).isEqualTo(400);
    get = clientRequest(String.format("/automation/v2/secrets/v2?idx=%d&num=%d&newestFirst=%s", -1, 3, false)).get().build();
    httpResponse = mutualSslClient.newCall(get).execute();
    assertThat(httpResponse.code()).isEqualTo(400);
    get = clientRequest(String.format("/automation/v2/secrets/v2?idx=%d&num=%d&newestFirst=%s", 0, -3, true)).get().build();
    httpResponse = mutualSslClient.newCall(get).execute();
    assertThat(httpResponse.code()).isEqualTo(400);
}
Also used : Response(okhttp3.Response) Request(okhttp3.Request) TestClients.clientRequest(keywhiz.TestClients.clientRequest) Test(org.junit.Test)

Aggregations

Response (okhttp3.Response)478 Request (okhttp3.Request)354 Test (org.junit.Test)213 IOException (java.io.IOException)177 Response (retrofit2.Response)156 ResponseBody (okhttp3.ResponseBody)137 ServiceResponse (com.microsoft.rest.ServiceResponse)114 Call (okhttp3.Call)104 Observable (rx.Observable)98 MockResponse (okhttp3.mockwebserver.MockResponse)76 RequestBody (okhttp3.RequestBody)71 OkHttpClient (okhttp3.OkHttpClient)67 Callback (okhttp3.Callback)44 List (java.util.List)39 TestClients.clientRequest (keywhiz.TestClients.clientRequest)37 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)32 MediaType (okhttp3.MediaType)27 HttpUrl (okhttp3.HttpUrl)26 Interceptor (okhttp3.Interceptor)26 ANResponse (com.androidnetworking.common.ANResponse)23