use of com.yahoo.athenz.common.server.cert.CertSigner in project athenz by yahoo.
the class ZTSImplTest method testPostInstanceRefreshRequestByUserIdentityFailure.
@Test
public void testPostInstanceRefreshRequestByUserIdentityFailure() throws IOException {
ChangeLogStore structStore = new ZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", privateKey, "0");
DataStore store = new DataStore(structStore, null);
ZTSImpl ztsImpl = new ZTSImpl(mockCloudStore, store);
Path path = Paths.get("src/test/resources/valid_provider_refresh.csr");
String certCsr = new String(Files.readAllBytes(path));
InstanceRefreshRequest req = new InstanceRefreshRequest().setCsr(certCsr).setKeyId("v0");
SimplePrincipal principal = (SimplePrincipal) SimplePrincipal.create("user", "doe", "v=U1,d=user;n=doe;s=sig", 0, new PrincipalAuthority());
principal.setKeyId("0");
String publicKeyName = "athenz.syncer_v0";
final String ztsPublicKey = "-----BEGIN PUBLIC KEY-----\n" + "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAMp9ZHVDK2s/FyinpKpD7lSsU+d6TSRE\n" + "NVo6sdLrEpOaCJETsh+0Qc0knhALxBD1+B9gS5F2rAFgtug0R6savvMCAwEAAQ==\n" + "-----END PUBLIC KEY-----";
ztsImpl.dataStore.getPublicKeyCache().put(publicKeyName, ztsPublicKey);
ZTSAuthorizer authorizer = Mockito.mock(ZTSAuthorizer.class);
Mockito.when(authorizer.access("update", "athenz:service", principal, null)).thenReturn(true);
ztsImpl.authorizer = authorizer;
HttpServletRequest servletRequest = Mockito.mock(HttpServletRequest.class);
Mockito.when(servletRequest.isSecure()).thenReturn(true);
ResourceContext context = createResourceContext(principal, servletRequest);
CertSigner certSigner = Mockito.mock(CertSigner.class);
Mockito.when(certSigner.generateX509Certificate(Mockito.anyString(), Mockito.anyString(), Mockito.anyInt())).thenReturn(null);
ztsImpl.certSigner = certSigner;
try {
ztsImpl.postInstanceRefreshRequest(context, "athenz", "syncer", req);
fail();
} catch (Exception ex) {
assertTrue(ex.getMessage().contains("Unable to generate identity"), ex.getMessage());
}
}
use of com.yahoo.athenz.common.server.cert.CertSigner in project athenz by yahoo.
the class InstanceCertManagerTest method testGenerateIdentity.
@Test
public void testGenerateIdentity() {
final String cert = "cert";
final String caCert = "caCert";
CertSigner certSigner = Mockito.mock(com.yahoo.athenz.common.server.cert.CertSigner.class);
Mockito.when(certSigner.generateX509Certificate(Mockito.<String>any(), Mockito.any(), Mockito.anyInt())).thenReturn(cert);
Mockito.when(certSigner.getCACertificate()).thenReturn(caCert);
InstanceCertManager instanceManager = new InstanceCertManager(null, certSigner);
InstanceIdentity identity = instanceManager.generateIdentity("csr", "cn", null, 0);
assertNotNull(identity);
assertEquals(identity.getName(), "cn");
assertEquals(identity.getX509Certificate(), cert);
assertEquals(identity.getX509CertificateSigner(), caCert);
}
use of com.yahoo.athenz.common.server.cert.CertSigner 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");
}
use of com.yahoo.athenz.common.server.cert.CertSigner 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);
}
use of com.yahoo.athenz.common.server.cert.CertSigner 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);
}
Aggregations