use of com.yahoo.athenz.common.server.dns.HostnameResolver in project athenz by yahoo.
the class InstanceProviderManagerTest method testGetClassProvider.
@Test
public void testGetClassProvider() {
SignedDomain signedDomain = createSignedDomainClassEndpoint("coretech", "weather", true, true);
store.processSignedDomain(signedDomain, false);
InstanceProviderManager provider = new InstanceProviderManager(store, null, null, null, null);
InstanceProvider client = provider.getProvider("coretech.weather", new HostnameResolver() {
});
assertNotNull(client);
client.close();
}
use of com.yahoo.athenz.common.server.dns.HostnameResolver in project athenz by yahoo.
the class InstanceCertManagerTest method testValidPrincipalsHostnameAlone.
@Test
public void testValidPrincipalsHostnameAlone() {
String hostname = "host1.athenz.cloud";
SshHostCsr sshHostCsr = new SshHostCsr();
sshHostCsr.setXPrincipals(new String[] { hostname });
sshHostCsr.setPrincipals(new String[] { "service.domain.athenz.cloud", hostname });
SSHCertRecord sshCertRecord = new SSHCertRecord();
sshCertRecord.setService("athenz.examples.httpd");
HostnameResolver hostnameResolver = Mockito.mock(HostnameResolver.class);
when(hostnameResolver.isValidHostname(hostname)).thenReturn(true);
InstanceCertManager instanceManager = new InstanceCertManager(null, null, hostnameResolver, true, null);
boolean result = instanceManager.validPrincipals(hostname, sshCertRecord, sshHostCsr);
assertTrue(result);
instanceManager.shutdown();
}
use of com.yahoo.athenz.common.server.dns.HostnameResolver in project athenz by yahoo.
the class InstanceCertManagerTest method testGenerateSshIdentityValidPrincipals.
@Test
public void testGenerateSshIdentityValidPrincipals() throws IOException {
Path path = Paths.get("src/test/resources/sshhost_valid_sample.csr");
String sshCsr = new String(Files.readAllBytes(path));
SSHSigner sshSigner = Mockito.mock(com.yahoo.athenz.common.server.ssh.SSHSigner.class);
SSHCertRequest sshRequest = new SSHCertRequest();
sshRequest.setCsr(sshCsr);
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);
boolean result = instanceManager.generateSSHIdentity(null, identity, hostname, sshCsr, null, sshCertRecord, "host");
assertTrue(result);
assertEquals(identity.getSshCertificate(), "ssh-cert");
assertEquals(identity.getSshCertificateSigner(), "ssh-host");
instanceManager.shutdown();
}
use of com.yahoo.athenz.common.server.dns.HostnameResolver in project athenz by yahoo.
the class InstanceCertManagerTest method testGenerateSshIdentityInalidPrincipals.
@Test
public void testGenerateSshIdentityInalidPrincipals() throws IOException {
Path path = Paths.get("src/test/resources/sshhost_valid_sample.csr");
String sshCsr = new String(Files.readAllBytes(path));
SSHSigner sshSigner = Mockito.mock(com.yahoo.athenz.common.server.ssh.SSHSigner.class);
SSHCertRequest sshRequest = new SSHCertRequest();
sshRequest.setCsr(sshCsr);
SSHCertificates certs = new SSHCertificates();
SSHCertificate cert = new SSHCertificate();
cert.setCertificate("ssh-cert");
InstanceIdentity identity = new InstanceIdentity().setName("athenz.service");
final SSHCertificates sshCertificates = certs.setCertificates(Collections.singletonList(cert));
when(sshSigner.generateCertificate(null, sshRequest, null, "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");
SSHCertRecord sshCertRecord = new SSHCertRecord();
sshCertRecord.setService("athenz.examples.httpd");
HostnameResolver hostnameResolver = Mockito.mock(HostnameResolver.class);
when(hostnameResolver.isValidHostCnameList(sshCertRecord.getService(), hostname, cnames, CertType.SSH_HOST)).thenReturn(false);
when(hostnameResolver.isValidHostname(hostname)).thenReturn(true);
InstanceCertManager instanceManager = new InstanceCertManager(null, null, hostnameResolver, true, null);
instanceManager.setSSHSigner(sshSigner);
boolean result = instanceManager.generateSSHIdentity(null, identity, hostname, sshCsr, null, new SSHCertRecord(), "host");
assertFalse(result);
instanceManager.shutdown();
}
use of com.yahoo.athenz.common.server.dns.HostnameResolver in project athenz by yahoo.
the class InstanceCertManagerTest method testValidPrincipalsSSHRequestNulls.
@Test
public void testValidPrincipalsSSHRequestNulls() {
final String hostname = "host1.athenz.cloud";
HostnameResolver hostnameResolver = Mockito.mock(HostnameResolver.class);
InstanceCertManager instanceManager = new InstanceCertManager(null, null, hostnameResolver, true, null);
SSHCertRecord sshCertRecord = new SSHCertRecord();
sshCertRecord.setService("athenz.examples.httpd");
SSHCertRequest sshCertRequest = new SSHCertRequest();
assertFalse(instanceManager.validPrincipals(hostname, sshCertRecord, sshCertRequest));
sshCertRequest.setCertRequestData(new SSHCertRequestData());
sshCertRequest.setCertRequestMeta(null);
assertFalse(instanceManager.validPrincipals(hostname, sshCertRecord, sshCertRequest));
sshCertRequest.setCertRequestData(null);
sshCertRequest.setCertRequestMeta(new SSHCertRequestMeta());
assertFalse(instanceManager.validPrincipals(hostname, sshCertRecord, sshCertRequest));
// null principals returns true
sshCertRequest.setCertRequestData(new SSHCertRequestData());
sshCertRequest.setCertRequestMeta(new SSHCertRequestMeta());
assertTrue(instanceManager.validPrincipals(hostname, sshCertRecord, sshCertRequest));
instanceManager.shutdown();
}
Aggregations