use of com.yahoo.athenz.zms.Policy in project athenz by yahoo.
the class ZTSImplTest method testGetPolicyList.
@Test
public void testGetPolicyList() {
List<com.yahoo.athenz.zms.Policy> policies = new ArrayList<>();
List<com.yahoo.athenz.zms.Assertion> assertions = new ArrayList<>();
com.yahoo.athenz.zms.Policy policy = new com.yahoo.athenz.zms.Policy();
com.yahoo.athenz.zms.Assertion assertion = new com.yahoo.athenz.zms.Assertion();
assertion.setResource("coretech:tenant.weather.*");
assertion.setAction("read");
assertion.setRole("coretech:role.readers");
assertions.add(assertion);
policy.setAssertions(assertions);
policy.setName("coretech:policy.reader");
policies.add(policy);
policy = new com.yahoo.athenz.zms.Policy();
assertion = new com.yahoo.athenz.zms.Assertion();
assertion.setResource("coretech:tenant.weather.*");
assertion.setAction("write");
assertion.setRole("coretech:role.writers");
assertions.add(assertion);
policy.setAssertions(assertions);
policy.setName("coretech:policy.writer");
policies.add(policy);
com.yahoo.athenz.zms.DomainPolicies domainPolicies = new com.yahoo.athenz.zms.DomainPolicies();
domainPolicies.setDomain("coretech");
domainPolicies.setPolicies(policies);
com.yahoo.athenz.zms.SignedPolicies signedPolicies = new com.yahoo.athenz.zms.SignedPolicies();
signedPolicies.setContents(domainPolicies);
signedPolicies.setSignature(Crypto.sign(SignUtils.asCanonicalString(domainPolicies), privateKey));
signedPolicies.setKeyId("0");
DomainData domain = new DomainData();
domain.setName("coretech");
domain.setPolicies(signedPolicies);
domain.setModified(Timestamp.fromCurrentTime());
List<com.yahoo.athenz.zts.Policy> policyList = zts.getPolicyList(domain);
assertEquals(policyList.size(), 2);
assertEquals(policyList.get(0).getName(), "coretech:policy.reader");
assertEquals(policyList.get(1).getName(), "coretech:policy.writer");
}
use of com.yahoo.athenz.zms.Policy in project athenz by yahoo.
the class ZTSImplTest method createPolicyObject.
private Policy createPolicyObject(String domainName, String policyName, String roleName, boolean generateRoleName, String action, String resource, AssertionEffect effect) {
Policy policy = new Policy();
policy.setName(domainName + ":policy." + policyName);
Assertion assertion = new Assertion();
assertion.setAction(action);
assertion.setEffect(effect);
assertion.setResource(resource);
if (generateRoleName) {
assertion.setRole(domainName + ":role." + roleName);
} else {
assertion.setRole(roleName);
}
List<Assertion> assertList = new ArrayList<Assertion>();
assertList.add(assertion);
policy.setAssertions(assertList);
return policy;
}
use of com.yahoo.athenz.zms.Policy in project athenz by yahoo.
the class JDBCConnectionTest method testUpdatePolicy.
@Test
public void testUpdatePolicy() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
Policy policy = new Policy().setName("my-domain:policy.policy1");
Mockito.doReturn(1).when(mockPrepStmt).executeUpdate();
Mockito.when(mockResultSet.next()).thenReturn(true);
// return domain id
Mockito.when(mockResultSet.getInt(1)).thenReturn(5).thenReturn(// policy id
4);
boolean requestSuccess = jdbcConn.updatePolicy("my-domain", policy);
assertTrue(requestSuccess);
// get domain id
Mockito.verify(mockPrepStmt, times(1)).setString(1, "my-domain");
// get policy id
Mockito.verify(mockPrepStmt, times(1)).setInt(1, 5);
Mockito.verify(mockPrepStmt, times(1)).setString(2, "policy1");
// update policy
Mockito.verify(mockPrepStmt, times(1)).setString(1, "policy1");
Mockito.verify(mockPrepStmt, times(1)).setInt(2, 4);
jdbcConn.close();
}
use of com.yahoo.athenz.zms.Policy in project athenz by yahoo.
the class JDBCConnectionTest method testUpdatePolicyInvalidName.
@Test
public void testUpdatePolicyInvalidName() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
Policy policy = new Policy().setName("policy1");
Mockito.when(mockResultSet.next()).thenReturn(true);
// return domain id
Mockito.doReturn(5).when(mockResultSet).getInt(1);
try {
jdbcConn.updatePolicy("my-domain", policy);
fail();
} catch (ResourceException ex) {
assertEquals(400, ex.getCode());
}
jdbcConn.close();
}
use of com.yahoo.athenz.zms.Policy in project athenz by yahoo.
the class JDBCConnectionTest method testGetPolicy.
@Test
public void testGetPolicy() throws Exception {
Mockito.when(mockResultSet.next()).thenReturn(true);
Mockito.doReturn("policy1").when(mockResultSet).getString(ZMSConsts.DB_COLUMN_NAME);
Mockito.doReturn(new java.sql.Timestamp(1454358916)).when(mockResultSet).getTimestamp(ZMSConsts.DB_COLUMN_MODIFIED);
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
Policy policy = jdbcConn.getPolicy("my-domain", "policy1");
assertNotNull(policy);
assertEquals("my-domain:policy.policy1", policy.getName());
Mockito.verify(mockPrepStmt, times(1)).setString(1, "my-domain");
Mockito.verify(mockPrepStmt, times(1)).setString(2, "policy1");
jdbcConn.close();
}
Aggregations