Search in sources :

Example 1 with ApiDate

use of keywhiz.api.ApiDate in project keywhiz by square.

the class ClientDetailResponseV2Test method deserializesNullLastSeenCorrectly.

@Test
public void deserializesNullLastSeenCorrectly() throws Exception {
    ApiDate createdAt = new ApiDate(1343826930);
    ApiDate updatedAt = new ApiDate(1347246930);
    Client client = new Client(0, "Client Name", "Client Description", null, createdAt, "creator-user", updatedAt, "updater-user", null, null, true, false);
    ClientDetailResponseV2 clientDetailResponse = ClientDetailResponseV2.fromClient(client);
    assertThat(fromJson(jsonFixture("fixtures/v2/clientDetailResponse_LastSeenNull.json"), ClientDetailResponseV2.class)).isEqualTo(clientDetailResponse);
    assertThat(fromJson(asJson(clientDetailResponse), ClientDetailResponseV2.class)).isEqualTo(clientDetailResponse);
}
Also used : ApiDate(keywhiz.api.ApiDate) Client(keywhiz.api.model.Client) Test(org.junit.Test)

Example 2 with ApiDate

use of keywhiz.api.ApiDate in project keywhiz by square.

the class BackfillRowHmacResourceTest method newAutomationClient.

private static AutomationClient newAutomationClient(String clientName) {
    ApiDate now = ApiDate.now();
    Client client = new Client(1, clientName, "1st client", null, now, "test", now, "test", null, null, true, true);
    AutomationClient automationClient = AutomationClient.of(client);
    return automationClient;
}
Also used : ApiDate(keywhiz.api.ApiDate) AutomationClient(keywhiz.api.model.AutomationClient) AutomationClient(keywhiz.api.model.AutomationClient) Client(keywhiz.api.model.Client)

Example 3 with ApiDate

use of keywhiz.api.ApiDate in project keywhiz by square.

the class SecretSeriesDAOTest method getMultipleSecretSeriesByNameReturnsOne.

@Test
public void getMultipleSecretSeriesByNameReturnsOne() {
    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);
    List<SecretSeries> actual = secretSeriesDAO.getMultipleSecretSeriesByName(List.of("newSecretSeries"));
    assertThat(actual).isEqualTo(expected);
}
Also used : ApiDate(keywhiz.api.ApiDate) SecretSeries(keywhiz.api.model.SecretSeries) Test(org.junit.Test)

Example 4 with ApiDate

use of keywhiz.api.ApiDate in project keywhiz by square.

the class ClientAuthenticatorTest method doesNotCreateDbRecordForNewClient_whenNotConfigured.

@Test
public void doesNotCreateDbRecordForNewClient_whenNotConfigured() {
    ApiDate now = ApiDate.now();
    Client newClient = new Client(2345L, "new-client", "desc", null, now, "automatic", now, "automatic", null, null, true, false);
    // lookup doesn't find client
    when(clientDAO.getClientByName("new-client")).thenReturn(Optional.empty());
    // a new DB record should not be created, but mock the DAO to create a client if called
    when(clientDAO.createClient(eq("new-client"), eq("automatic"), any(), any())).thenReturn(2345L);
    when(clientDAO.getClientById(2345L)).thenReturn(Optional.of(newClient));
    assertThat(authenticator.authenticate(SimplePrincipal.of("CN=new-client"), false)).isEmpty();
    // the authenticator should not have tried to create the new client
    verify(clientDAO, never()).createClient(anyString(), anyString(), anyString(), any());
}
Also used : ApiDate(keywhiz.api.ApiDate) Client(keywhiz.api.model.Client) Test(org.junit.Test)

Example 5 with ApiDate

use of keywhiz.api.ApiDate in project keywhiz by square.

the class ClientAuthenticatorTest method createsDbRecordForNewClient_whenConfigured_spiffePrincipal.

@Test
public void createsDbRecordForNewClient_whenConfigured_spiffePrincipal() throws URISyntaxException {
    ApiDate now = ApiDate.now();
    Client newClient = new Client(2345L, "new-client", "desc", null, now, "automatic", now, "automatic", null, null, true, false);
    // lookup doesn't find client
    when(clientDAO.getClientByName("new-client")).thenReturn(Optional.empty());
    // a new DB record is created
    when(clientDAO.createClient(eq("new-client"), eq("automatic"), any(), any())).thenReturn(2345L);
    when(clientDAO.getClientById(2345L)).thenReturn(Optional.of(newClient));
    assertThat(authenticator.authenticate(new SpiffePrincipal(new URI("spiffe://example.org/new-client")), true)).isEqualTo(Optional.of(newClient));
}
Also used : ApiDate(keywhiz.api.ApiDate) Client(keywhiz.api.model.Client) URI(java.net.URI) SpiffePrincipal(keywhiz.auth.mutualssl.SpiffePrincipal) 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