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());
}
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());
}
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());
}
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());
}
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);
}
Aggregations