use of com.yahoo.athenz.zms.Assertion in project athenz by yahoo.
the class SignUtils method asStruct.
private static Struct asStruct(com.yahoo.athenz.zts.Policy policy) {
// all of our fields are in canonical order based
// on their attribute name
Struct struct = new Struct();
List<com.yahoo.athenz.zts.Assertion> assertions = policy.getAssertions();
if (assertions != null && !assertions.isEmpty()) {
Array assertionsArray = new Array();
for (com.yahoo.athenz.zts.Assertion assertion : assertions) {
Struct structAssertion = new Struct();
appendObject(structAssertion, ATTR_ACTION, assertion.getAction());
appendObject(structAssertion, ATTR_EFFECT, assertion.getEffect());
appendObject(structAssertion, ATTR_RESOURCE, assertion.getResource());
appendObject(structAssertion, ATTR_ROLE, assertion.getRole());
assertionsArray.add(structAssertion);
}
appendArray(struct, ATTR_ASSERTIONS, assertionsArray);
}
appendObject(struct, ATTR_MODIFIED, policy.getModified());
appendObject(struct, ATTR_NAME, policy.getName());
return struct;
}
use of com.yahoo.athenz.zms.Assertion in project athenz by yahoo.
the class FileConnectionTest method testAssertionMatch.
@Test
public void testAssertionMatch() {
File fileDir = new File("/home/athenz/zms_store");
File quotaDir = new File("/home/athenz/zms_quota");
Assertion assertion1 = new Assertion();
assertion1.setAction("UPDATE").setResource("resource").setRole("zmsRole");
Assertion assertion2 = new Assertion();
assertion2.setAction("UPDATE").setResource("resource").setRole("zmsRole");
try (FileConnection fileconnection = new FileConnection(fileDir, quotaDir)) {
assertTrue(fileconnection.assertionMatch(assertion1, assertion2));
Assertion assertion3 = new Assertion();
assertion3.setAction("UPDATE").setResource("resource").setRole("zmsRole");
Assertion assertion4 = new Assertion();
assertion4.setAction("Delete").setResource("resource").setRole("zmsRole");
assertFalse(fileconnection.assertionMatch(assertion3, assertion4));
Assertion assertion5 = new Assertion();
assertion5.setAction("UPDATE").setResource("resource1").setRole("zmsRole");
Assertion assertion6 = new Assertion();
assertion6.setAction("UPDATE").setResource("resource2").setRole("zmsRole");
assertFalse(fileconnection.assertionMatch(assertion5, assertion6));
Assertion assertion7 = new Assertion();
assertion7.setAction("UPDATE").setResource("resource").setRole("zmsRole1");
Assertion assertion8 = new Assertion();
assertion8.setAction("UPDATE").setResource("resource").setRole("zmsRole2");
assertFalse(fileconnection.assertionMatch(assertion7, assertion8));
Assertion assertion9 = new Assertion();
AssertionEffect effect1 = AssertionEffect.ALLOW;
assertion9.setAction("UPDATE").setResource("resource").setRole("zmsRole").setEffect(effect1);
Assertion assertion10 = new Assertion();
assertion10.setAction("UPDATE").setResource("resource").setRole("zmsRole").setEffect(effect1);
assertTrue(fileconnection.assertionMatch(assertion9, assertion10));
Assertion assertion11 = new Assertion();
AssertionEffect effect2 = AssertionEffect.ALLOW;
AssertionEffect effect3 = AssertionEffect.DENY;
assertion11.setAction("UPDATE").setResource("resource").setRole("zmsRole").setEffect(effect2);
Assertion assertion12 = new Assertion();
assertion12.setAction("UPDATE").setResource("resource").setRole("zmsRole").setEffect(effect3);
assertFalse(fileconnection.assertionMatch(assertion11, assertion12));
}
}
use of com.yahoo.athenz.zms.Assertion in project athenz by yahoo.
the class FileConnectionTest method testInsertAssertion.
@Test
public void testInsertAssertion() {
File fileDir = new File("/home/athenz/zms_store");
File quotaDir = new File("/home/athenz/zms_quota");
try (FileConnection fileconnection = new FileConnection(fileDir, quotaDir)) {
Assertion assertion = new Assertion();
try {
fileconnection.insertAssertion("Domain1", "policy1", assertion);
} catch (Exception ex) {
assertTrue(true);
}
}
}
use of com.yahoo.athenz.zms.Assertion in project athenz by yahoo.
the class DataCacheTest method testPolicyWithInvalidAssertionRole.
@Test
public void testPolicyWithInvalidAssertionRole() {
Domain domain = new Domain();
domain.setName("testDomain");
Role role1 = new Role();
role1.setName("testDomain.role.role1");
List<RoleMember> members1 = new ArrayList<>();
members1.add(new RoleMember().setMemberName("user_domain.user1"));
members1.add(new RoleMember().setMemberName("user_domain.user2"));
role1.setRoleMembers(members1);
Role role2 = new Role();
role2.setName("testDomain.role.role2");
List<RoleMember> members2 = new ArrayList<>();
members2.add(new RoleMember().setMemberName("user_domain.user2"));
role2.setRoleMembers(members2);
Role role3 = new Role();
role3.setName("testDomain.role.role3");
List<RoleMember> members3 = new ArrayList<>();
members3.add(new RoleMember().setMemberName("user_domain.user3"));
role3.setRoleMembers(members3);
Policy policy = new Policy();
policy.setName("testDomain.policy.policy1");
Assertion assertion = new Assertion();
assertion.setAction("assume_role");
assertion.setEffect(AssertionEffect.ALLOW);
assertion.setResource("testDomain.role");
assertion.setRole("testDomain.role.Invalid");
List<Assertion> assertList = new ArrayList<Assertion>();
assertList.add(assertion);
policy.setAssertions(assertList);
HashMap<String, Role> roleList = new HashMap<>();
roleList.put(role1.getName(), role1);
roleList.put(role2.getName(), role2);
roleList.put(role3.getName(), role3);
DataCache cache = new DataCache();
cache.processRole(role1);
cache.processRole(role2);
cache.processRole(role3);
cache.processPolicy(domain.getName(), policy, roleList);
Set<MemberRole> set1 = cache.getMemberRoleSet("user_domain.user1");
assertNotNull(set1);
assertTrue(set1.contains(new MemberRole("testDomain.role.role1", 0)));
assertEquals(set1.size(), 1);
Set<MemberRole> set2 = cache.getMemberRoleSet("user_domain.user2");
assertNotNull(set2);
assertTrue(set2.contains(new MemberRole("testDomain.role.role1", 0)));
assertTrue(set2.contains(new MemberRole("testDomain.role.role2", 0)));
assertEquals(set2.size(), 2);
Set<MemberRole> set3 = cache.getMemberRoleSet("user_domain.user3");
assertNotNull(set3);
assertTrue(set3.contains(new MemberRole("testDomain.role.role3", 0)));
assertEquals(set3.size(), 1);
}
use of com.yahoo.athenz.zms.Assertion in project athenz by yahoo.
the class DataCacheTest method testPolicyWithAssertionRoleNoMember.
@Test
public void testPolicyWithAssertionRoleNoMember() {
Domain domain = new Domain();
domain.setName("testDomain");
Role role1 = new Role();
role1.setName("testDomain.role.role1");
Role role2 = new Role();
role2.setName("testDomain.role.role2");
List<RoleMember> members2 = new ArrayList<>();
members2.add(new RoleMember().setMemberName("user_domain.user2"));
role2.setRoleMembers(members2);
Role role3 = new Role();
role3.setName("testDomain.role.role3");
List<RoleMember> members3 = new ArrayList<>();
members3.add(new RoleMember().setMemberName("user_domain.user3"));
role3.setRoleMembers(members3);
Policy policy = new Policy();
policy.setName("testDomain.policy.policy1");
Assertion assertion = new Assertion();
assertion.setAction("assume_role");
assertion.setEffect(AssertionEffect.ALLOW);
assertion.setResource("testDomain.roleA");
assertion.setRole("testDomain.role.role1");
List<Assertion> assertList = new ArrayList<Assertion>();
assertList.add(assertion);
policy.setAssertions(assertList);
HashMap<String, Role> roleList = new HashMap<>();
roleList.put(role1.getName(), role1);
roleList.put(role2.getName(), role2);
roleList.put(role3.getName(), role3);
DataCache cache = new DataCache();
cache.processRole(role1);
cache.processRole(role2);
cache.processRole(role3);
cache.processPolicy(domain.getName(), policy, roleList);
Set<MemberRole> set1 = cache.getMemberRoleSet("user_domain.user1");
assertNull(set1);
Set<MemberRole> set2 = cache.getMemberRoleSet("user_domain.user2");
assertNotNull(set2);
assertTrue(set2.contains(new MemberRole("testDomain.role.role2", 0)));
assertEquals(set2.size(), 1);
Set<MemberRole> set3 = cache.getMemberRoleSet("user_domain.user3");
assertNotNull(set3);
assertTrue(set3.contains(new MemberRole("testDomain.role.role3", 0)));
assertEquals(set3.size(), 1);
}
Aggregations