use of com.yahoo.athenz.common.server.dns.HostnameResolver in project athenz by yahoo.
the class InstanceCertManagerTest method testGenerateSshIdentityCertRequestInValidPrincipals.
@Test
public void testGenerateSshIdentityCertRequestInValidPrincipals() {
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(false);
when(hostnameResolver.isValidHostname(hostname)).thenReturn(true);
InstanceCertManager instanceManager = new InstanceCertManager(null, null, hostnameResolver, true, null);
instanceManager.setSSHSigner(sshSigner);
assertFalse(instanceManager.generateSSHIdentity(null, identity, hostname, null, sshRequest, sshCertRecord, "host"));
instanceManager.shutdown();
}
use of com.yahoo.athenz.common.server.dns.HostnameResolver in project athenz by yahoo.
the class InstanceCertManagerTest method testValidPrincipalsIpAlone.
@Test
public void testValidPrincipalsIpAlone() {
String hostname = "host1.athenz.cloud";
SshHostCsr sshHostCsr = new SshHostCsr();
sshHostCsr.setXPrincipals(new String[] { "10.1.2.3" });
sshHostCsr.setPrincipals(new String[] { "service.domain.athenz.cloud", "10.1.2.3" });
SSHCertRecord sshCertRecord = new SSHCertRecord();
sshCertRecord.setService("athenz.examples.httpd");
HostnameResolver hostnameResolver = Mockito.mock(HostnameResolver.class);
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 testValidPrincipalsBadCsr.
@Test
public void testValidPrincipalsBadCsr() {
// 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);
SSHSigner signer = Mockito.mock(SSHSigner.class);
instanceManager.setSSHSigner(signer);
String sshCsr = "{\"pubkey\":\"key\",\"certtype\":\"host\"";
InstanceIdentity identity = new InstanceIdentity().setName("athenz.test");
boolean result = instanceManager.generateSSHIdentity(null, identity, hostname, sshCsr, null, new SSHCertRecord(), ZTSConsts.ZTS_SSH_HOST);
assertFalse(result);
}
use of com.yahoo.athenz.common.server.dns.HostnameResolver in project athenz by yahoo.
the class X509CertRequestTest method testValidateDnsNamesWithCnameValues.
@Test
public void testValidateDnsNamesWithCnameValues() throws IOException {
Path path = Paths.get("src/test/resources/athenz.instanceid.cname.csr");
String csr = new String(Files.readAllBytes(path));
String service = "athenz.production";
X509CertRequest certReq = new X509CertRequest(csr);
assertNotNull(certReq);
DataCache athenzSysDomainCache = Mockito.mock(DataCache.class);
Mockito.when(athenzSysDomainCache.getProviderDnsSuffixList("provider")).thenReturn(Collections.singletonList("ostk.athenz.cloud"));
List<String> allowedSuffixList = new ArrayList<>();
allowedSuffixList.add("athenz.info");
allowedSuffixList.add("athenz.cloud");
Mockito.when(athenzSysDomainCache.getProviderHostnameAllowedSuffixList("provider")).thenReturn(allowedSuffixList);
Mockito.when(athenzSysDomainCache.getProviderHostnameDeniedSuffixList("provider")).thenReturn(null);
List<String> cnameList = new ArrayList<>();
cnameList.add("cname1.athenz.info");
cnameList.add("cname2.athenz.info");
HostnameResolver resolver = Mockito.mock(HostnameResolver.class);
Mockito.when(resolver.isValidHostCnameList(service, "host1.athenz.cloud", cnameList, CertType.X509)).thenReturn(false).thenReturn(true);
Mockito.when(resolver.isValidHostname("host1.athenz.cloud")).thenReturn(true);
// first call we're going to get failure
assertFalse(certReq.validateDnsNames("athenz", "production", "provider", athenzSysDomainCache, "ostk.athenz.cloud", "host1.athenz.cloud", cnameList, resolver));
// second call is success
assertTrue(certReq.validateDnsNames("athenz", "production", "provider", athenzSysDomainCache, "ostk.athenz.cloud", "host1.athenz.cloud", cnameList, resolver));
}
use of com.yahoo.athenz.common.server.dns.HostnameResolver 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();
}
Aggregations