use of com.yahoo.athenz.common.server.ssh.SSHCertRecord in project athenz by yahoo.
the class FileSSHRecordStoreConnectionTest method testSSHCertOperations.
@Test
public void testSSHCertOperations() {
// make sure the directory does not exist
ZTSTestUtils.deleteDirectory(new File("/tmp/zts-ssh-tests"));
FileSSHRecordStore store = new FileSSHRecordStore(new File("/tmp/zts-ssh-tests"));
FileSSHRecordStoreConnection con = (FileSSHRecordStoreConnection) store.getConnection();
assertNotNull(con);
con.setOperationTimeout(10);
// first verify that we don't have the entry
SSHCertRecord certRecordCheck = con.getSSHCertRecord("instance-id", "cn");
assertNull(certRecordCheck);
// now write the entry
SSHCertRecord certRecord = new SSHCertRecord();
certRecord.setInstanceId("instance-id");
certRecord.setService("cn");
certRecord.setPrincipals("host1,host2");
certRecord.setClientIP("10.10.10.11");
certRecord.setPrivateIP("10.10.10.12");
assertTrue(con.insertSSHCertRecord(certRecord));
// now read the entry again
certRecordCheck = con.getSSHCertRecord("instance-id", "cn");
assertNotNull(certRecordCheck);
assertEquals(certRecordCheck.getInstanceId(), "instance-id");
assertEquals(certRecordCheck.getService(), "cn");
assertEquals(certRecordCheck.getPrincipals(), "host1,host2");
assertEquals(certRecordCheck.getClientIP(), "10.10.10.11");
assertEquals(certRecordCheck.getPrivateIP(), "10.10.10.12");
// now update the entry
certRecord.setPrincipals("host1,host2,host3");
certRecord.setClientIP("10.10.10.13");
assertTrue(con.updateSSHCertRecord(certRecord));
certRecordCheck = con.getSSHCertRecord("instance-id", "cn");
assertNotNull(certRecordCheck);
assertEquals(certRecordCheck.getInstanceId(), "instance-id");
assertEquals(certRecordCheck.getService(), "cn");
assertEquals(certRecordCheck.getPrincipals(), "host1,host2,host3");
assertEquals(certRecordCheck.getClientIP(), "10.10.10.13");
assertEquals(certRecordCheck.getPrivateIP(), "10.10.10.12");
// now delete the entry
con.deleteSSHCertRecord("instance-id", "cn");
certRecordCheck = con.getSSHCertRecord("instance-id", "cn");
assertNull(certRecordCheck);
con.close();
}
use of com.yahoo.athenz.common.server.ssh.SSHCertRecord in project athenz by yahoo.
the class DynamoDBSSHRecordStoreConnectionTest method testInsertSSHRecord.
@Test
public void testInsertSSHRecord() {
DynamoDBSSHRecordStoreConnection dbConn = new DynamoDBSSHRecordStoreConnection(dynamoDB, tableName);
SSHCertRecord certRecord = new SSHCertRecord();
certRecord.setInstanceId("1234");
certRecord.setService("cn");
certRecord.setPrincipals("host1,host2");
certRecord.setClientIP("10.10.10.11");
certRecord.setPrivateIP("10.10.10.12");
Item item = new Item().withPrimaryKey("primaryKey", "cn:1234").withString("instanceId", certRecord.getInstanceId()).withString("service", certRecord.getService()).withString("principals", certRecord.getPrincipals()).withString("clientIP", certRecord.getClientIP()).withString("privateIP", certRecord.getPrivateIP());
Mockito.doReturn(putOutcome).when(table).putItem(item);
boolean requestSuccess = dbConn.insertSSHCertRecord(certRecord);
assertTrue(requestSuccess);
dbConn.close();
}
use of com.yahoo.athenz.common.server.ssh.SSHCertRecord in project athenz by yahoo.
the class DynamoDBSSHRecordStoreConnectionTest method testUpdateSSHRecord.
@Test
public void testUpdateSSHRecord() {
DynamoDBSSHRecordStoreConnection dbConn = new DynamoDBSSHRecordStoreConnection(dynamoDB, tableName);
SSHCertRecord certRecord = new SSHCertRecord();
certRecord.setInstanceId("1234");
certRecord.setService("cn");
certRecord.setPrincipals("host1,host2");
certRecord.setClientIP("10.10.10.11");
certRecord.setPrivateIP("10.10.10.12");
UpdateItemSpec item = new UpdateItemSpec().withPrimaryKey("primaryKey", "cn:1234").withAttributeUpdate(new AttributeUpdate("instanceId").put(certRecord.getInstanceId()), new AttributeUpdate("service").put(certRecord.getService()), new AttributeUpdate("principals").put(certRecord.getPrincipals()), new AttributeUpdate("clientIP").put(certRecord.getClientIP()), new AttributeUpdate("privateIP").put(certRecord.getPrivateIP()));
Mockito.doReturn(updateOutcome).when(table).updateItem(item);
boolean requestSuccess = dbConn.updateSSHCertRecord(certRecord);
assertTrue(requestSuccess);
dbConn.close();
}
use of com.yahoo.athenz.common.server.ssh.SSHCertRecord in project athenz by yahoo.
the class DynamoDBSSHRecordStoreConnectionTest method testInsertSSHRecordException.
@Test
public void testInsertSSHRecordException() {
SSHCertRecord certRecord = new SSHCertRecord();
Mockito.doThrow(new AmazonDynamoDBException("invalid operation")).when(table).putItem(ArgumentMatchers.any(Item.class));
DynamoDBSSHRecordStoreConnection dbConn = new DynamoDBSSHRecordStoreConnection(dynamoDB, tableName);
boolean requestSuccess = dbConn.insertSSHCertRecord(certRecord);
assertFalse(requestSuccess);
dbConn.close();
}
use of com.yahoo.athenz.common.server.ssh.SSHCertRecord in project athenz by yahoo.
the class DynamoDBSSHRecordStoreConnectionTest method testGetSSHCertRecordNotFoundException.
@Test
public void testGetSSHCertRecordNotFoundException() {
Mockito.doThrow(new AmazonDynamoDBException("item not found")).when(table).getItem("primaryKey", "cn:1234");
DynamoDBSSHRecordStoreConnection dbConn = new DynamoDBSSHRecordStoreConnection(dynamoDB, tableName);
SSHCertRecord certRecord = dbConn.getSSHCertRecord("1234", "cn");
assertNull(certRecord);
dbConn.close();
}
Aggregations