Search in sources :

Example 11 with SanitizedSecret

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

Example 12 with SanitizedSecret

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

Example 13 with SanitizedSecret

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

Example 14 with SanitizedSecret

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

Example 15 with SanitizedSecret

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

Aggregations

SanitizedSecret (keywhiz.api.model.SanitizedSecret)41 Test (org.junit.Test)20 Group (keywhiz.api.model.Group)13 Client (keywhiz.api.model.Client)12 NotFoundException (javax.ws.rs.NotFoundException)10 IOException (java.io.IOException)9 ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)7 Timed (com.codahale.metrics.annotation.Timed)7 GET (javax.ws.rs.GET)6 Secret (keywhiz.api.model.Secret)5 KeywhizClient (keywhiz.client.KeywhizClient)5 ImmutableList (com.google.common.collect.ImmutableList)4 SecretDeliveryResponse (keywhiz.api.SecretDeliveryResponse)4 AutomationClient (keywhiz.api.model.AutomationClient)4 NotFoundException (keywhiz.client.KeywhizClient.NotFoundException)4 Consumes (javax.ws.rs.Consumes)3 POST (javax.ws.rs.POST)3 Path (javax.ws.rs.Path)3 BatchSecretRequest (keywhiz.api.BatchSecretRequest)3 GroupDetailResponse (keywhiz.api.GroupDetailResponse)3