Search in sources :

Example 26 with SSHCertRecord

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();
}
Also used : File(java.io.File) SSHCertRecord(com.yahoo.athenz.common.server.ssh.SSHCertRecord) Test(org.testng.annotations.Test)

Example 27 with SSHCertRecord

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();
}
Also used : SSHCertRecord(com.yahoo.athenz.common.server.ssh.SSHCertRecord) Test(org.testng.annotations.Test)

Example 28 with SSHCertRecord

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();
}
Also used : UpdateItemSpec(com.amazonaws.services.dynamodbv2.document.spec.UpdateItemSpec) SSHCertRecord(com.yahoo.athenz.common.server.ssh.SSHCertRecord) Test(org.testng.annotations.Test)

Example 29 with SSHCertRecord

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();
}
Also used : AmazonDynamoDBException(com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException) SSHCertRecord(com.yahoo.athenz.common.server.ssh.SSHCertRecord) Test(org.testng.annotations.Test)

Example 30 with SSHCertRecord

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();
}
Also used : AmazonDynamoDBException(com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException) SSHCertRecord(com.yahoo.athenz.common.server.ssh.SSHCertRecord) Test(org.testng.annotations.Test)

Aggregations

SSHCertRecord (com.yahoo.athenz.common.server.ssh.SSHCertRecord)57 Test (org.testng.annotations.Test)51 SSHSigner (com.yahoo.athenz.common.server.ssh.SSHSigner)14 HostnameResolver (com.yahoo.athenz.common.server.dns.HostnameResolver)12 Path (java.nio.file.Path)5 File (java.io.File)4 AmazonDynamoDBException (com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 SSHRecordStore (com.yahoo.athenz.common.server.ssh.SSHRecordStore)3 SSHRecordStoreConnection (com.yahoo.athenz.common.server.ssh.SSHRecordStoreConnection)3 IOException (java.io.IOException)3 UpdateItemSpec (com.amazonaws.services.dynamodbv2.document.spec.UpdateItemSpec)2 Principal (com.yahoo.athenz.auth.Principal)2 PrincipalToken (com.yahoo.athenz.auth.token.PrincipalToken)2 CryptoException (com.yahoo.athenz.auth.util.CryptoException)2 Priority (com.yahoo.athenz.common.server.cert.Priority)2 StatusCheckException (com.yahoo.athenz.common.server.status.StatusCheckException)2 InstanceConfirmation (com.yahoo.athenz.instance.provider.InstanceConfirmation)2 InstanceProvider (com.yahoo.athenz.instance.provider.InstanceProvider)2 ResourceException (com.yahoo.athenz.zts.ResourceException)2