Search in sources :

Example 1 with CreateSecretRequest

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

Example 2 with CreateSecretRequest

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

Example 3 with CreateSecretRequest

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);
}
Also used : CreateSecretRequest(keywhiz.api.CreateSecretRequest)

Example 4 with CreateSecretRequest

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

Example 5 with CreateSecretRequest

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