use of com.yahoo.athenz.auth.impl.PrincipalAuthority in project athenz by yahoo.
the class ZTSImplTest method testPostInstanceRefreshRequest.
@Test
public void testPostInstanceRefreshRequest() throws IOException {
Path path = Paths.get("src/test/resources/valid.csr");
String certCsr = new String(Files.readAllBytes(path));
InstanceRefreshRequest req = new InstanceRefreshRequest().setCsr(certCsr);
SimplePrincipal principal = (SimplePrincipal) SimplePrincipal.create("athenz", "syncer", "v=S1,d=athenz;n=syncer;s=sig", 0, new PrincipalAuthority());
principal.setKeyId("0");
String publicKeyName = "athenz.syncer_0";
final String ztsPublicKey = "-----BEGIN PUBLIC KEY-----\n" + "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKrvfvBgXWqWAorw5hYJu3dpOJe0gp3n\n" + "TgiiPGT7+jzm6BRcssOBTPFIMkePT2a8Tq+FYSmFnHfbQjwmYw2uMK8CAwEAAQ==\n" + "-----END PUBLIC KEY-----";
zts.dataStore.getPublicKeyCache().put(publicKeyName, ztsPublicKey);
HttpServletRequest servletRequest = Mockito.mock(HttpServletRequest.class);
Mockito.when(servletRequest.isSecure()).thenReturn(true);
ResourceContext context = createResourceContext(principal, servletRequest);
Identity identity = zts.postInstanceRefreshRequest(context, "athenz", "syncer", req);
assertNotNull(identity);
X509Certificate cert = Crypto.loadX509Certificate(identity.getCertificate());
assertNotNull(cert);
}
use of com.yahoo.athenz.auth.impl.PrincipalAuthority in project athenz by yahoo.
the class ZTSImplTest method testPostInstanceRefreshRequestByUserInvalidRequest.
@Test
public void testPostInstanceRefreshRequestByUserInvalidRequest() 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.csr");
String certCsr = new String(Files.readAllBytes(path));
InstanceRefreshRequest req = new InstanceRefreshRequest().setCsr(certCsr).setKeyId("v0");
SimplePrincipal principal = (SimplePrincipal) SimplePrincipal.create("user", "doe", "v=U1,d=user;n=doe;s=sig", 0, new PrincipalAuthority());
principal.setKeyId("1");
String publicKeyName = "athenz.api_v0";
final String ztsPublicKey = "-----BEGIN PUBLIC KEY-----\n" + "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAMp9ZHVDK2s/FyinpKpD7lSsU+d6TSRE\n" + "NVo6sdLrEpOaCJETsh+0Qc0knhALxBD1+B9gS5F2rAFgtug0R6savvMCAwEAAQ==\n" + "-----END PUBLIC KEY-----";
ztsImpl.dataStore.getPublicKeyCache().put(publicKeyName, ztsPublicKey);
ZTSAuthorizer authorizer = Mockito.mock(ZTSAuthorizer.class);
Mockito.when(authorizer.access("update", "athenz:service", principal, null)).thenReturn(true);
ztsImpl.authorizer = authorizer;
HttpServletRequest servletRequest = Mockito.mock(HttpServletRequest.class);
Mockito.when(servletRequest.isSecure()).thenReturn(true);
ResourceContext context = createResourceContext(principal, servletRequest);
try {
ztsImpl.postInstanceRefreshRequest(context, "athenz", "api", req);
fail();
} catch (Exception ex) {
assertTrue(ex.getMessage().contains("Invalid CSR - data mismatch"), ex.getMessage());
}
}
use of com.yahoo.athenz.auth.impl.PrincipalAuthority in project athenz by yahoo.
the class ZTSImplTest method testResourceAccess.
@Test
public void testResourceAccess() {
final String domainName = "coretechaccess";
DataCache domain = new DataCache();
DomainData domainData = new DomainData();
domainData.setName(domainName);
domain.setDomainData(domainData);
domainData.setRoles(new ArrayList<Role>());
Role role1 = createRoleObject(domainName, "role1", null, "user.user1", "user.user3");
Role role2 = createRoleObject(domainName, "role2", null, "user.user2", null);
domainData.getRoles().add(role1);
domainData.getRoles().add(role2);
Policy policy = createPolicyObject(domainName, "access", domainName + ":role.role1", false, "update", domainName + ":table1", AssertionEffect.ALLOW);
domainData.setPolicies(new com.yahoo.athenz.zms.SignedPolicies());
domainData.getPolicies().setContents(new com.yahoo.athenz.zms.DomainPolicies());
domainData.getPolicies().getContents().setPolicies(new ArrayList<Policy>());
domainData.getPolicies().getContents().getPolicies().add(policy);
store.getCacheStore().put(domainName, domain);
Authority principalAuthority = new com.yahoo.athenz.common.server.debug.DebugPrincipalAuthority();
Principal principal = SimplePrincipal.create("user", "user1", "v=U1;d=user;n=user1;s=signature", 0, principalAuthority);
ResourceContext ctx = createResourceContext(principal, null);
// process
ResourceAccess access = zts.getResourceAccess(ctx, "update", domainName + ":table1", null, null);
assertTrue(access.getGranted());
access = zts.getResourceAccessExt(ctx, "update", domainName + ":table1", null, null);
assertTrue(access.getGranted());
access = zts.getResourceAccess(ctx, "update", domainName + ":table2", null, null);
assertFalse(access.getGranted());
access = zts.getResourceAccessExt(ctx, "update", domainName + ":table2", null, null);
assertFalse(access.getGranted());
access = zts.getResourceAccess(ctx, "delete", domainName + ":table1", null, null);
assertFalse(access.getGranted());
access = zts.getResourceAccessExt(ctx, "delete", domainName + ":table1", null, null);
assertFalse(access.getGranted());
access = zts.getResourceAccess(ctx, "update", domainName + ":table1", null, "user.user2");
assertFalse(access.getGranted());
access = zts.getResourceAccess(ctx, "update", domainName + ":table1", null, "user.user3");
assertTrue(access.getGranted());
access = zts.getResourceAccess(ctx, "update", domainName + ":table2", null, "user.user3");
assertFalse(access.getGranted());
store.getCacheStore().invalidate(domainName);
}
use of com.yahoo.athenz.auth.impl.PrincipalAuthority in project athenz by yahoo.
the class ZTSImplTest method testCheckRoleTokenAuthorizedServiceRequest.
@Test
public void testCheckRoleTokenAuthorizedServiceRequest() {
// match authorized service - top level domain
SimplePrincipal principal = (SimplePrincipal) SimplePrincipal.create("user", "doe", "v=U1,d=user;n=doe;s=sig", 0, new PrincipalAuthority());
principal.setAuthorizedService("sports.api");
zts.checkRoleTokenAuthorizedServiceRequest(principal, "sports", "caller");
// match authorized service - subdomain
principal.setAuthorizedService("sports.hockey.api");
zts.checkRoleTokenAuthorizedServiceRequest(principal, "sports.hockey", "caller");
// mismatch
principal.setAuthorizedService("weather.api");
try {
zts.checkRoleTokenAuthorizedServiceRequest(principal, "sports", "caller");
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 403);
}
}
use of com.yahoo.athenz.auth.impl.PrincipalAuthority in project athenz by yahoo.
the class ZTSImplTest method testGetServiceIdentityList.
@Test
public void testGetServiceIdentityList() {
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);
com.yahoo.athenz.zts.ServiceIdentityList svcList = zts.getServiceIdentityList(context, "coretech");
assertEquals(svcList.getNames().size(), 2);
assertTrue(svcList.getNames().contains("storage"));
assertTrue(svcList.getNames().contains("backup"));
}
Aggregations