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());
}
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");
}
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);
}
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());
}
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");
}
Aggregations