use of keywhiz.api.CreateSecretRequest in project keywhiz by square.
the class AutomationSecretResourceIntegrationTest method addSecrets.
@Test
public void addSecrets() throws Exception {
CreateSecretRequest request = new CreateSecretRequest("new_secret", "desc", "superSecret", ImmutableMap.of(), 0);
String body = mapper.writeValueAsString(request);
Request post = new Request.Builder().post(RequestBody.create(KeywhizClient.JSON, body)).url(testUrl("/automation/secrets")).addHeader("Content-Type", MediaType.APPLICATION_JSON).build();
Response response = mutualSslClient.newCall(post).execute();
assertThat(response.code()).isEqualTo(200);
}
use of keywhiz.api.CreateSecretRequest in project keywhiz by square.
the class AutomationSecretResourceTest method addSecret.
@Test
public void addSecret() {
CreateSecretRequest request = new CreateSecretRequest("mySecret", "some secret", "ponies", null, 0);
Secret secret = new Secret(0, /* Set by DB */
request.name, request.description, () -> Base64.getUrlEncoder().encodeToString(request.content.getBytes(UTF_8)), "checksum", NOW, automation.getName(), NOW, /* updatedAt set by DB */
automation.getName(), request.metadata, null, null, 0, 1L);
when(secretBuilder.create()).thenReturn(secret);
when(secretController.getSecretByName(eq(request.name))).thenReturn(Optional.of(secret));
AutomationSecretResponse response = resource.createSecret(automation, request);
assertThat(response.id()).isEqualTo(secret.getId());
assertThat(response.secret()).isEqualTo(secret.getSecret());
assertThat(response.name()).isEqualTo(secret.getDisplayName());
assertThat(response.metadata()).isEqualTo(secret.getMetadata());
}
use of keywhiz.api.CreateSecretRequest in project keywhiz by square.
the class KeywhizClient method createSecret.
public SecretDetailResponse createSecret(String name, String description, byte[] content, ImmutableMap<String, String> metadata, long expiry) throws IOException {
checkArgument(!name.isEmpty());
checkArgument(content.length > 0, "Content must not be empty");
String b64Content = Base64.getEncoder().encodeToString(content);
CreateSecretRequest request = new CreateSecretRequest(name, description, b64Content, metadata, expiry);
String response = httpPost(baseUrl.resolve("/admin/secrets"), request);
return mapper.readValue(response, SecretDetailResponse.class);
}
use of keywhiz.api.CreateSecretRequest in project keywhiz by square.
the class AutomationSecretResourceIntegrationTest method addInvalidSecrets.
@Test
public void addInvalidSecrets() throws Exception {
CreateSecretRequest request = new CreateSecretRequest("empty_secret", "desc", "", null, 0);
String body = mapper.writeValueAsString(request);
Request post = new Request.Builder().post(RequestBody.create(KeywhizClient.JSON, body)).url(testUrl("/automation/secrets")).addHeader("Content-Type", MediaType.APPLICATION_JSON).build();
Response response = mutualSslClient.newCall(post).execute();
assertThat(response.code()).isEqualTo(422);
}
use of keywhiz.api.CreateSecretRequest in project keywhiz by square.
the class AutomationSecretResourceIntegrationTest method readValidSecret.
@Test
public void readValidSecret() throws Exception {
CreateSecretRequest request = new CreateSecretRequest("readable", "desc", "c3VwZXJTZWNyZXQK", ImmutableMap.of(), 0);
String body = mapper.writeValueAsString(request);
Request post = new Request.Builder().post(RequestBody.create(KeywhizClient.JSON, body)).url(testUrl("/automation/secrets")).addHeader("Content-Type", MediaType.APPLICATION_JSON).build();
Response response = mutualSslClient.newCall(post).execute();
assertThat(response.code()).isEqualTo(200);
Request get = new Request.Builder().get().url(testUrl("/automation/secrets?name=readable")).build();
response = mutualSslClient.newCall(get).execute();
assertThat(response.code()).isEqualTo(200);
}
Aggregations