Search in sources :

Example 1 with SecretDeliveryResponse

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));
}
Also used : Secret(keywhiz.api.model.Secret) SanitizedSecret(keywhiz.api.model.SanitizedSecret) SanitizedSecret(keywhiz.api.model.SanitizedSecret) SecretDeliveryResponse(keywhiz.api.SecretDeliveryResponse) Test(org.junit.Test)

Example 2 with SecretDeliveryResponse

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

Example 3 with SecretDeliveryResponse

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));
}
Also used : Secret(keywhiz.api.model.Secret) SanitizedSecret(keywhiz.api.model.SanitizedSecret) SecretDeliveryResponse(keywhiz.api.SecretDeliveryResponse) Test(org.junit.Test)

Aggregations

SecretDeliveryResponse (keywhiz.api.SecretDeliveryResponse)3 Test (org.junit.Test)3 SanitizedSecret (keywhiz.api.model.SanitizedSecret)2 Secret (keywhiz.api.model.Secret)2