Search in sources :

Example 6 with InstanceIdentity

use of com.yahoo.athenz.zts.InstanceIdentity in project athenz by yahoo.

the class InstanceCertManagerTest method testGenerateSshIdentity.

@Test
public void testGenerateSshIdentity() {
    String sshCsr = "{\"csr\":\"csr\",\"certtype\":\"host\"}";
    CertSigner certSigner = Mockito.mock(com.yahoo.athenz.common.server.cert.CertSigner.class);
    Mockito.when(certSigner.generateSSHCertificate(sshCsr)).thenReturn("ssh-cert");
    Mockito.when(certSigner.getSSHCertificate(ZTSConsts.ZTS_SSH_HOST)).thenReturn("ssh-host");
    Mockito.when(certSigner.getSSHCertificate(ZTSConsts.ZTS_SSH_USER)).thenReturn("ssh-user");
    InstanceCertManager instanceManager = new InstanceCertManager(null, certSigner);
    InstanceIdentity identity = new InstanceIdentity().setName("athenz.service");
    boolean result = instanceManager.generateSshIdentity(identity, sshCsr, "host");
    assertTrue(result);
    assertEquals(identity.getSshCertificate(), "ssh-cert");
    assertEquals(identity.getSshCertificateSigner(), "ssh-host");
}
Also used : CertSigner(com.yahoo.athenz.common.server.cert.CertSigner) InstanceIdentity(com.yahoo.athenz.zts.InstanceIdentity) Test(org.testng.annotations.Test)

Example 7 with InstanceIdentity

use of com.yahoo.athenz.zts.InstanceIdentity in project athenz by yahoo.

the class InstanceCertManagerTest method testGenerateSshIdentityNullCertError.

@Test
public void testGenerateSshIdentityNullCertError() {
    String sshCsr = "{\"csr\":\"csr\",\"certtype\":\"host\"}";
    CertSigner certSigner = Mockito.mock(com.yahoo.athenz.common.server.cert.CertSigner.class);
    Mockito.when(certSigner.generateSSHCertificate(sshCsr)).thenReturn(null);
    Mockito.when(certSigner.getSSHCertificate(ZTSConsts.ZTS_SSH_HOST)).thenReturn("ssh-host");
    Mockito.when(certSigner.getSSHCertificate(ZTSConsts.ZTS_SSH_USER)).thenReturn("ssh-user");
    InstanceCertManager instanceManager = new InstanceCertManager(null, certSigner);
    InstanceIdentity identity = new InstanceIdentity().setName("athenz.service");
    boolean result = instanceManager.generateSshIdentity(identity, sshCsr, "host");
    assertFalse(result);
}
Also used : CertSigner(com.yahoo.athenz.common.server.cert.CertSigner) InstanceIdentity(com.yahoo.athenz.zts.InstanceIdentity) Test(org.testng.annotations.Test)

Example 8 with InstanceIdentity

use of com.yahoo.athenz.zts.InstanceIdentity in project athenz by yahoo.

the class InstanceCertManagerTest method testGenerateIdentityEmptyCert.

@Test
public void testGenerateIdentityEmptyCert() {
    CertSigner certSigner = Mockito.mock(com.yahoo.athenz.common.server.cert.CertSigner.class);
    Mockito.when(certSigner.generateX509Certificate(Mockito.<String>any(), Mockito.any(), Mockito.anyInt())).thenReturn("");
    InstanceCertManager instanceManager = new InstanceCertManager(null, certSigner);
    InstanceIdentity identity = instanceManager.generateIdentity("csr", "cn", null, 0);
    assertNull(identity);
}
Also used : CertSigner(com.yahoo.athenz.common.server.cert.CertSigner) InstanceIdentity(com.yahoo.athenz.zts.InstanceIdentity) Test(org.testng.annotations.Test)

Example 9 with InstanceIdentity

use of com.yahoo.athenz.zts.InstanceIdentity in project athenz by yahoo.

the class InstanceCertManagerTest method testGenerateSshIdentityInvalidSsh.

@Test
public void testGenerateSshIdentityInvalidSsh() {
    InstanceIdentity identity = new InstanceIdentity().setName("athenz.service");
    InstanceCertManager instanceManager = new InstanceCertManager(null, null);
    boolean result = instanceManager.generateSshIdentity(identity, "{\"csr\":\"csr\"}", null);
    assertFalse(result);
}
Also used : InstanceIdentity(com.yahoo.athenz.zts.InstanceIdentity) Test(org.testng.annotations.Test)

Example 10 with InstanceIdentity

use of com.yahoo.athenz.zts.InstanceIdentity in project athenz by yahoo.

the class InstanceCertManagerTest method testGenerateIdentityNullCert.

@Test
public void testGenerateIdentityNullCert() {
    CertSigner certSigner = Mockito.mock(com.yahoo.athenz.common.server.cert.CertSigner.class);
    Mockito.when(certSigner.generateX509Certificate(Mockito.<String>any(), Mockito.any(), Mockito.anyInt())).thenReturn(null);
    InstanceCertManager instanceManager = new InstanceCertManager(null, certSigner);
    InstanceIdentity identity = instanceManager.generateIdentity("csr", "cn", null, 0);
    assertNull(identity);
}
Also used : CertSigner(com.yahoo.athenz.common.server.cert.CertSigner) InstanceIdentity(com.yahoo.athenz.zts.InstanceIdentity) Test(org.testng.annotations.Test)

Aggregations

InstanceIdentity (com.yahoo.athenz.zts.InstanceIdentity)10 Test (org.testng.annotations.Test)8 CertSigner (com.yahoo.athenz.common.server.cert.CertSigner)6 ZTSClient (com.yahoo.athenz.zts.ZTSClient)2 ZTSClientException (com.yahoo.athenz.zts.ZTSClientException)2 File (java.io.File)2 PrivateKey (java.security.PrivateKey)2 CommandLine (org.apache.commons.cli.CommandLine)2 DERIA5String (org.bouncycastle.asn1.DERIA5String)2 InstanceRefreshInformation (com.yahoo.athenz.zts.InstanceRefreshInformation)1 InstanceRegisterInformation (com.yahoo.athenz.zts.InstanceRegisterInformation)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1