use of keywhiz.api.SecretDeliveryResponse in project keywhiz by square.
the class SecretDeliveryResourceTest method returnsSecretWhenAllowed.
@Test
public void returnsSecretWhenAllowed() throws Exception {
Secret secret = new Secret(0, "secret_name", null, () -> "unused_secret", "checksum", NOW, null, NOW, null, null, null, null, 0, 1L);
SanitizedSecret sanitizedSecret = SanitizedSecret.fromSecret(secret);
String name = sanitizedSecret.name();
when(aclDAO.getSanitizedSecretFor(client, name)).thenReturn(Optional.of(sanitizedSecret));
when(secretController.getSecretByName(name)).thenReturn(Optional.of(secret));
SecretDeliveryResponse response = secretDeliveryResource.getSecret(sanitizedSecret.name(), client);
assertThat(response).isEqualTo(SecretDeliveryResponse.fromSecret(secret));
}
use of keywhiz.api.SecretDeliveryResponse in project keywhiz by square.
the class SecretDeliveryResourceTest method doesNotEscapeBase64.
@Test
public void doesNotEscapeBase64() throws Exception {
String name = secretBase64.getName();
when(aclDAO.getSanitizedSecretFor(client, name)).thenReturn(Optional.of(SanitizedSecret.fromSecret(secretBase64)));
when(secretController.getSecretByName(name)).thenReturn(Optional.of(secretBase64));
SecretDeliveryResponse response = secretDeliveryResource.getSecret(secretBase64.getName(), client);
assertThat(response.getSecret()).isEqualTo(secretBase64.getSecret());
}
use of keywhiz.api.SecretDeliveryResponse in project keywhiz by square.
the class SecretDeliveryResourceTest method returnsVersionedSecretWhenAllowed.
@Test
public void returnsVersionedSecretWhenAllowed() throws Exception {
String name = "secret_name";
Secret versionedSecret = new Secret(2, name, null, () -> "U3BpZGVybWFu", "checksum", NOW, null, NOW, null, null, null, null, 0, 1L);
when(aclDAO.getSanitizedSecretFor(client, name)).thenReturn(Optional.of(SanitizedSecret.fromSecret(versionedSecret)));
when(secretController.getSecretByName(name)).thenReturn(Optional.of(versionedSecret));
String displayName = versionedSecret.getDisplayName();
SecretDeliveryResponse response = secretDeliveryResource.getSecret(displayName, client);
assertThat(response).isEqualTo(SecretDeliveryResponse.fromSecret(versionedSecret));
}
Aggregations