Search in sources :

Example 11 with SSHSigner

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

Example 12 with SSHSigner

use of com.yahoo.athenz.common.server.ssh.SSHSigner in project athenz by yahoo.

the class InstanceCertManagerTest method testGetSSHCertificateSigner.

@Test
public void testGetSSHCertificateSigner() {
    SSHSigner sshSigner = Mockito.mock(com.yahoo.athenz.common.server.ssh.SSHSigner.class);
    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);
    assertEquals(instanceManager.getSSHCertificateSigner("host"), "ssh-host");
    assertEquals(instanceManager.getSSHCertificateSigner("user"), "ssh-user");
    // second time we should not fetch from certsigner and use fetched copies
    when(sshSigner.getSignerCertificate(ZTSConsts.ZTS_SSH_HOST)).thenReturn(null);
    when(sshSigner.getSignerCertificate(ZTSConsts.ZTS_SSH_USER)).thenReturn(null);
    assertEquals(instanceManager.getSSHCertificateSigner("host"), "ssh-host");
    assertEquals(instanceManager.getSSHCertificateSigner("user"), "ssh-user");
    instanceManager.shutdown();
}
Also used : SSHSigner(com.yahoo.athenz.common.server.ssh.SSHSigner) Test(org.testng.annotations.Test)

Example 13 with SSHSigner

use of com.yahoo.athenz.common.server.ssh.SSHSigner in project athenz by yahoo.

the class InstanceCertManagerTest method testGenerateSshIdentityCertRequestValidPrincipals.

@Test
public void testGenerateSshIdentityCertRequestValidPrincipals() {
    SSHSigner sshSigner = Mockito.mock(com.yahoo.athenz.common.server.ssh.SSHSigner.class);
    SSHCertRequest sshRequest = new SSHCertRequest();
    sshRequest.setCertRequestData(new SSHCertRequestData().setPrincipals(Arrays.asList("host1.athenz.cloud", "cname.athenz.info", "vip.athenz.info", "10.1.2.3")).setPublicKey("sample public key"));
    sshRequest.setCertRequestMeta(new SSHCertRequestMeta().setKeyIdPrincipals(Arrays.asList("service.domain.athenz.cloud", "host1.athenz.cloud", "cname.athenz.info", "vip.athenz.info", "10.1.2.3")).setCertType("host").setTransId("123456").setOrigin("10.1.2.3"));
    SSHCertificates certs = new SSHCertificates();
    SSHCertificate cert = new SSHCertificate();
    cert.setCertificate("ssh-cert");
    SSHCertRecord sshCertRecord = new SSHCertRecord();
    sshCertRecord.setPrincipals("127.0.0.1");
    sshCertRecord.setService("athenz.service");
    InstanceIdentity identity = new InstanceIdentity().setName("athenz.service");
    final SSHCertificates sshCertificates = certs.setCertificates(Collections.singletonList(cert));
    when(sshSigner.generateCertificate(null, sshRequest, sshCertRecord, "host")).thenReturn(sshCertificates);
    when(sshSigner.getSignerCertificate(ZTSConsts.ZTS_SSH_HOST)).thenReturn("ssh-host");
    // setup the hostname resolver for our request
    String hostname = "host1.athenz.cloud";
    List<String> cnames = new ArrayList<>();
    cnames.add("cname.athenz.info");
    cnames.add("vip.athenz.info");
    HostnameResolver hostnameResolver = Mockito.mock(HostnameResolver.class);
    when(hostnameResolver.isValidHostCnameList(sshCertRecord.getService(), hostname, cnames, CertType.SSH_HOST)).thenReturn(true);
    when(hostnameResolver.isValidHostname(hostname)).thenReturn(true);
    InstanceCertManager instanceManager = new InstanceCertManager(null, null, hostnameResolver, true, null);
    instanceManager.setSSHSigner(sshSigner);
    assertTrue(instanceManager.generateSSHIdentity(null, identity, hostname, null, sshRequest, sshCertRecord, "host"));
    assertEquals(identity.getSshCertificate(), "ssh-cert");
    assertEquals(identity.getSshCertificateSigner(), "ssh-host");
    instanceManager.shutdown();
}
Also used : HostnameResolver(com.yahoo.athenz.common.server.dns.HostnameResolver) SSHSigner(com.yahoo.athenz.common.server.ssh.SSHSigner) SSHCertRecord(com.yahoo.athenz.common.server.ssh.SSHCertRecord) Test(org.testng.annotations.Test)

Example 14 with SSHSigner

use of com.yahoo.athenz.common.server.ssh.SSHSigner in project athenz by yahoo.

the class InstanceCertManagerTest method testGetSSHCertificates.

@Test
public void testGetSSHCertificates() {
    InstanceCertManager instanceCertManager = new InstanceCertManager(null, null, null, true, null);
    instanceCertManager.setSSHSigner(null);
    assertNull(instanceCertManager.generateSSHCertificates(null, null));
    SSHSigner signer = Mockito.mock(SSHSigner.class);
    Principal principal = Mockito.mock(Principal.class);
    SSHCertRequest certRequest = new SSHCertRequest();
    certRequest.setCertRequestMeta(new SSHCertRequestMeta());
    SSHCertificates certs = new SSHCertificates();
    when(signer.generateCertificate(principal, certRequest, null, null)).thenReturn(certs);
    instanceCertManager.setSSHSigner(signer);
    assertEquals(certs, instanceCertManager.generateSSHCertificates(principal, certRequest));
    instanceCertManager.shutdown();
}
Also used : SSHSigner(com.yahoo.athenz.common.server.ssh.SSHSigner) Principal(com.yahoo.athenz.auth.Principal) Test(org.testng.annotations.Test)

Example 15 with SSHSigner

use of com.yahoo.athenz.common.server.ssh.SSHSigner in project athenz by yahoo.

the class InstanceCertManagerTest method testGenerateSshIdentityInvalidSsh.

@Test
public void testGenerateSshIdentityInvalidSsh() {
    InstanceIdentity identity = new InstanceIdentity().setName("athenz.service");
    SSHSigner sshSigner = Mockito.mock(com.yahoo.athenz.common.server.ssh.SSHSigner.class);
    InstanceCertManager instanceManager = new InstanceCertManager(null, null, null, true, null);
    instanceManager.setSSHSigner(sshSigner);
    boolean result = instanceManager.generateSSHIdentity(null, identity, "host.athenz.com", "{\"csr\":\"csr\"}", null, new SSHCertRecord(), ZTSConsts.ZTS_SSH_HOST);
    assertFalse(result);
}
Also used : SSHSigner(com.yahoo.athenz.common.server.ssh.SSHSigner) SSHCertRecord(com.yahoo.athenz.common.server.ssh.SSHCertRecord) Test(org.testng.annotations.Test)

Aggregations

SSHSigner (com.yahoo.athenz.common.server.ssh.SSHSigner)18 Test (org.testng.annotations.Test)18 SSHCertRecord (com.yahoo.athenz.common.server.ssh.SSHCertRecord)14 HostnameResolver (com.yahoo.athenz.common.server.dns.HostnameResolver)6 Principal (com.yahoo.athenz.auth.Principal)2 Path (java.nio.file.Path)2