use of com.yahoo.athenz.common.server.cert.X509CertRecord in project athenz by yahoo.
the class DynamoDBCertRecordStoreConnectionTest method testUpdateUnrefreshedCertificatesNotificationTimestampUpdateException.
@Test
public void testUpdateUnrefreshedCertificatesNotificationTimestampUpdateException() {
DynamoDBCertRecordStoreConnection dbConn = getDBConnection();
Date now = new Date(1591706189000L);
long nowL = now.getTime();
long fiveDaysAgo = nowL - 5 * 24 * 60 * 60 * 1000;
Map<String, AttributeValue> reNotified = ZTSTestUtils.generateAttributeValues("home.test.service3", "reNotified", Long.toString(fiveDaysAgo), Long.toString(fiveDaysAgo), "testServer", null, "testHost2");
Item item1 = ItemUtils.toItem(reNotified);
ItemCollection<QueryOutcome> itemCollection = Mockito.mock(ItemCollection.class);
IteratorSupport<Item, QueryOutcome> iteratorSupport = Mockito.mock(IteratorSupport.class);
when(itemCollection.iterator()).thenReturn(iteratorSupport);
when(iteratorSupport.hasNext()).thenReturn(true, false);
when(iteratorSupport.next()).thenReturn(item1);
Mockito.doReturn(itemCollection).when(currentTimeIndex).query(any(QuerySpec.class));
ItemCollection<QueryOutcome> itemCollection2 = Mockito.mock(ItemCollection.class);
IteratorSupport<Item, QueryOutcome> iteratorSupport2 = Mockito.mock(IteratorSupport.class);
when(itemCollection2.iterator()).thenReturn(iteratorSupport2);
when(iteratorSupport2.hasNext()).thenReturn(true, false);
when(iteratorSupport2.next()).thenReturn(item1);
Mockito.doReturn(itemCollection2).when(hostNameIndex).query(any(QuerySpec.class));
Mockito.doThrow(new TransactionConflictException("error")).when(table).updateItem(any(UpdateItemSpec.class));
List<X509CertRecord> result = dbConn.updateUnrefreshedCertificatesNotificationTimestamp("serverTest", 1591706189000L, "providerTest");
assertEquals(result.size(), 0);
dbConn.close();
}
use of com.yahoo.athenz.common.server.cert.X509CertRecord in project athenz by yahoo.
the class DynamoDBCertRecordStoreConnectionTest method testGetX509CertRecordNotFoundNull.
@Test
public void testGetX509CertRecordNotFoundNull() {
Mockito.doReturn(null).when(table).getItem("primaryKey", "athenz.provider:cn:1234");
DynamoDBCertRecordStoreConnection dbConn = getDBConnection();
X509CertRecord certRecord = dbConn.getX509CertRecord("athenz.provider", "1234", "cn");
assertNull(certRecord);
dbConn.close();
}
use of com.yahoo.athenz.common.server.cert.X509CertRecord in project athenz by yahoo.
the class DynamoDBCertRecordStoreConnectionTest method testUpdateUnrefreshedCertificatesNotificationTimestampTimeException.
@Test
public void testUpdateUnrefreshedCertificatesNotificationTimestampTimeException() {
DynamoDBCertRecordStoreConnection dbConn = getDBConnection();
Mockito.doThrow(new TransactionConflictException("error")).when(currentTimeIndex).query(any(QuerySpec.class));
List<X509CertRecord> result = dbConn.updateUnrefreshedCertificatesNotificationTimestamp("serverTest", 1591706189000L, "providerTest");
assertEquals(result.size(), 0);
dbConn.close();
}
use of com.yahoo.athenz.common.server.cert.X509CertRecord in project athenz by yahoo.
the class DynamoDBCertRecordStoreConnectionTest method testInsertX509RecordException.
@Test
public void testInsertX509RecordException() {
Date now = new Date();
X509CertRecord certRecord = getRecordNonNullableColumns(now);
Mockito.doThrow(new AmazonDynamoDBException("invalid operation")).when(table).putItem(any(Item.class));
DynamoDBCertRecordStoreConnection dbConn = getDBConnection();
boolean requestSuccess = dbConn.insertX509CertRecord(certRecord);
assertFalse(requestSuccess);
dbConn.close();
}
use of com.yahoo.athenz.common.server.cert.X509CertRecord in project athenz by yahoo.
the class DynamoDBCertRecordStoreConnectionTest method testUpdateX509Record.
@Test
public void testUpdateX509Record() {
DynamoDBCertRecordStoreConnection dbConn = getDBConnection();
Date now = new Date();
X509CertRecord certRecord = getRecordNonNullableColumns(now);
certRecord.setLastNotifiedTime(now);
certRecord.setLastNotifiedServer("last-notified-server");
certRecord.setExpiryTime(now);
certRecord.setHostName("hostname");
certRecord.setSvcDataUpdateTime(now);
UpdateItemSpec item = new UpdateItemSpec().withPrimaryKey("primaryKey", "athenz.provider:cn:1234").withAttributeUpdate(new AttributeUpdate("instanceId").put(certRecord.getInstanceId()), new AttributeUpdate("provider").put(certRecord.getProvider()), new AttributeUpdate("service").put(certRecord.getService()), new AttributeUpdate("currentSerial").put(certRecord.getCurrentSerial()), new AttributeUpdate("currentIP").put(certRecord.getCurrentIP()), new AttributeUpdate("currentTime").put(certRecord.getCurrentTime().getTime()), new AttributeUpdate("currentDate").put(DynamoDBUtils.getIso8601FromDate(certRecord.getCurrentTime())), new AttributeUpdate("prevSerial").put(certRecord.getPrevSerial()), new AttributeUpdate("prevIP").put(certRecord.getPrevIP()), new AttributeUpdate("prevTime").put(certRecord.getPrevTime().getTime()), new AttributeUpdate("clientCert").put(certRecord.getClientCert()), new AttributeUpdate("ttl").put(certRecord.getCurrentTime().getTime() / 1000L + 3660 * 720), new AttributeUpdate("svcDataUpdateTime").put(certRecord.getSvcDataUpdateTime().getTime()), new AttributeUpdate("expiryTime").put(certRecord.getExpiryTime().getTime()), new AttributeUpdate("hostName").put(certRecord.getHostName()));
Mockito.doReturn(updateOutcome).when(table).updateItem(item);
boolean requestSuccess = dbConn.updateX509CertRecord(certRecord);
assertTrue(requestSuccess);
ArgumentCaptor<UpdateItemSpec> itemCaptor = ArgumentCaptor.forClass(UpdateItemSpec.class);
Mockito.verify(table, times(1)).updateItem(itemCaptor.capture());
List<UpdateItemSpec> allValues = itemCaptor.getAllValues();
assertEquals(1, allValues.size());
UpdateItemSpec capturedItem = allValues.get(0);
assertEquals(capturedItem.getKeyComponents().toArray()[0].toString(), item.getKeyComponents().toArray()[0].toString());
List<AttributeUpdate> capturedAttributes = capturedItem.getAttributeUpdate();
List<AttributeUpdate> expectedAttributes = item.getAttributeUpdate();
for (int i = 0; i < expectedAttributes.size(); ++i) {
System.out.println("expected attr: " + expectedAttributes.get(i).getAttributeName() + ", value: " + expectedAttributes.get(i).getValue());
assertEquals(capturedAttributes.get(i).getAttributeName(), expectedAttributes.get(i).getAttributeName());
assertEquals(capturedAttributes.get(i).getValue(), expectedAttributes.get(i).getValue());
}
dbConn.close();
}
Aggregations