use of com.yahoo.athenz.auth.impl.SimplePrincipal in project athenz by yahoo.
the class DBServiceTest method zmsInit.
private ZMSImpl zmsInit() {
// we want to make sure we start we clean dir structure
FileConnection.deleteDirectory(new File(ZMS_DATA_STORE_PATH));
FileConnection.deleteDirectory(new File(ZMS_DATA_QUOTA_PATH));
Authority principalAuthority = new com.yahoo.athenz.common.server.debug.DebugPrincipalAuthority();
rsrcPrince = SimplePrincipal.create("user", "user1", "v=U1;d=user;n=user1;s=signature", 0, principalAuthority);
((SimplePrincipal) rsrcPrince).setUnsignedCreds("v=U1;d=user;n=user1");
Mockito.when(mockDomRestRsrcCtx.request()).thenReturn(mockServletRequest);
Mockito.when(mockDomRestRsrcCtx.principal()).thenReturn(rsrcPrince);
Mockito.when(mockDomRsrcCtx.context()).thenReturn(mockDomRestRsrcCtx);
Mockito.when(mockDomRsrcCtx.request()).thenReturn(mockServletRequest);
Mockito.when(mockDomRsrcCtx.principal()).thenReturn(rsrcPrince);
adminUser = System.getProperty(ZMSConsts.ZMS_PROP_DOMAIN_ADMIN);
// enable product id support
System.setProperty(ZMSConsts.ZMS_PROP_PRODUCT_ID_SUPPORT, "true");
System.setProperty(ZMSConsts.ZMS_PROP_SOLUTION_TEMPLATE_FNAME, "src/test/resources/solution_templates.json");
System.setProperty(ZMSConsts.ZMS_PROP_FILE_STORE_PATH, "/tmp/zms_core_unit_tests/");
System.clearProperty(ZMSConsts.ZMS_PROP_JDBC_RW_STORE);
System.clearProperty(ZMSConsts.ZMS_PROP_JDBC_RO_STORE);
ZMSImpl zmsObj = new ZMSImpl();
return zmsObj;
}
use of com.yahoo.athenz.auth.impl.SimplePrincipal in project athenz by yahoo.
the class ZTSImplTest method testValidateServiceX509RefreshRequestNotAllowedIP.
@Test
public void testValidateServiceX509RefreshRequestNotAllowedIP() 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 csr = new String(Files.readAllBytes(path));
X509CertRequest certReq = new X509CertRequest(csr);
assertNotNull(certReq);
path = Paths.get("src/test/resources/valid_provider_refresh.pem");
String pem = new String(Files.readAllBytes(path));
X509Certificate cert = Crypto.loadX509Certificate(pem);
SimplePrincipal principal = (SimplePrincipal) SimplePrincipal.create("athenz", "syncer", "v=S1,d=athenz;n=syncer;s=sig", 0, new CertificateAuthority());
principal.setX509Certificate(cert);
// our ip will not match 10.0.0.1 thus failure
assertTrue(ztsImpl.validateServiceX509RefreshRequest(principal, certReq, "10.0.0.2") == ServiceX509RefreshRequestStatus.IP_NOT_ALLOWED);
}
use of com.yahoo.athenz.auth.impl.SimplePrincipal in project athenz by yahoo.
the class ZTSImplTest method testValidateServiceX509RefreshRequestMismatchDns.
@Test
public void testValidateServiceX509RefreshRequestMismatchDns() 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/athenz.mismatch.dns.csr");
String csr = new String(Files.readAllBytes(path));
X509CertRequest certReq = new X509CertRequest(csr);
assertNotNull(certReq);
path = Paths.get("src/test/resources/athenz.instanceid.pem");
String pem = new String(Files.readAllBytes(path));
X509Certificate cert = Crypto.loadX509Certificate(pem);
SimplePrincipal principal = (SimplePrincipal) SimplePrincipal.create("athenz", "syncer", "v=S1,d=athenz;n=syncer;s=sig", 0, new CertificateAuthority());
principal.setX509Certificate(cert);
assertTrue(ztsImpl.validateServiceX509RefreshRequest(principal, certReq, "10.0.0.1") == ServiceX509RefreshRequestStatus.DNS_NAME_MISMATCH);
}
use of com.yahoo.athenz.auth.impl.SimplePrincipal in project athenz by yahoo.
the class ZTSImplTest method testGetServiceIdentityListInvalidDomain.
@Test
public void testGetServiceIdentityListInvalidDomain() {
SignedDomain signedDomain = createSignedDomain("coretech", "weather", "storage", true);
store.processDomain(signedDomain, false);
SimplePrincipal principal = (SimplePrincipal) SimplePrincipal.create("hockey", "kings", "v=S1,d=hockey;n=kings;s=sig", 0, new PrincipalAuthority());
ResourceContext context = createResourceContext(principal);
try {
@SuppressWarnings("unused") com.yahoo.athenz.zts.ServiceIdentityList svcList = zts.getServiceIdentityList(context, "testDomain2");
fail();
} catch (ResourceException ex) {
assertTrue(true);
}
}
use of com.yahoo.athenz.auth.impl.SimplePrincipal in project athenz by yahoo.
the class ZTSImplTest method testPostInstanceRefreshInformationSSHFailure.
@Test
public void testPostInstanceRefreshInformationSSHFailure() 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);
SignedDomain providerDomain = signedAuthorizedProviderDomain();
store.processDomain(providerDomain, false);
SignedDomain tenantDomain = signedBootstrapTenantDomain("athenz.provider", "athenz", "production");
store.processDomain(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);
InstanceConfirmation confirmation = new InstanceConfirmation().setDomain("athenz").setService("production").setProvider("athenz.provider");
InstanceCertManager instanceManager = Mockito.spy(ztsImpl.instanceCertManager);
Mockito.when(instanceProviderManager.getProvider("athenz.provider")).thenReturn(providerClient);
Mockito.when(providerClient.refreshInstance(Mockito.any())).thenReturn(confirmation);
X509CertRecord certRecord = new X509CertRecord();
certRecord.setInstanceId("1001");
certRecord.setProvider("athenz.provider");
certRecord.setService("athenz.production");
certRecord.setCurrentSerial("16503746516960996918");
certRecord.setPrevSerial("16503746516960996918");
Mockito.when(instanceManager.getX509CertRecord("athenz.provider", "1001")).thenReturn(certRecord);
Mockito.when(instanceManager.updateX509CertRecord(Mockito.any())).thenReturn(true);
Mockito.when(instanceManager.generateSshIdentity(Mockito.any(), Mockito.eq("ssh-csr"), Mockito.eq("user"))).thenReturn(false);
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.anyInt());
ztsImpl.instanceProviderManager = instanceProviderManager;
ztsImpl.instanceCertManager = instanceManager;
InstanceRefreshInformation info = new InstanceRefreshInformation().setCsr(certCsr).setSsh("ssh-csr").setToken(true);
CertificateAuthority certAuthority = new CertificateAuthority();
SimplePrincipal principal = (SimplePrincipal) SimplePrincipal.create("athenz", "production", "v=S1;d=athenz;n=production;s=signature", 0, certAuthority);
X509Certificate cert = Crypto.loadX509Certificate(pem);
principal.setX509Certificate(cert);
ResourceContext context = createResourceContext(principal);
identity = ztsImpl.postInstanceRefreshInformation(context, "athenz.provider", "athenz", "production", "1001", info);
assertNull(identity.getSshCertificate());
}
Aggregations