use of keywhiz.api.model.SanitizedSecret in project keywhiz by square.
the class SecretsResourceTest method listSecretsBatched.
@Test
public void listSecretsBatched() {
SanitizedSecret secret1 = SanitizedSecret.of(1, "name1", null, "desc", "checksum", NOW, "user", NOW, "user", emptyMap, null, null, 1136214245, 125L, NOW, "user");
SanitizedSecret secret2 = SanitizedSecret.of(2, "name2", null, "desc", "checksum", NOWPLUS, "user", NOWPLUS, "user", emptyMap, null, null, 1136214245, 250L, NOW, "user");
when(secretController.getSecretsBatched(0, 1, false)).thenReturn(ImmutableList.of(secret1));
when(secretController.getSecretsBatched(0, 1, true)).thenReturn(ImmutableList.of(secret2));
when(secretController.getSecretsBatched(1, 1, false)).thenReturn(ImmutableList.of(secret2));
List<SanitizedSecret> response = resource.listSecretsBatched(user, 0, 1, false);
assertThat(response).containsOnly(secret1);
response = resource.listSecretsBatched(user, 1, 1, false);
assertThat(response).containsOnly(secret2);
response = resource.listSecretsBatched(user, 0, 1, true);
assertThat(response).containsOnly(secret2);
}
use of keywhiz.api.model.SanitizedSecret in project keywhiz by square.
the class SecretsResourceTest method listSecrets.
@Test
public void listSecrets() {
SanitizedSecret secret1 = SanitizedSecret.of(1, "name1", null, "desc", "checksum", NOW, "user", NOW, "user", emptyMap, null, null, 1136214245, 125L, NOW, "user");
SanitizedSecret secret2 = SanitizedSecret.of(2, "name2", null, "desc", "checksum", NOW, "user", NOW, "user", emptyMap, null, null, 1136214245, 250L, NOW, "user");
when(secretController.getSanitizedSecrets(null, null)).thenReturn(ImmutableList.of(secret1, secret2));
List<SanitizedSecret> response = resource.listSecrets(user);
assertThat(response).containsOnly(secret1, secret2);
}
use of keywhiz.api.model.SanitizedSecret in project keywhiz by square.
the class BatchSecretDeliveryResourceTest method returnsSingleSecretWhenAllowed.
@Test
public void returnsSingleSecretWhenAllowed() throws Exception {
SanitizedSecret sanitizedSecret = SanitizedSecret.fromSecret(secret);
ImmutableList<String> secretNames = ImmutableList.of(sanitizedSecret.name());
BatchSecretRequest req = BatchSecretRequest.create(secretNames);
when(aclDAO.getBatchSanitizedSecretsFor(client, secretNames)).thenReturn(List.of(sanitizedSecret));
when(clientDAO.getClientByName(client.getName())).thenReturn(Optional.of(client));
when(secretController.getSecretsByName(secretNames)).thenReturn(List.of(secret));
List<SecretDeliveryResponse> response = batchSecretDeliveryResource.getBatchSecret(client, req);
assertThat(response).isEqualTo(ImmutableList.of(SecretDeliveryResponse.fromSecret(secret)));
}
use of keywhiz.api.model.SanitizedSecret in project keywhiz by square.
the class BatchSecretDeliveryResourceTest method returnsMultipleSecretsWhenAllowed.
@Test
public void returnsMultipleSecretsWhenAllowed() throws Exception {
SanitizedSecret sanitizedSecret = SanitizedSecret.fromSecret(secret);
SanitizedSecret sanitizedSecret2 = SanitizedSecret.fromSecret(secret2);
ImmutableList<String> secretnames = ImmutableList.of(sanitizedSecret.name(), sanitizedSecret2.name());
BatchSecretRequest req = BatchSecretRequest.create(secretnames);
when(aclDAO.getBatchSanitizedSecretsFor(client, secretnames)).thenReturn(List.of(sanitizedSecret, sanitizedSecret2));
when(clientDAO.getClientByName(client.getName())).thenReturn(Optional.of(client));
when(secretController.getSecretsByName(secretnames)).thenReturn(List.of(secret, secret2));
List<SecretDeliveryResponse> response = batchSecretDeliveryResource.getBatchSecret(client, req);
assertThat(response).containsExactlyInAnyOrder(SecretDeliveryResponse.fromSecret(secret), SecretDeliveryResponse.fromSecret(secret2));
}
use of keywhiz.api.model.SanitizedSecret in project keywhiz by square.
the class BatchSecretDeliveryResourceTest method returnsNotFoundWhenOneOfSecretsDoesNotExist.
@Test(expected = NotFoundException.class)
public void returnsNotFoundWhenOneOfSecretsDoesNotExist() throws Exception {
SanitizedSecret sanitizedSecret = SanitizedSecret.fromSecret(secret);
ImmutableList<String> secretnames = ImmutableList.of(sanitizedSecret.name(), "secretthatdoesnotexist");
BatchSecretRequest req = BatchSecretRequest.create(secretnames);
when(aclDAO.getBatchSanitizedSecretsFor(client, secretnames)).thenReturn(List.of(sanitizedSecret));
when(clientDAO.getClientByName(client.getName())).thenReturn(Optional.of(client));
when(secretController.getSecretsByName(secretnames)).thenReturn(List.of(secret));
batchSecretDeliveryResource.getBatchSecret(client, req);
}
Aggregations