use of keywhiz.api.ApiDate in project keywhiz by square.
the class BackfillRowHmacResourceIntegrationTest method before.
@Before
public void before() {
secretDAO = secretDAOFactory.readwrite();
secretSeriesDAO = secretSeriesDAOFactory.readwrite();
ApiDate now = ApiDate.now();
Client client = new Client(1, "client", "1st client", null, now, "test", now, "test", null, null, true, true);
automationClient = AutomationClient.of(client);
}
use of keywhiz.api.ApiDate in project keywhiz by square.
the class SecretSeriesDAOTest method getMultipleSecretSeriesByNameDuplicatesReturnsOne.
@Test
public void getMultipleSecretSeriesByNameDuplicatesReturnsOne() {
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);
List<SecretSeries> expected = List.of(SecretSeries.of(id, "newSecretSeries", null, "desc", nowDate, "creator", nowDate, "creator", null, ImmutableMap.of("foo", "bar"), contentId));
assertThat(tableSize()).isEqualTo(before + 1);
// Requesting same secret multiple times - should yield one result
List<SecretSeries> actual = secretSeriesDAO.getMultipleSecretSeriesByName(List.of("newSecretSeries", "newSecretSeries", "newSecretSeries"));
assertThat(actual).isEqualTo(expected);
}
use of keywhiz.api.ApiDate 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.ApiDate 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);
}
Aggregations