use of com.yahoo.athenz.common.server.cert.X509CertRecord in project athenz by yahoo.
the class JDBCCertRecordStoreConnectionTest method testUpdateX509RecordException.
@Test
public void testUpdateX509RecordException() throws Exception {
JDBCCertRecordStoreConnection jdbcConn = new JDBCCertRecordStoreConnection(mockConn);
Date now = new Date();
X509CertRecord certRecord = getRecordWithNonNullableColumns(now);
certRecord.setExpiryTime(now);
certRecord.setHostName("hostname");
Mockito.doThrow(new SQLException("error", "state", 503)).when(mockPrepStmt).executeUpdate();
try {
jdbcConn.updateX509CertRecord(certRecord);
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 500);
}
jdbcConn.close();
}
use of com.yahoo.athenz.common.server.cert.X509CertRecord in project athenz by yahoo.
the class JDBCCertRecordStoreConnectionTest method testUpdateUnrefreshedCertificatesNotificationTimestamp.
@Test
public void testUpdateUnrefreshedCertificatesNotificationTimestamp() throws Exception {
JDBCCertRecordStoreConnection jdbcConn = new JDBCCertRecordStoreConnection(mockConn);
Mockito.when(mockPrepStmt.executeUpdate()).thenReturn(// 3 members updated
3).thenReturn(// On second call, no members were updated
0);
long currentTime = System.currentTimeMillis();
Timestamp ts = new Timestamp(currentTime);
Mockito.when(mockResultSet.getTimestamp(JDBCCertRecordStoreConnection.DB_COLUMN_LAST_NOTIFIED_TIME)).thenReturn(ts).thenReturn(ts).thenReturn(ts);
Mockito.when(mockResultSet.getString(JDBCCertRecordStoreConnection.DB_COLUMN_LAST_NOTIFIED_SERVER)).thenReturn("server0").thenReturn("server1").thenReturn("server2");
Mockito.when(mockResultSet.next()).thenReturn(// this one is for server1
true).thenReturn(// this one is for server2
true).thenReturn(// this one is for server3
true).thenReturn(// end
false);
Mockito.when(mockResultSet.getString(JDBCCertRecordStoreConnection.DB_COLUMN_SERVICE)).thenReturn(null);
Mockito.when(mockResultSet.getString(JDBCCertRecordStoreConnection.DB_COLUMN_HOSTNAME)).thenReturn(null);
Mockito.when(mockResultSet.getString(JDBCCertRecordStoreConnection.DB_COLUMN_INSTANCE_ID)).thenReturn(null);
Mockito.when(mockResultSet.getTimestamp(JDBCCertRecordStoreConnection.DB_COLUMN_EXPIRY_TIME)).thenReturn(ts);
Mockito.when(mockResultSet.getBoolean(JDBCCertRecordStoreConnection.DB_COLUMN_CLIENT_CERT)).thenReturn(false);
Mockito.when(mockResultSet.getTimestamp(JDBCCertRecordStoreConnection.DB_COLUMN_CURRENT_TIME)).thenReturn(ts);
Mockito.when(mockResultSet.getTimestamp(JDBCCertRecordStoreConnection.DB_COLUMN_PREV_TIME)).thenReturn(ts);
List<X509CertRecord> unrefreshedCertificateRecords = jdbcConn.updateUnrefreshedCertificatesNotificationTimestamp("localhost", currentTime, "provider");
assertNotNull(unrefreshedCertificateRecords);
assertEquals(unrefreshedCertificateRecords.size(), 3);
for (int i = 0; i < unrefreshedCertificateRecords.size(); ++i) {
assertEquals(unrefreshedCertificateRecords.get(i).getLastNotifiedServer(), "server" + i);
assertEquals(unrefreshedCertificateRecords.get(i).getLastNotifiedTime(), new Date(currentTime));
}
jdbcConn.close();
}
use of com.yahoo.athenz.common.server.cert.X509CertRecord in project athenz by yahoo.
the class JDBCCertRecordStoreConnectionTest method testInsertX509RecordException.
@Test
public void testInsertX509RecordException() throws Exception {
JDBCCertRecordStoreConnection jdbcConn = new JDBCCertRecordStoreConnection(mockConn);
Date now = new Date();
X509CertRecord certRecord = getRecordWithNonNullableColumns(now);
certRecord.setExpiryTime(now);
certRecord.setHostName("hostname");
Mockito.doThrow(new SQLException("error", "state", 503)).when(mockPrepStmt).executeUpdate();
try {
jdbcConn.insertX509CertRecord(certRecord);
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 500);
}
jdbcConn.close();
}
use of com.yahoo.athenz.common.server.cert.X509CertRecord in project athenz by yahoo.
the class JDBCCertRecordStoreConnectionTest method testUpdateX509Record.
@Test
public void testUpdateX509Record() throws Exception {
JDBCCertRecordStoreConnection jdbcConn = new JDBCCertRecordStoreConnection(mockConn);
Date now = new Date();
X509CertRecord certRecord = getRecordWithNonNullableColumns(now);
certRecord.setLastNotifiedTime(now);
certRecord.setLastNotifiedServer("last-notified-server");
certRecord.setExpiryTime(now);
certRecord.setHostName("hostname");
Mockito.doReturn(1).when(mockPrepStmt).executeUpdate();
boolean requestSuccess = jdbcConn.updateX509CertRecord(certRecord);
assertTrue(requestSuccess);
verifyUpdateNonNullableColumns(now);
Mockito.verify(mockPrepStmt, times(1)).setTimestamp(7, new java.sql.Timestamp(now.getTime()));
Mockito.verify(mockPrepStmt, times(1)).setString(8, "hostname");
jdbcConn.close();
}
use of com.yahoo.athenz.common.server.cert.X509CertRecord in project athenz by yahoo.
the class DynamoDBCertRecordStoreConnectionTest method testGetX509CertRecordNullableColumns.
@Test
public void testGetX509CertRecordNullableColumns() {
Date now = new Date();
mockNonNullableColumns(now, true);
Mockito.doReturn(true).when(item).isNull("lastNotifiedTime");
Mockito.doReturn(true).when(item).isNull("lastNotifiedServer");
Mockito.doReturn(true).when(item).isNull("expiryTime");
Mockito.doReturn(true).when(item).isNull("hostName");
DynamoDBCertRecordStoreConnection dbConn = getDBConnection();
dbConn.setOperationTimeout(10);
X509CertRecord certRecord = dbConn.getX509CertRecord("athenz.provider", "1234", "cn");
assertNonNullableColumns(now, certRecord);
assertNull(certRecord.getLastNotifiedTime());
assertNull(certRecord.getLastNotifiedServer());
assertNull(certRecord.getExpiryTime());
assertNull(certRecord.getHostName());
dbConn.close();
}
Aggregations