use of com.yahoo.athenz.zts.store.DataStore in project athenz by yahoo.
the class ZTSImplTest method testPostInstanceRefreshInformationNoProviderClient.
@Test
public void testPostInstanceRefreshInformationNoProviderClient() 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(null);
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(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);
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);
try {
ztsImpl.postInstanceRefreshInformation(context, "athenz.provider", "athenz", "production", "1001", info);
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 400, ex.getMessage());
assertTrue(ex.getMessage().contains("unable to get instance for provider"));
}
}
use of com.yahoo.athenz.zts.store.DataStore in project athenz by yahoo.
the class ZTSImplTest method testGetRoleTokenAddrLoopbackNoXFFAuditLog.
@Test
public void testGetRoleTokenAddrLoopbackNoXFFAuditLog() {
HttpServletRequest servletRequest = Mockito.mock(HttpServletRequest.class);
Mockito.when(servletRequest.getRemoteAddr()).thenReturn("127.0.0.1");
Mockito.when(servletRequest.isSecure()).thenReturn(true);
final java.util.Set<String> aLogMsgs = new java.util.HashSet<String>();
AuditLogger alogger = new AuditLogger() {
public void log(String logMsg, String msgVersionTag) {
aLogMsgs.add(logMsg);
}
public void log(AuditLogMsgBuilder msgBldr) {
String msg = msgBldr.build();
aLogMsgs.add(msg);
}
@Override
public AuditLogMsgBuilder getMsgBuilder() {
return new DefaultAuditLogMsgBuilder();
}
};
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);
ZTSImpl.serverHostName = "localhost";
ztsImpl.auditLogger = alogger;
SignedDomain signedDomain = createSignedDomain("coretech", "weather", "storage", true);
store.processDomain(signedDomain, false);
Principal principal = SimplePrincipal.create("user_domain", "user", "v=U1;d=user_domain;n=user;s=signature", 0, null);
ResourceContext context = createResourceContext(principal, servletRequest);
RoleToken roleToken = ztsImpl.getRoleToken(context, "coretech", null, Integer.valueOf(600), Integer.valueOf(1200), null);
com.yahoo.athenz.auth.token.RoleToken token = new com.yahoo.athenz.auth.token.RoleToken(roleToken.getToken());
assertNotNull(token);
String unsignToken = token.getUnsignedToken();
for (String msg : aLogMsgs) {
assertTrue(msg.contains("SUCCESS ROLETOKEN=(" + unsignToken));
assertTrue(msg.contains("i=127.0.0.1"));
assertTrue(msg.contains("CLIENT-IP=(127.0.0.1)"));
break;
}
}
use of com.yahoo.athenz.zts.store.DataStore in project athenz by yahoo.
the class ZTSImplTest method testPostInstanceRefreshInformationNullCSRs.
@Test
public void testPostInstanceRefreshInformationNullCSRs() 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);
InstanceRefreshInformation info = new InstanceRefreshInformation().setCsr(null).setSsh("");
PrincipalAuthority authority = new PrincipalAuthority();
SimplePrincipal principal = (SimplePrincipal) SimplePrincipal.create("athenz", "production", "v=S1;d=athenzn=production;s=signature", 0, authority);
ResourceContext context = createResourceContext(principal);
try {
ztsImpl.postInstanceRefreshInformation(context, "athenz.provider", "athenz", "production", "1001", info);
fail();
} catch (ResourceException ex) {
assertTrue(ex.getMessage().contains("no csr provided"));
}
}
use of com.yahoo.athenz.zts.store.DataStore in project athenz by yahoo.
the class ZTSImplTest method testPostInstanceRefreshInformationNoCertAuthority.
@Test
public void testPostInstanceRefreshInformationNoCertAuthority() 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.instanceid.csr");
String certCsr = new String(Files.readAllBytes(path));
InstanceRefreshInformation info = new InstanceRefreshInformation().setCsr(certCsr);
PrincipalAuthority authority = new PrincipalAuthority();
SimplePrincipal principal = (SimplePrincipal) SimplePrincipal.create("athenz", "production", "v=S1;d=athenzn=production;s=signature", 0, authority);
ResourceContext context = createResourceContext(principal);
try {
ztsImpl.postInstanceRefreshInformation(context, "athenz.provider", "athenz", "production", "1001", info);
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 400);
assertTrue(ex.getMessage().contains("Unsupported authority for TLS Certs"));
}
}
use of com.yahoo.athenz.zts.store.DataStore in project athenz by yahoo.
the class ZTSImplTest method testPostInstanceRefreshInformationProviderNotAuthorized.
@Test
public void testPostInstanceRefreshInformationProviderNotAuthorized() 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));
InstanceRefreshInformation info = new InstanceRefreshInformation().setCsr(certCsr);
CertificateAuthority certAuthority = new CertificateAuthority();
SimplePrincipal principal = (SimplePrincipal) SimplePrincipal.create("athenz", "production", "v=S1;d=athenz;n=production;s=signature", 0, certAuthority);
ResourceContext context = createResourceContext(principal);
try {
ztsImpl.postInstanceRefreshInformation(context, "athenz.provider2", "athenz", "production", "1001", info);
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 403);
assertTrue(ex.getMessage().contains("not authorized to launch instances in Athenz"));
}
}
Aggregations