Search in sources :

Example 6 with ZMSAuthorizer

use of com.yahoo.athenz.zms.ZMSAuthorizer in project athenz by yahoo.

the class ZMSAuthorizerTest method testAuthorizerNoDomain.

@Test
public void testAuthorizerNoDomain() {
    ZMSClient client = getClient(systemAdminUser);
    String domain = "AuthorizerDom3";
    ZMSAuthorizer authorizer = new ZMSAuthorizer(zmsUrl, null);
    assertNotNull(authorizer);
    // create 3 user client objects
    Principal p1 = createPrincipal("user1");
    Principal p2 = createPrincipal("user2");
    Principal p3 = createPrincipal("user3");
    ZMSRDLGeneratedClient c = Mockito.mock(ZMSRDLGeneratedClient.class);
    client.setZMSRDLGeneratedClient(c);
    Domain domainMock = Mockito.mock(Domain.class);
    Mockito.when(c.postTopLevelDomain(Mockito.<String>any(), Mockito.any(TopLevelDomain.class))).thenReturn(domainMock);
    setupAccess(client, domain);
    ZMSClient mockZMSClient = Mockito.mock(ZMSClient.class);
    authorizer.setZMSClient(mockZMSClient);
    // only user1 and user3 have access to UPDATE/resource1
    Access accessMock = Mockito.mock(Access.class);
    Mockito.when(mockZMSClient.getAccess("UPDATE", "AuthorizerDom3:resource1", "AuthorizerDom3")).thenReturn(accessMock);
    Mockito.when(accessMock.getGranted()).thenReturn(true, false, true);
    Mockito.when(c.getAccess("UPDATE", "AuthorizerDom3:resource1", "AuthorizerDom3", null)).thenReturn(accessMock);
    boolean access = authorizer.access("UPDATE", domain + ":resource1", p1, domain);
    assertTrue(access);
    access = authorizer.access("UPDATE", domain + ":resource1", p2, domain);
    assertFalse(access);
    access = authorizer.access("UPDATE", domain + ":resource1", p3, domain);
    assertTrue(access);
    TopLevelDomain topLevelDomainMock = Mockito.mock(TopLevelDomain.class);
    Mockito.when(c.deleteTopLevelDomain(domain, AUDIT_REF)).thenReturn(topLevelDomainMock);
    authorizer.close();
    cleanUpAccess(domain);
}
Also used : ZMSAuthorizer(com.yahoo.athenz.zms.ZMSAuthorizer) Principal(com.yahoo.athenz.auth.Principal) SimplePrincipal(com.yahoo.athenz.auth.impl.SimplePrincipal) Test(org.testng.annotations.Test)

Example 7 with ZMSAuthorizer

use of com.yahoo.athenz.zms.ZMSAuthorizer in project athenz by yahoo.

the class ZMSAuthorizerTest method testAuthorizerNoEndpoint.

@Test
public void testAuthorizerNoEndpoint() {
    String domain = "AuthorizerDom2";
    ZMSAuthorizer authorizer = new ZMSAuthorizer(domain);
    assertNotNull(authorizer);
}
Also used : ZMSAuthorizer(com.yahoo.athenz.zms.ZMSAuthorizer) Test(org.testng.annotations.Test)

Aggregations

ZMSAuthorizer (com.yahoo.athenz.zms.ZMSAuthorizer)7 Test (org.testng.annotations.Test)6 Principal (com.yahoo.athenz.auth.Principal)4 SimplePrincipal (com.yahoo.athenz.auth.impl.SimplePrincipal)4 PrintWriter (java.io.PrintWriter)1