use of keywhiz.api.CreateSecretRequest in project keywhiz by square.
the class AutomationSecretResourceIntegrationTest method addConflictingSecrets.
@Test
public void addConflictingSecrets() throws Exception {
CreateSecretRequest request = new CreateSecretRequest("dup_secret", "desc", "content", 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);
response = mutualSslClient.newCall(post).execute();
assertThat(response.code()).isEqualTo(409);
}
use of keywhiz.api.CreateSecretRequest in project keywhiz by square.
the class AutomationSecretResourceIntegrationTest method deleteSecrets.
@Test
public void deleteSecrets() throws Exception {
CreateSecretRequest request = new CreateSecretRequest("deletable", "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 delete = new Request.Builder().delete().url(testUrl("/automation/secrets/deletable")).build();
response = mutualSslClient.newCall(delete).execute();
assertThat(response.code()).isEqualTo(200);
}
use of keywhiz.api.CreateSecretRequest in project keywhiz by square.
the class AutomationSecretResourceTest method triesToCreateDuplicateSecret.
@Test(expected = ConflictException.class)
public void triesToCreateDuplicateSecret() throws Exception {
DataAccessException exception = new DataAccessException("");
ImmutableMap<String, String> emptyMap = ImmutableMap.of();
doThrow(exception).when(secretBuilder).create();
CreateSecretRequest req = new CreateSecretRequest("name", "desc", "content", emptyMap, 0);
resource.createSecret(automation, req);
}
use of keywhiz.api.CreateSecretRequest in project keywhiz by square.
the class SecretsResourceTest method createsSecret.
@Test
public void createsSecret() throws Exception {
when(secretController.getSecretById(secret.getId())).thenReturn(Optional.of(secret));
SecretController.SecretBuilder secretBuilder = mock(SecretController.SecretBuilder.class);
when(secretController.builder(secret.getName(), secret.getSecret(), user.getName(), 0)).thenReturn(secretBuilder);
when(secretBuilder.create()).thenReturn(secret);
CreateSecretRequest req = new CreateSecretRequest(secret.getName(), secret.getDescription(), secret.getSecret(), emptyMap, 0);
Response response = resource.createSecret(user, req);
assertThat(response.getStatus()).isEqualTo(201);
assertThat(response.getMetadata().get(HttpHeaders.LOCATION)).containsExactly(new URI("/admin/secrets/" + secret.getId()));
}
use of keywhiz.api.CreateSecretRequest in project keywhiz by square.
the class SecretsResourceTest method triesToCreateDuplicateSecret.
@Test(expected = ConflictException.class)
public void triesToCreateDuplicateSecret() throws Exception {
SecretController.SecretBuilder secretBuilder = mock(SecretController.SecretBuilder.class);
when(secretController.builder("name", "content", user.getName(), 0)).thenReturn(secretBuilder);
DataAccessException exception = new DataAccessException("");
doThrow(exception).when(secretBuilder).create();
CreateSecretRequest req = new CreateSecretRequest("name", "desc", "content", emptyMap, 0);
resource.createSecret(user, req);
}
Aggregations