Search in sources :

Example 6 with CreateSecretRequest

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);
}
Also used : Response(okhttp3.Response) CreateSecretRequest(keywhiz.api.CreateSecretRequest) CreateSecretRequest(keywhiz.api.CreateSecretRequest) Request(okhttp3.Request) Test(org.junit.Test)

Example 7 with CreateSecretRequest

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);
}
Also used : Response(okhttp3.Response) CreateSecretRequest(keywhiz.api.CreateSecretRequest) CreateSecretRequest(keywhiz.api.CreateSecretRequest) Request(okhttp3.Request) Test(org.junit.Test)

Example 8 with CreateSecretRequest

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);
}
Also used : CreateSecretRequest(keywhiz.api.CreateSecretRequest) Matchers.anyString(org.mockito.Matchers.anyString) DataAccessException(org.jooq.exception.DataAccessException) Test(org.junit.Test)

Example 9 with CreateSecretRequest

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()));
}
Also used : Response(javax.ws.rs.core.Response) SecretDetailResponse(keywhiz.api.SecretDetailResponse) CreateSecretRequest(keywhiz.api.CreateSecretRequest) SecretController(keywhiz.service.daos.SecretController) URI(java.net.URI) Test(org.junit.Test)

Example 10 with CreateSecretRequest

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);
}
Also used : CreateSecretRequest(keywhiz.api.CreateSecretRequest) SecretController(keywhiz.service.daos.SecretController) DataAccessException(org.jooq.exception.DataAccessException) Test(org.junit.Test)

Aggregations

CreateSecretRequest (keywhiz.api.CreateSecretRequest)10 Test (org.junit.Test)9 Request (okhttp3.Request)5 Response (okhttp3.Response)5 SecretController (keywhiz.service.daos.SecretController)2 DataAccessException (org.jooq.exception.DataAccessException)2 URI (java.net.URI)1 Response (javax.ws.rs.core.Response)1 AutomationSecretResponse (keywhiz.api.AutomationSecretResponse)1 SecretDetailResponse (keywhiz.api.SecretDetailResponse)1 Matchers.anyString (org.mockito.Matchers.anyString)1