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);
}
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);
}
Aggregations