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