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");
}
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>>() {
});
}
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);
}
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>>() {
});
}
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);
}
Aggregations