Search in sources :

Example 26 with SecretSeries

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

the class SecretSeriesDAOTest method ownerRoundTrip.

@Test
public void ownerRoundTrip() {
    String ownerName = "foo";
    long ownerId = groupDAO.createGroup(ownerName, null, null, ImmutableMap.of());
    long secretId = secretSeriesDAO.createSecretSeries("name", ownerId, null, null, null, null, ApiDate.now().toEpochSecond());
    createSecretContent(secretId);
    SecretSeries series = secretSeriesDAO.getSecretSeriesById(secretId).get();
    assertEquals(ownerName, series.owner());
}
Also used : SecretSeries(keywhiz.api.model.SecretSeries) Test(org.junit.Test)

Example 27 with SecretSeries

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

the class SecretSeriesDAOTest method createAndLookupSecretSeries.

@Test
public void createAndLookupSecretSeries() {
    int before = tableSize();
    long now = OffsetDateTime.now().toEpochSecond();
    ApiDate nowDate = new ApiDate(now);
    long id = secretSeriesDAO.createSecretSeries("newSecretSeries", null, "creator", "desc", null, ImmutableMap.of("foo", "bar"), now);
    long contentId = secretContentDAO.createSecretContent(id, "blah", "checksum", "creator", null, 0, now);
    secretSeriesDAO.setCurrentVersion(id, contentId, "creator", now);
    SecretSeries expected = SecretSeries.of(id, "newSecretSeries", null, "desc", nowDate, "creator", nowDate, "creator", null, ImmutableMap.of("foo", "bar"), contentId);
    assertThat(tableSize()).isEqualTo(before + 1);
    SecretSeries actual = secretSeriesDAO.getSecretSeriesById(id).orElseThrow(RuntimeException::new);
    assertThat(actual).isEqualTo(expected);
    actual = secretSeriesDAO.getSecretSeriesByName("newSecretSeries").orElseThrow(RuntimeException::new);
    assertThat(actual).isEqualToComparingOnlyGivenFields(expected, "name", "description", "type", "generationOptions", "currentVersion");
}
Also used : ApiDate(keywhiz.api.ApiDate) SecretSeries(keywhiz.api.model.SecretSeries) Test(org.junit.Test)

Example 28 with SecretSeries

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

the class SecretSeriesDAOTest method getMultipleSecretSeriesByName.

@Test
public void getMultipleSecretSeriesByName() {
    int before = tableSize();
    long now = OffsetDateTime.now().toEpochSecond();
    ApiDate nowDate = new ApiDate(now);
    long id = secretSeriesDAO.createSecretSeries("newSecretSeries", null, "creator", "desc", null, ImmutableMap.of("foo", "bar"), now);
    long contentId = secretContentDAO.createSecretContent(id, "blah", "checksum", "creator", null, 0, now);
    secretSeriesDAO.setCurrentVersion(id, contentId, "creator", now);
    long id2 = secretSeriesDAO.createSecretSeries("newSecretSeries2", null, "creator", "desc", null, ImmutableMap.of("f00", "b4r"), now);
    long contentId2 = secretContentDAO.createSecretContent(id2, "blah", "checksum", "creator", null, 0, now);
    secretSeriesDAO.setCurrentVersion(id2, contentId2, "creator", now);
    assertThat(tableSize()).isEqualTo(before + 2);
    SecretSeries expected1 = SecretSeries.of(id, "newSecretSeries", null, "desc", nowDate, "creator", nowDate, "creator", null, ImmutableMap.of("foo", "bar"), contentId);
    SecretSeries expected2 = SecretSeries.of(id2, "newSecretSeries2", null, "desc", nowDate, "creator", nowDate, "creator", null, ImmutableMap.of("f00", "b4r"), contentId2);
    List<SecretSeries> actual = secretSeriesDAO.getMultipleSecretSeriesByName(List.of("newSecretSeries", "newSecretSeries2"));
    assertThat(actual).contains(expected1);
    assertThat(actual).contains(expected2);
}
Also used : ApiDate(keywhiz.api.ApiDate) SecretSeries(keywhiz.api.model.SecretSeries) Test(org.junit.Test)

Example 29 with SecretSeries

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

the class SecretSeriesMapperTest method mapsRecordWithNullOwner.

@Test
public void mapsRecordWithNullOwner() {
    SecretsRecord record = minimalRecord();
    assertNull(record.getOwner());
    SecretSeries series = mapper.map(record);
    assertNull(series.owner());
}
Also used : SecretsRecord(keywhiz.jooq.tables.records.SecretsRecord) SecretSeries(keywhiz.api.model.SecretSeries) Test(org.junit.Test)

Example 30 with SecretSeries

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

the class AclDAOTest method getSecretSeriesFor.

@Test
public void getSecretSeriesFor() throws Exception {
    SecretSeries secretSeries1 = secretSeriesDAO.getSecretSeriesById(secret1.getId()).get();
    aclDAO.enrollClient(jooqContext.configuration(), client2.getId(), group1.getId());
    aclDAO.enrollClient(jooqContext.configuration(), client2.getId(), group3.getId());
    aclDAO.enrollClient(jooqContext.configuration(), client2.getId(), group2.getId());
    aclDAO.allowAccess(jooqContext.configuration(), secret1.getId(), group1.getId());
    aclDAO.allowAccess(jooqContext.configuration(), secret1.getId(), group2.getId());
    SecretSeries secretSeries = aclDAO.getSecretSeriesFor(jooqContext.configuration(), client2, secret1.getName()).orElseThrow(RuntimeException::new);
    assertThat(secretSeries).isEqualToIgnoringGivenFields(secretSeries1, "id");
    aclDAO.evictClient(jooqContext.configuration(), client2.getId(), group1.getId());
    aclDAO.evictClient(jooqContext.configuration(), client2.getId(), group2.getId());
    assertThat(aclDAO.getSecretSeriesFor(jooqContext.configuration(), client2, secret1.getName())).isEmpty();
    aclDAO.allowAccess(jooqContext.configuration(), secret1.getId(), group3.getId());
    secretSeries = aclDAO.getSecretSeriesFor(jooqContext.configuration(), client2, secret1.getName()).orElseThrow(RuntimeException::new);
    assertThat(secretSeries).isEqualToIgnoringGivenFields(secretSeries1, "id");
}
Also used : SecretSeries(keywhiz.api.model.SecretSeries) Test(org.junit.Test)

Aggregations

SecretSeries (keywhiz.api.model.SecretSeries)30 Test (org.junit.Test)12 SecretContent (keywhiz.api.model.SecretContent)9 SecretSeriesAndContent (keywhiz.api.model.SecretSeriesAndContent)8 ApiDate (keywhiz.api.ApiDate)6 ImmutableList (com.google.common.collect.ImmutableList)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 NotFoundException (javax.ws.rs.NotFoundException)3 SecretsRecord (keywhiz.jooq.tables.records.SecretsRecord)3 HashSet (java.util.HashSet)2 Group (keywhiz.api.model.Group)2 SanitizedSecret (keywhiz.api.model.SanitizedSecret)2 Secret (keywhiz.api.model.Secret)2 Event (keywhiz.log.Event)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 ArrayList (java.util.ArrayList)1 BadRequestException (javax.ws.rs.BadRequestException)1 ContentEncodingException (keywhiz.service.crypto.ContentEncodingException)1 Record (org.jooq.Record)1 DataAccessException (org.jooq.exception.DataAccessException)1