Search in sources :

Example 16 with Secret

use of keywhiz.api.model.Secret in project keywhiz by square.

the class BatchSecretDeliveryResourceIntegrationTest method setUp.

// For declaration of these passwords see file server/src/main/java/keywhiz/commands/DbSeedCommand.java
// DbSeedCommand is invoked via MigrationRule
// TODO(michael): refactor how we test
@Before
public void setUp() throws Exception {
    client = TestClients.mutualSslClient();
    keywhizClient = TestClients.keywhizClient();
    generalPassword = new Secret(0, "General_Password", null, null, () -> "YXNkZGFz", "", ApiDate.parse("2011-09-29T15:46:00Z"), null, ApiDate.parse("2011-09-29T15:46:00Z"), null, null, "upload", null, 0, 1L, ApiDate.parse("2011-09-29T15:46:00Z"), null);
    databasePassword = new Secret(1, "Database_Password", null, null, () -> "MTIzNDU=", "", ApiDate.parse("2011-09-29T15:46:00.232Z"), null, ApiDate.parse("2011-09-29T15:46:00.232Z"), null, null, null, null, 0, 2L, ApiDate.parse("2011-09-29T15:46:00.312Z"), null);
}
Also used : Secret(keywhiz.api.model.Secret) Before(org.junit.Before)

Example 17 with Secret

use of keywhiz.api.model.Secret in project keywhiz by square.

the class SecretDeliveryResourceTest method returnsSecretWhenAllowed.

@Test
public void returnsSecretWhenAllowed() throws Exception {
    Secret secret = new Secret(0, "secret_name", null, null, () -> "unused_secret", "checksum", NOW, null, NOW, null, null, null, null, 0, 1L, NOW, null);
    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 18 with Secret

use of keywhiz.api.model.Secret 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, null, () -> "U3BpZGVybWFu", "checksum", NOW, null, NOW, null, null, null, null, 0, 1L, NOW, null);
    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)

Example 19 with Secret

use of keywhiz.api.model.Secret in project keywhiz by square.

the class SecretsDeliveryResourceIntegrationTest method setUp.

@Before
public void setUp() throws Exception {
    client = TestClients.mutualSslClient();
    noSecretsClient = TestClients.noSecretsClient();
    clientNoClientCert = TestClients.unauthenticatedClient();
    generalPassword = SecretDeliveryResponse.fromSanitizedSecret(SanitizedSecret.fromSecret(new Secret(0, "General_Password", null, null, () -> "YXNkZGFz", "checksum", ApiDate.parse("2011-09-29T15:46:00.312Z"), null, ApiDate.parse("2011-09-29T15:46:00.312Z"), null, null, null, null, 0, 1L, ApiDate.parse("2011-09-29T15:46:00.312Z"), null)));
    databasePassword = SecretDeliveryResponse.fromSanitizedSecret(SanitizedSecret.fromSecret(new Secret(1, "Database_Password", null, null, () -> "MTIzNDU=", "checksum", ApiDate.parse("2011-09-29T15:46:00.232Z"), null, ApiDate.parse("2011-09-29T15:46:00.232Z"), null, null, null, null, 0, 2L, ApiDate.parse("2011-09-29T15:46:00.312Z"), null)));
    nobodyPgPassPassword = SecretDeliveryResponse.fromSanitizedSecret(SanitizedSecret.fromSecret(new Secret(2, "Nobody_PgPass", null, null, () -> "c29tZWhvc3Quc29tZXBsYWNlLmNvbTo1NDMyOnNvbWVkYXRhYmFzZTptaXN0ZXJhd2Vzb21lOmhlbGwwTWNGbHkK", "checksum", ApiDate.parse("2011-09-29T15:46:00.232Z"), null, ApiDate.parse("2011-09-29T15:46:00.232Z"), null, ImmutableMap.of("owner", "nobody", "mode", "0400"), null, null, 0, 3L, ApiDate.parse("2011-09-29T15:46:00.312Z"), null)));
    nonExistentOwnerPass = SecretDeliveryResponse.fromSanitizedSecret(SanitizedSecret.fromSecret(new Secret(3, "NonexistentOwner_Pass", null, null, () -> "MTIzNDU=", "checksum", ApiDate.parse("2011-09-29T15:46:00.232Z"), null, ApiDate.parse("2011-09-29T15:46:00.232Z"), null, ImmutableMap.of("owner", "NonExistent", "mode", "0400"), null, null, 0, 4L, ApiDate.parse("2011-09-29T15:46:00.312Z"), null)));
}
Also used : Secret(keywhiz.api.model.Secret) SanitizedSecret(keywhiz.api.model.SanitizedSecret) Before(org.junit.Before)

Example 20 with Secret

use of keywhiz.api.model.Secret in project keywhiz by square.

the class ClientsResourceTest method includesAssociations.

@Test
public void includesAssociations() {
    Group group1 = new Group(0, "group1", null, null, null, null, null, null);
    Group group2 = new Group(0, "group2", null, null, null, null, null, null);
    Secret secret = new Secret(15, "secret", null, null, () -> "supersecretdata", "checksum", now, "creator", now, "updater", null, null, null, 0, 1L, now, "updater");
    when(clientDAO.getClientById(1)).thenReturn(Optional.of(client));
    when(aclDAO.getGroupsFor(client)).thenReturn(Sets.newHashSet(group1, group2));
    when(aclDAO.getSanitizedSecretsFor(client)).thenReturn(ImmutableSet.of(SanitizedSecret.fromSecret(secret)));
    ClientDetailResponse response = resource.getClient(user, new LongParam("1"));
    assertThat(response.groups).containsOnly(group1, group2);
    assertThat(response.secrets).containsOnly(SanitizedSecret.fromSecret(secret));
}
Also used : Secret(keywhiz.api.model.Secret) SanitizedSecret(keywhiz.api.model.SanitizedSecret) Group(keywhiz.api.model.Group) LongParam(io.dropwizard.jersey.params.LongParam) ClientDetailResponse(keywhiz.api.ClientDetailResponse) Test(org.junit.Test)

Aggregations

Secret (keywhiz.api.model.Secret)34 SanitizedSecret (keywhiz.api.model.SanitizedSecret)21 ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)15 Timed (com.codahale.metrics.annotation.Timed)15 Test (org.junit.Test)14 HashMap (java.util.HashMap)12 Event (keywhiz.log.Event)12 NotFoundException (javax.ws.rs.NotFoundException)10 POST (javax.ws.rs.POST)10 Path (javax.ws.rs.Path)9 Consumes (javax.ws.rs.Consumes)8 Group (keywhiz.api.model.Group)6 ConflictException (keywhiz.service.exceptions.ConflictException)6 Response (javax.ws.rs.core.Response)5 SecretController (keywhiz.service.daos.SecretController)5 DataAccessException (org.jooq.exception.DataAccessException)5 ArrayList (java.util.ArrayList)4 DELETE (javax.ws.rs.DELETE)4 GET (javax.ws.rs.GET)4 SecretDetailResponse (keywhiz.api.SecretDetailResponse)4