use of com.yahoo.athenz.auth.Authority in project athenz by yahoo.
the class RsrcCtxWrapperTest method testAuthenticateException.
@Test
public void testAuthenticateException() {
HttpServletRequest reqMock = Mockito.mock(HttpServletRequest.class);
HttpServletResponse resMock = Mockito.mock(HttpServletResponse.class);
AuthorityList authListMock = new AuthorityList();
Authorizer authorizerMock = Mockito.mock(Authorizer.class);
Authority authMock = Mockito.mock(Authority.class);
Metric metricMock = Mockito.mock(Metric.class);
Object timerMetricMock = Mockito.mock(Object.class);
Mockito.when(authMock.getHeader()).thenReturn("testheader");
Mockito.when(reqMock.getHeader("testheader")).thenReturn("testcred");
Mockito.when(authMock.getCredSource()).thenReturn(com.yahoo.athenz.auth.Authority.CredSource.HEADER);
Mockito.when(authMock.authenticate(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())).thenThrow(new com.yahoo.athenz.common.server.rest.ResourceException(403));
Mockito.when(reqMock.getRemoteAddr()).thenReturn("1.1.1.1");
Mockito.when(reqMock.getMethod()).thenReturn("POST");
authListMock.add(authMock);
RsrcCtxWrapper wrapper = new RsrcCtxWrapper(reqMock, resMock, authListMock, false, authorizerMock, metricMock, timerMetricMock, "apiName");
try {
wrapper.authenticate();
} catch (ResourceException ex) {
assertEquals(403, ex.getCode());
}
}
use of com.yahoo.athenz.auth.Authority in project athenz by yahoo.
the class RsrcCtxWrapperTest method testLogPrincipalRoleName.
@Test
public void testLogPrincipalRoleName() {
HttpServletRequest reqMock = Mockito.mock(HttpServletRequest.class);
HttpServletResponse resMock = Mockito.mock(HttpServletResponse.class);
AuthorityList authListMock = new AuthorityList();
Authorizer authorizerMock = Mockito.mock(Authorizer.class);
Authority authMock = Mockito.mock(Authority.class);
Metric metricMock = Mockito.mock(Metric.class);
Object timerMetricMock = Mockito.mock(Object.class);
SimplePrincipal principal = (SimplePrincipal) SimplePrincipal.create("hockey", "kings", "v=S1,d=hockey;n=kings;s=sig", 0, new PrincipalAuthority());
principal.setRolePrincipalName("athenz.role");
Mockito.when(authMock.getHeader()).thenReturn("testheader");
Mockito.when(reqMock.getHeader("testheader")).thenReturn("testcred");
Mockito.when(authMock.getCredSource()).thenReturn(com.yahoo.athenz.auth.Authority.CredSource.HEADER);
Mockito.when(authMock.authenticate(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(principal);
Mockito.when(reqMock.getRemoteAddr()).thenReturn("1.1.1.1");
Mockito.when(reqMock.getMethod()).thenReturn("POST");
authListMock.add(authMock);
RsrcCtxWrapper wrapper = new RsrcCtxWrapper(reqMock, resMock, authListMock, false, authorizerMock, metricMock, timerMetricMock, "apiName");
wrapper.authenticate();
assertEquals("athenz.role", wrapper.logPrincipal());
assertEquals("hockey", wrapper.getPrincipalDomain());
}
use of com.yahoo.athenz.auth.Authority in project athenz by yahoo.
the class ZTSAuthorizerTest method testAccessInvalidResourceDomain.
@Test
public void testAccessInvalidResourceDomain() {
ZTSAuthorizer authz = new ZTSAuthorizer(null);
Authority authority = Mockito.mock(Authority.class);
Mockito.when(authority.allowAuthorization()).thenReturn(true);
Principal principal = Mockito.mock(Principal.class);
Mockito.when(principal.getAuthority()).thenReturn(authority);
try {
authz.access("op", "invalid-resource", principal, null);
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 404);
}
}
use of com.yahoo.athenz.auth.Authority in project athenz by yahoo.
the class ZMSImplTest method testGetResourceAccessList.
@Test
public void testGetResourceAccessList() {
Authority principalAuthority = new com.yahoo.athenz.common.server.debug.DebugPrincipalAuthority();
Principal principal1 = principalAuthority.authenticate("v=U1;d=user;n=user1;s=signature", "10.11.12.13", "GET", null);
ResourceContext rsrcCtx1 = createResourceContext(principal1);
try {
zms.getResourceAccessList(rsrcCtx1, "principal", "UPDATE");
} catch (Exception ex) {
assertTrue(true);
}
}
use of com.yahoo.athenz.auth.Authority in project athenz by yahoo.
the class ZMSImplTest method testIsAllowedResourceLookForAllUsers.
@Test
public void testIsAllowedResourceLookForAllUsers() {
Authority principalAuthority = new com.yahoo.athenz.common.server.debug.DebugPrincipalAuthority();
Principal principal1 = principalAuthority.authenticate("v=U1;d=user;n=user1;s=signature", "10.11.12.13", "GET", null);
try {
zms.isAllowedResourceLookForAllUsers(principal1);
} catch (Exception ex) {
assertTrue(true);
}
}
Aggregations