use of com.yahoo.athenz.common.server.dns.HostnameResolver in project athenz by yahoo.
the class SecureBootProviderTest method testRefreshInstance.
@Test
public void testRefreshInstance() {
System.setProperty(SecureBootProvider.ZTS_PROP_SB_ATTR_VALIDATOR_FACTORY_CLASS, "com.yahoo.athenz.instance.provider.impl.MockAttrValidatorFactory");
HostnameResolver hostnameResolver = Mockito.mock(HostnameResolver.class);
Mockito.when(hostnameResolver.getAllByName("athenz-examples1.abc.com")).thenReturn(new HashSet<>(Arrays.asList("10.1.1.1", "2001:db8:a0b:12f0:0:0:0:1")));
SecureBootProvider provider = new SecureBootProvider();
provider.initialize("sys.auth.sb-provider", "com.yahoo.athenz.instance.provider.impl.SecureBootProvider", null, null);
provider.setHostnameResolver(hostnameResolver);
InstanceConfirmation confirmation = new InstanceConfirmation();
confirmation.setAttestationData("sample attestation data");
confirmation.setDomain("sports");
confirmation.setService("api");
confirmation.setProvider("sys.auth.sb-provider");
Map<String, String> attributes = new HashMap<>();
attributes.put(InstanceProvider.ZTS_INSTANCE_SAN_DNS, "api.sports.zts.athenz.cloud,inst1.instanceid.athenz.zts.athenz.cloud");
attributes.put(InstanceProvider.ZTS_INSTANCE_HOSTNAME, "athenz-examples1.abc.com");
attributes.put(InstanceProvider.ZTS_INSTANCE_CERT_HOSTNAME, "athenz-examples1.abc.com");
confirmation.setAttributes(attributes);
assertNotNull(provider.refreshInstance(confirmation));
provider.close();
System.clearProperty(SecureBootProvider.ZTS_PROP_SB_ATTR_VALIDATOR_FACTORY_CLASS);
}
use of com.yahoo.athenz.common.server.dns.HostnameResolver in project athenz by yahoo.
the class InstanceProviderManagerTest method testGetClassInstance.
@Test
public void testGetClassInstance() {
HostnameResolver hostnameResolver = new HostnameResolver() {
};
InstanceProviderManager providerManager = new InstanceProviderManager(null, null, null, null, null);
InstanceProvider provider = providerManager.getClassProvider("unknown.class", "provider", hostnameResolver);
assertNull(provider);
provider = providerManager.getClassProvider("com.yahoo.athenz.instance.provider.impl.InstanceAWSProvider", "provider", hostnameResolver);
assertNotNull(provider);
provider = providerManager.getClassProvider("com.yahoo.athenz.instance.provider.impl.InstanceAWSECSProvider", "provider", hostnameResolver);
assertNotNull(provider);
provider = providerManager.getClassProvider("com.yahoo.athenz.instance.provider.impl.InstanceAWSLambdaProvider", "provider", hostnameResolver);
assertNotNull(provider);
// we should get this from the cache now
provider = providerManager.getClassProvider("com.yahoo.athenz.instance.provider.impl.InstanceAWSProvider", "provider", hostnameResolver);
assertNotNull(provider);
// some invalid class name
provider = providerManager.getClassProvider("com.yahoo.athenz.unknown.class", "provider", hostnameResolver);
assertNull(provider);
try {
providerManager.getClassProvider("com.yahoo.athenz.zts.ZTSConsts", "provider", hostnameResolver);
fail();
} catch (Exception ignored) {
}
}
use of com.yahoo.athenz.common.server.dns.HostnameResolver in project athenz by yahoo.
the class InstanceProviderManagerTest method testGetClassProviderForZTS.
@Test
public void testGetClassProviderForZTS() {
SignedDomain signedDomain = createSignedDomainClassEndpoint("sys.auth", "zts", true, true);
store.processSignedDomain(signedDomain, false);
PrivateKey privateKey = Mockito.mock(PrivateKey.class);
ServerPrivateKey serverPrivateKey = new ServerPrivateKey(privateKey, "0");
InstanceProviderManager provider = new InstanceProviderManager(store, null, null, serverPrivateKey, null);
InstanceProvider client = provider.getProvider("sys.auth.zts", new HostnameResolver() {
});
assertNotNull(client);
client.close();
}
use of com.yahoo.athenz.common.server.dns.HostnameResolver in project athenz by yahoo.
the class InstanceProviderManagerTest method testGetClassProviderException.
@Test
public void testGetClassProviderException() {
SignedDomain signedDomain = createSignedDomainClassEndpoint("coretech", "weather", true, true);
store.processSignedDomain(signedDomain, false);
System.setProperty("athenz.instance.test.class.exception", "true");
InstanceProviderManager provider = new InstanceProviderManager(store, null, null, null, null);
InstanceProvider client = provider.getProvider("coretech.weather", new HostnameResolver() {
});
assertNull(client);
System.clearProperty("athenz.instance.test.class.exception");
}
use of com.yahoo.athenz.common.server.dns.HostnameResolver in project athenz by yahoo.
the class ZTSImplTest method testPostInstanceRegisterInformationInvalidHostname.
@Test
public void testPostInstanceRegisterInformationInvalidHostname() throws IOException {
ChangeLogStore structStore = new ZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", privateKey, "0");
DataStore store = new DataStore(structStore, null, ztsMetric);
ZTSImpl ztsImpl = new ZTSImpl(mockCloudStore, store);
SignedDomain providerDomain = signedAuthorizedProviderDomain();
store.processSignedDomain(providerDomain, false);
SignedDomain tenantDomain = signedBootstrapTenantDomain("athenz.provider", "athenz", "production");
store.processSignedDomain(tenantDomain, false);
Path path = Paths.get("src/test/resources/athenz.instanceid.csr");
String certCsr = new String(Files.readAllBytes(path));
InstanceProviderManager instanceProviderManager = Mockito.mock(InstanceProviderManager.class);
InstanceProvider providerClient = Mockito.mock(InstanceProvider.class);
Mockito.when(providerClient.getProviderScheme()).thenReturn(InstanceProvider.Scheme.CLASS);
Map<String, String> attrs = new HashMap<>();
attrs.put("certSSH", "true");
InstanceConfirmation confirmation = new InstanceConfirmation().setDomain("athenz").setService("production").setProvider("athenz.provider").setAttributes(attrs);
HostnameResolver resolver = Mockito.mock(HostnameResolver.class);
Mockito.when(resolver.isValidHostname("host1.athenz.cloud")).thenReturn(false);
InstanceCertManager instanceManager = Mockito.spy(ztsImpl.instanceCertManager);
Mockito.when(instanceProviderManager.getProvider("athenz.provider", resolver)).thenReturn(providerClient);
Mockito.when(providerClient.confirmInstance(Mockito.any())).thenReturn(confirmation);
Mockito.when(instanceManager.insertX509CertRecord(Mockito.any())).thenReturn(true);
path = Paths.get("src/test/resources/athenz.instanceid.pem");
String pem = new String(Files.readAllBytes(path));
InstanceIdentity identity = new InstanceIdentity().setName("athenz.production").setX509Certificate(pem);
Mockito.doReturn(identity).when(instanceManager).generateIdentity(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.anyInt(), Mockito.any());
ztsImpl.instanceProviderManager = instanceProviderManager;
ztsImpl.instanceCertManager = instanceManager;
ztsImpl.hostnameResolver = resolver;
InstanceRegisterInformation info = new InstanceRegisterInformation().setAttestationData("attestationData").setCsr(certCsr).setDomain("athenz").setService("production").setProvider("athenz.provider").setToken(true).setHostname("unknown.host.athenz.cloud");
ResourceContext context = createResourceContext(null);
try {
ztsImpl.postInstanceRegisterInformation(context, info);
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), ResourceException.BAD_REQUEST);
}
}
Aggregations