Search in sources :

Example 11 with Secret

use of keywhiz.api.model.Secret in project keywhiz by square.

the class SecretControllerTest method createsSecretWithOwner.

@Test
public void createsSecretWithOwner() {
    String ownerName = UUID.randomUUID().toString();
    groupDAO.createGroup(ownerName, "creator", "description", ImmutableMap.of());
    String secretName = UUID.randomUUID().toString();
    Secret created = secretController.builder(secretName, "secret", "creator", now).withOwnerName(ownerName).create();
    assertEquals(ownerName, created.getOwner());
}
Also used : Secret(keywhiz.api.model.Secret) Test(org.junit.Test)

Example 12 with Secret

use of keywhiz.api.model.Secret in project keywhiz by square.

the class SecretControllerTest method loadsSecretWithOwnerById.

@Test
public void loadsSecretWithOwnerById() {
    String ownerName = UUID.randomUUID().toString();
    groupDAO.createGroup(ownerName, "creator", "description", ImmutableMap.of());
    String secretName = UUID.randomUUID().toString();
    Secret created = secretController.builder(secretName, "secret", "creator", now).withOwnerName(ownerName).create();
    Secret persisted = secretController.getSecretById(created.getId()).get();
    assertEquals(ownerName, persisted.getOwner());
}
Also used : Secret(keywhiz.api.model.Secret) Test(org.junit.Test)

Example 13 with Secret

use of keywhiz.api.model.Secret in project keywhiz by square.

the class AutomationSecretResourceTest method addSecret.

@Test
public void addSecret() {
    CreateSecretRequest request = new CreateSecretRequest("mySecret", null, "some secret", "ponies", null, 0);
    Secret secret = new Secret(0, /* Set by DB */
    request.name, request.description, null, () -> 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, NOW, automation.getName());
    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 : Secret(keywhiz.api.model.Secret) CreateSecretRequest(keywhiz.api.CreateSecretRequest) AutomationSecretResponse(keywhiz.api.AutomationSecretResponse) Test(org.junit.Test)

Example 14 with Secret

use of keywhiz.api.model.Secret in project keywhiz by square.

the class AutomationSecretResourceTest method deleteSecret.

@Test
public void deleteSecret() throws Exception {
    Secret secret = new Secret(0, "mySecret", null, null, (Secret.LazyString) () -> "meh", "checksum", NOW, null, NOW, null, ImmutableMap.of(), null, null, 0, 1L, NOW, null);
    HashSet<Group> groups = new HashSet<>();
    groups.add(new Group(0, "group1", "", NOW, null, NOW, null, null));
    groups.add(new Group(0, "group2", "", NOW, null, NOW, null, null));
    when(secretController.getSecretByName(secret.getName())).thenReturn(Optional.of(secret));
    when(aclDAO.getGroupsFor(secret)).thenReturn(groups);
    resource.deleteSecretSeries(automation, secret.getName());
    verify(secretDAO).deleteSecretsByName(secret.getName());
}
Also used : Secret(keywhiz.api.model.Secret) Group(keywhiz.api.model.Group) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 15 with Secret

use of keywhiz.api.model.Secret in project keywhiz by square.

the class SecretsResourceTest method rollbackSuccess.

@Test
public void rollbackSuccess() {
    Secret secret1 = new Secret(1, "name1", null, "desc", () -> "secret", "checksum", NOW, "user", NOW, "user", emptyMap, null, null, 1136214245, 125L, NOW, "user");
    when(secretController.getSecretByName("name1")).thenReturn(Optional.of(secret1));
    Response response = resource.resetSecretVersion(user, "name1", new LongParam("125"));
    assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_CREATED);
}
Also used : Secret(keywhiz.api.model.Secret) SanitizedSecret(keywhiz.api.model.SanitizedSecret) Response(javax.ws.rs.core.Response) SecretDetailResponse(keywhiz.api.SecretDetailResponse) LongParam(io.dropwizard.jersey.params.LongParam) Test(org.junit.Test)

Aggregations

Secret (keywhiz.api.model.Secret)34 SanitizedSecret (keywhiz.api.model.SanitizedSecret)21 ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)15 Timed (com.codahale.metrics.annotation.Timed)15 Test (org.junit.Test)14 HashMap (java.util.HashMap)12 Event (keywhiz.log.Event)12 NotFoundException (javax.ws.rs.NotFoundException)10 POST (javax.ws.rs.POST)10 Path (javax.ws.rs.Path)9 Consumes (javax.ws.rs.Consumes)8 Group (keywhiz.api.model.Group)6 ConflictException (keywhiz.service.exceptions.ConflictException)6 Response (javax.ws.rs.core.Response)5 SecretController (keywhiz.service.daos.SecretController)5 DataAccessException (org.jooq.exception.DataAccessException)5 ArrayList (java.util.ArrayList)4 DELETE (javax.ws.rs.DELETE)4 GET (javax.ws.rs.GET)4 SecretDetailResponse (keywhiz.api.SecretDetailResponse)4