Search in sources :

Example 16 with ApiDate

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);
}
Also used : ApiDate(keywhiz.api.ApiDate) AutomationClient(keywhiz.api.model.AutomationClient) Client(keywhiz.api.model.Client) Before(org.junit.Before)

Example 17 with ApiDate

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

Example 18 with ApiDate

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

Example 19 with ApiDate

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

Aggregations

ApiDate (keywhiz.api.ApiDate)19 Test (org.junit.Test)14 Client (keywhiz.api.model.Client)13 SecretSeries (keywhiz.api.model.SecretSeries)6 URI (java.net.URI)2 AutomationClient (keywhiz.api.model.AutomationClient)2 SpiffePrincipal (keywhiz.auth.mutualssl.SpiffePrincipal)2 Instant (java.time.Instant)1 CertificatePrincipal (keywhiz.auth.mutualssl.CertificatePrincipal)1 SecretsRecord (keywhiz.jooq.tables.records.SecretsRecord)1 Record (org.jooq.Record)1 Before (org.junit.Before)1