Search in sources :

Example 46 with ObjectStoreConnection

use of com.yahoo.athenz.zms.store.ObjectStoreConnection in project athenz by yahoo.

the class QuotaCheckerTest method testCheckRoleQuotaRoleMemberExceeded.

@Test
public void testCheckRoleQuotaRoleMemberExceeded() {
    QuotaChecker quotaCheck = new QuotaChecker();
    Quota mockQuota = new Quota().setName("athenz").setRole(2).setRoleMember(2);
    ObjectStoreConnection con = Mockito.mock(ObjectStoreConnection.class);
    Mockito.when(con.getQuota("athenz")).thenReturn(mockQuota);
    Mockito.when(con.countRoles("athenz")).thenReturn(1);
    ArrayList<RoleMember> roleMembers = new ArrayList<>();
    roleMembers.add(new RoleMember().setMemberName("user.joe"));
    roleMembers.add(new RoleMember().setMemberName("user.jane"));
    roleMembers.add(new RoleMember().setMemberName("user.doe"));
    Role role = new Role().setRoleMembers(roleMembers);
    try {
        quotaCheck.checkRoleQuota(con, "athenz", role, "caller");
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), ResourceException.TOO_MANY_REQUESTS);
        assertTrue(ex.getMessage().contains("role member quota exceeded"));
    }
}
Also used : ArrayList(java.util.ArrayList) ObjectStoreConnection(com.yahoo.athenz.zms.store.ObjectStoreConnection) Test(org.testng.annotations.Test)

Example 47 with ObjectStoreConnection

use of com.yahoo.athenz.zms.store.ObjectStoreConnection in project athenz by yahoo.

the class QuotaCheckerTest method testCheckRoleMembershipQuota.

@Test
public void testCheckRoleMembershipQuota() {
    QuotaChecker quotaCheck = new QuotaChecker();
    Quota mockQuota = new Quota().setName("athenz").setRole(2).setRoleMember(2);
    ObjectStoreConnection con = Mockito.mock(ObjectStoreConnection.class);
    Mockito.when(con.getQuota("athenz")).thenReturn(mockQuota);
    Mockito.when(con.countRoleMembers("athenz", "readers")).thenReturn(1);
    // this should complete successfully
    quotaCheck.checkRoleMembershipQuota(con, "athenz", "readers", "caller");
}
Also used : ObjectStoreConnection(com.yahoo.athenz.zms.store.ObjectStoreConnection) Test(org.testng.annotations.Test)

Example 48 with ObjectStoreConnection

use of com.yahoo.athenz.zms.store.ObjectStoreConnection in project athenz by yahoo.

the class QuotaCheckerTest method testCheckPolicyAssertionQuota.

@Test
public void testCheckPolicyAssertionQuota() {
    QuotaChecker quotaCheck = new QuotaChecker();
    Quota mockQuota = new Quota().setName("athenz").setPolicy(2).setAssertion(2);
    ObjectStoreConnection con = Mockito.mock(ObjectStoreConnection.class);
    Mockito.when(con.getQuota("athenz")).thenReturn(mockQuota);
    Mockito.when(con.countAssertions("athenz", "readers")).thenReturn(1);
    // this should be successful - no exceptions
    quotaCheck.checkPolicyAssertionQuota(con, "athenz", "readers", "caller");
}
Also used : ObjectStoreConnection(com.yahoo.athenz.zms.store.ObjectStoreConnection) Test(org.testng.annotations.Test)

Example 49 with ObjectStoreConnection

use of com.yahoo.athenz.zms.store.ObjectStoreConnection in project athenz by yahoo.

the class QuotaCheckerTest method testCheckPolicyQuotaPolicyCountExceeded.

@Test
public void testCheckPolicyQuotaPolicyCountExceeded() {
    QuotaChecker quotaCheck = new QuotaChecker();
    Quota mockQuota = new Quota().setName("athenz").setPolicy(2).setAssertion(2);
    ObjectStoreConnection con = Mockito.mock(ObjectStoreConnection.class);
    Mockito.when(con.getQuota("athenz")).thenReturn(mockQuota);
    Mockito.when(con.countPolicies("athenz")).thenReturn(2);
    ArrayList<Assertion> assertions = new ArrayList<>();
    assertions.add(new Assertion().setAction("*").setResource("*").setRole("admin"));
    assertions.add(new Assertion().setAction("*").setResource("*").setRole("admin"));
    Policy policy = new Policy();
    policy.setAssertions(assertions);
    try {
        quotaCheck.checkPolicyQuota(con, "athenz", policy, "caller");
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), ResourceException.TOO_MANY_REQUESTS);
        assertTrue(ex.getMessage().contains("policy quota exceeded"));
    }
}
Also used : ArrayList(java.util.ArrayList) ObjectStoreConnection(com.yahoo.athenz.zms.store.ObjectStoreConnection) Test(org.testng.annotations.Test)

Example 50 with ObjectStoreConnection

use of com.yahoo.athenz.zms.store.ObjectStoreConnection in project athenz by yahoo.

the class QuotaCheckerTest method testCheckServiceQuotaServiceCountExceeded.

@Test
public void testCheckServiceQuotaServiceCountExceeded() {
    QuotaChecker quotaCheck = new QuotaChecker();
    Quota mockQuota = new Quota().setName("athenz").setService(2).setServiceHost(2).setPublicKey(2);
    ObjectStoreConnection con = Mockito.mock(ObjectStoreConnection.class);
    Mockito.when(con.getQuota("athenz")).thenReturn(mockQuota);
    Mockito.when(con.countServiceIdentities("athenz")).thenReturn(2);
    ArrayList<String> hosts = new ArrayList<>();
    hosts.add("host1");
    ArrayList<PublicKeyEntry> publicKeys = new ArrayList<>();
    publicKeys.add(new PublicKeyEntry().setId("id1").setKey("key"));
    ServiceIdentity service = new ServiceIdentity();
    service.setHosts(hosts);
    service.setPublicKeys(publicKeys);
    try {
        quotaCheck.checkServiceIdentityQuota(con, "athenz", service, "caller");
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), ResourceException.TOO_MANY_REQUESTS);
        assertTrue(ex.getMessage().contains("service quota exceeded"));
    }
}
Also used : ArrayList(java.util.ArrayList) ObjectStoreConnection(com.yahoo.athenz.zms.store.ObjectStoreConnection) Test(org.testng.annotations.Test)

Aggregations

ObjectStoreConnection (com.yahoo.athenz.zms.store.ObjectStoreConnection)53 Test (org.testng.annotations.Test)22 ArrayList (java.util.ArrayList)14 AthenzDomain (com.yahoo.athenz.zms.store.AthenzDomain)4 Timestamp (com.yahoo.rdl.Timestamp)1