use of com.yahoo.athenz.auth.Authorizer in project athenz by yahoo.
the class ResourceContextTest method testResourceContext.
@Test
public void testResourceContext() {
HttpServletRequest httpServletRequest = Mockito.mock(HttpServletRequest.class);
HttpServletResponse httpServletResponse = Mockito.mock(HttpServletResponse.class);
Authorizer authorizer = Mockito.mock(Authorizer.class);
Http.AuthorityList authorities = new Http.AuthorityList();
ResourceContext context = new ResourceContext(httpServletRequest, httpServletResponse, authorities, authorizer);
assertEquals(context.request(), httpServletRequest);
assertEquals(context.response(), httpServletResponse);
assertNull(context.principal());
}
use of com.yahoo.athenz.auth.Authorizer in project athenz by yahoo.
the class HttpTest method testAuthorizedUserUserInvalidCredentials.
@Test
public void testAuthorizedUserUserInvalidCredentials() throws Exception {
HttpServletRequest httpServletRequest = Mockito.mock(HttpServletRequest.class);
Authorizer authorizer = Mockito.mock(Authorizer.class);
Http.AuthorityList authorities = new Http.AuthorityList();
try {
Http.authorizedUser(httpServletRequest, authorities, authorizer, "action", null, null);
} catch (ResourceException expected) {
assertEquals(expected.getCode(), 401);
}
}
use of com.yahoo.athenz.auth.Authorizer in project athenz by yahoo.
the class HttpTest method testAuthorizedForbidden.
@Test
public void testAuthorizedForbidden() throws Exception {
Authorizer authorizer = Mockito.mock(Authorizer.class);
Principal principal = Mockito.mock(Principal.class);
try {
Http.authorize(authorizer, principal, "action", "resource", null);
} catch (ResourceException expected) {
assertEquals(expected.getCode(), 403);
}
}
use of com.yahoo.athenz.auth.Authorizer in project athenz by yahoo.
the class RsrcCtxWrapperTest method TestAuthorize.
@Test
public void TestAuthorize() {
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);
Principal prin = Mockito.mock(Principal.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.<String>any(), Mockito.<String>any(), Mockito.<String>any(), Mockito.any())).thenReturn(prin);
Mockito.when(reqMock.getRemoteAddr()).thenReturn("1.1.1.1");
Mockito.when(reqMock.getMethod()).thenReturn("POST");
authListMock.add(authMock);
// force true access right
Mockito.when(authorizerMock.access(Mockito.<String>any(), Mockito.<String>any(), Mockito.any(), Mockito.any())).thenReturn(true);
RsrcCtxWrapper wrapper = new RsrcCtxWrapper(reqMock, resMock, authListMock, false, authorizerMock);
wrapper.authorize("add-domain", "test", "test");
// after authorize success, principal should be set
assertEquals(wrapper.principal(), prin);
}
use of com.yahoo.athenz.auth.Authorizer in project athenz by yahoo.
the class RsrcCtxWrapperTest method TestRsrcCtxWrapperSimpleAssertion.
@Test
public void TestRsrcCtxWrapperSimpleAssertion() {
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);
Principal prin = Mockito.mock(Principal.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.<String>any(), Mockito.<String>any(), Mockito.<String>any(), Mockito.any())).thenReturn(prin);
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);
assertNotNull(wrapper.context());
// default principal should be null
assertEquals(wrapper.principal(), null);
assertEquals(wrapper.request(), reqMock);
assertEquals(wrapper.response(), resMock);
wrapper.authenticate();
// after authenticate, principal should be set
assertEquals(wrapper.principal(), prin);
// invalid kerberos request
try {
wrapper.authenticateKerberos();
fail();
} catch (ResourceException ex) {
assertNotNull(ex);
}
}
Aggregations