use of com.yahoo.athenz.common.server.rest.Http.AuthorityList in project athenz by yahoo.
the class RsrcCtxWrapperTest method testDomainChangeMessageDisabled.
@Test
public void testDomainChangeMessageDisabled() {
HttpServletRequest servletRequest = new MockHttpServletRequest();
HttpServletResponse servletResponse = Mockito.mock(HttpServletResponse.class);
AuthorityList authListMock = new AuthorityList();
Authorizer authorizerMock = Mockito.mock(Authorizer.class);
Object timerMetric = new Object();
RsrcCtxWrapper wrapper = new RsrcCtxWrapper(servletRequest, servletResponse, authListMock, false, authorizerMock, timerMetric, "apiName", false);
assertNull(wrapper.getDomainChangeMessages());
// add domain msg
wrapper.addDomainChangeMessage(new DomainChangeMessage().setDomainName("domain1Name").setObjectName("domain1Name1").setObjectType(DOMAIN));
// add role msg for the same domain
wrapper.addDomainChangeMessage(new DomainChangeMessage().setDomainName("domain1Name").setObjectName("domain1role").setObjectType(ROLE));
assertNull(wrapper.getDomainChangeMessages());
}
use of com.yahoo.athenz.common.server.rest.Http.AuthorityList in project athenz by yahoo.
the class RsrcCtxWrapperTest method testLogPrincipal.
@Test
public void testLogPrincipal() {
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);
SimplePrincipal principal = (SimplePrincipal) SimplePrincipal.create("hockey", "kings", "v=S1,d=hockey;n=kings;s=sig", 0, new PrincipalAuthority());
Mockito.when(authMock.getHeader()).thenReturn("testheader");
Mockito.when(reqMock.getHeader("testheader")).thenReturn("testcred");
Mockito.when(authMock.getCredSource()).thenReturn(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);
Object timerMetric = new Object();
RsrcCtxWrapper wrapper = new RsrcCtxWrapper(reqMock, resMock, authListMock, false, authorizerMock, timerMetric, "apiName", false);
wrapper.authenticate();
wrapper.logPrincipal();
Mockito.verify(reqMock, times(1)).setAttribute("com.yahoo.athenz.auth.principal", "hockey.kings");
Mockito.verify(reqMock, times(1)).setAttribute("com.yahoo.athenz.auth.authority_id", "Auth-NTOKEN");
}
use of com.yahoo.athenz.common.server.rest.Http.AuthorityList in project athenz by yahoo.
the class RsrcCtxWrapperTest method testAuthorizeInvalid.
@Test(expectedExceptions = { ResourceException.class })
public void testAuthorizeInvalid() {
HttpServletRequest reqMock = Mockito.mock(HttpServletRequest.class);
HttpServletResponse resMock = Mockito.mock(HttpServletResponse.class);
AuthorityList authListMock = new AuthorityList();
Authorizer authorizerMock = Mockito.mock(Authorizer.class);
Mockito.when(reqMock.getHeader("testheader")).thenReturn("testcred");
Mockito.when(reqMock.getRemoteAddr()).thenReturn("1.1.1.1");
Mockito.when(reqMock.getMethod()).thenReturn("POST");
// force true access right
Mockito.when(authorizerMock.access(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(true);
Object timerMetric = new Object();
RsrcCtxWrapper wrapper = new RsrcCtxWrapper(reqMock, resMock, authListMock, false, authorizerMock, timerMetric, "apiName", false);
// when not set authority
wrapper.authorize("add-domain", "test", "test");
}
use of com.yahoo.athenz.common.server.rest.Http.AuthorityList in project athenz by yahoo.
the class RsrcCtxWrapperTest method testLogAuthorityId.
@Test
public void testLogAuthorityId() {
HttpServletRequest servletRequest = new MockHttpServletRequest();
HttpServletResponse servletResponse = Mockito.mock(HttpServletResponse.class);
AuthorityList authListMock = new AuthorityList();
Authorizer authorizerMock = Mockito.mock(Authorizer.class);
Object timerMetric = new Object();
RsrcCtxWrapper wrapper = new RsrcCtxWrapper(servletRequest, servletResponse, authListMock, false, authorizerMock, timerMetric, "apiName", false);
wrapper.logAuthorityId(null);
assertNull(servletRequest.getAttribute("com.yahoo.athenz.auth.authority_id"));
wrapper.logAuthorityId(new PrincipalAuthority());
assertEquals(servletRequest.getAttribute("com.yahoo.athenz.auth.authority_id"), "Auth-NTOKEN");
}
use of com.yahoo.athenz.common.server.rest.Http.AuthorityList 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);
Metric metricMock = Mockito.mock(Metric.class);
Object timerMetricMock = Mockito.mock(Object.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.any(), Mockito.any(), Mockito.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.any(), Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(true);
RsrcCtxWrapper wrapper = new RsrcCtxWrapper(reqMock, resMock, authListMock, false, authorizerMock, metricMock, timerMetricMock, "apiName");
wrapper.authorize("add-domain", "test", "test");
// after authorize success, principal should be set
assertEquals(wrapper.principal(), prin);
}
Aggregations