use of com.yahoo.athenz.common.server.ssh.SSHCertRecord in project athenz by yahoo.
the class InstanceCertManagerTest method testValidPrincipalsNoCnames.
@Test
public void testValidPrincipalsNoCnames() throws IOException {
Path path = Paths.get("src/test/resources/sshhost_nocnames.csr");
String sshCsr = new String(Files.readAllBytes(path));
SSHCertRecord sshCertRecord = new SSHCertRecord();
sshCertRecord.setService("athenz.examples.httpd");
// setup the hostname resolver for our request
String hostname = "host1.athenz.cloud";
HostnameResolver hostnameResolver = Mockito.mock(HostnameResolver.class);
when(hostnameResolver.isValidHostname(hostname)).thenReturn(true);
InstanceCertManager instanceManager = new InstanceCertManager(null, null, hostnameResolver, true, null);
ObjectMapper objectMapper = new ObjectMapper();
boolean result = instanceManager.validPrincipals("host1.athenz.cloud", sshCertRecord, objectMapper.readValue(sshCsr, SshHostCsr.class));
assertTrue(result);
instanceManager.shutdown();
}
use of com.yahoo.athenz.common.server.ssh.SSHCertRecord in project athenz by yahoo.
the class InstanceCertManagerTest method testInsertSSHCertRecord.
@Test
public void testInsertSSHCertRecord() {
InstanceCertManager instance = new InstanceCertManager(null, null, null, true, null);
instance.setSSHSigner(null);
SSHRecordStore certStore = Mockito.mock(SSHRecordStore.class);
SSHRecordStoreConnection certConnection = Mockito.mock(SSHRecordStoreConnection.class);
when(certStore.getConnection()).thenReturn(certConnection);
when(certConnection.insertSSHCertRecord(ArgumentMatchers.isA(SSHCertRecord.class))).thenReturn(true);
instance.setSSHStore(certStore);
SSHCertRecord sshCertRecord = new SSHCertRecord();
assertTrue(instance.updateSSHCertRecord(sshCertRecord, false));
instance.shutdown();
}
use of com.yahoo.athenz.common.server.ssh.SSHCertRecord in project athenz by yahoo.
the class InstanceCertManagerTest method testGenerateSshIdentityNullCertError.
@Test
public void testGenerateSshIdentityNullCertError() {
String sshCsr = "{\"csr\":\"csr\",\"certtype\":\"host\"}";
SSHSigner sshSigner = Mockito.mock(com.yahoo.athenz.common.server.ssh.SSHSigner.class);
SSHCertRequest sshRequest = new SSHCertRequest();
sshRequest.setCsr(sshCsr);
when(sshSigner.generateCertificate(null, sshRequest, null, "host")).thenReturn(null);
when(sshSigner.getSignerCertificate(ZTSConsts.ZTS_SSH_HOST)).thenReturn("ssh-host");
when(sshSigner.getSignerCertificate(ZTSConsts.ZTS_SSH_USER)).thenReturn("ssh-user");
InstanceCertManager instanceManager = new InstanceCertManager(null, null, null, true, null);
instanceManager.setSSHSigner(sshSigner);
InstanceIdentity identity = new InstanceIdentity().setName("athenz.service");
boolean result = instanceManager.generateSSHIdentity(null, identity, null, sshCsr, null, new SSHCertRecord(), "host");
assertFalse(result);
instanceManager.shutdown();
}
use of com.yahoo.athenz.common.server.ssh.SSHCertRecord in project athenz by yahoo.
the class InstanceCertManagerTest method testValidPrincipalsSSHRequest.
@Test
public void testValidPrincipalsSSHRequest() {
final String hostname = "host1.athenz.cloud";
HostnameResolver hostnameResolver = Mockito.mock(HostnameResolver.class);
when(hostnameResolver.isValidHostname(hostname)).thenReturn(true);
InstanceCertManager instanceManager = new InstanceCertManager(null, null, hostnameResolver, true, null);
SSHCertRecord sshCertRecord = new SSHCertRecord();
sshCertRecord.setService("athenz.examples.httpd");
SSHCertRequest sshCertRequest = new SSHCertRequest();
sshCertRequest.setCertRequestData(new SSHCertRequestData().setPrincipals(Collections.singletonList("host1.athenz.cloud")));
sshCertRequest.setCertRequestMeta(new SSHCertRequestMeta());
assertTrue(instanceManager.validPrincipals(hostname, sshCertRecord, sshCertRequest));
instanceManager.shutdown();
}
use of com.yahoo.athenz.common.server.ssh.SSHCertRecord in project athenz by yahoo.
the class InstanceCertManagerTest method testValidPrincipalsNoXPrincipals.
@Test
public void testValidPrincipalsNoXPrincipals() throws IOException {
InstanceCertManager instanceManager = new InstanceCertManager(null, null, null, true, null);
SSHCertRecord sshCertRecord = new SSHCertRecord();
sshCertRecord.setService("athenz.examples.httpd");
String sshCsr = "{\"pubkey\":\"key\",\"certtype\":\"host\"}";
ObjectMapper objectMapper = new ObjectMapper();
boolean result = instanceManager.validPrincipals("host1.athenz.cloud", sshCertRecord, objectMapper.readValue(sshCsr, SshHostCsr.class));
assertTrue(result);
result = instanceManager.validPrincipals("host1.athenz.cloud", sshCertRecord, objectMapper.readValue("{}", SshHostCsr.class));
assertTrue(result);
instanceManager.shutdown();
}
Aggregations