Search in sources :

Example 21 with Metric

use of com.yahoo.athenz.common.metrics.Metric 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);
    Metric metricMock = Mockito.mock(Metric.class);
    Object timerMetricMock = Mockito.mock(Object.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);
    RsrcCtxWrapper wrapper = new RsrcCtxWrapper(reqMock, resMock, authListMock, false, authorizerMock, metricMock, timerMetricMock, "apiName");
    // when not set authority
    wrapper.authorize("add-domain", "test", "test");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Authorizer(com.yahoo.athenz.auth.Authorizer) HttpServletResponse(javax.servlet.http.HttpServletResponse) Metric(com.yahoo.athenz.common.metrics.Metric) AuthorityList(com.yahoo.athenz.common.server.rest.Http.AuthorityList) Test(org.testng.annotations.Test)

Aggregations

Metric (com.yahoo.athenz.common.metrics.Metric)21 Test (org.testng.annotations.Test)19 Authorizer (com.yahoo.athenz.auth.Authorizer)11 AuthorityList (com.yahoo.athenz.common.server.rest.Http.AuthorityList)11 HttpServletRequest (javax.servlet.http.HttpServletRequest)11 HttpServletResponse (javax.servlet.http.HttpServletResponse)11 Authority (com.yahoo.athenz.auth.Authority)7 PrincipalAuthority (com.yahoo.athenz.auth.impl.PrincipalAuthority)7 SimplePrincipal (com.yahoo.athenz.auth.impl.SimplePrincipal)6 Principal (com.yahoo.athenz.auth.Principal)4 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)2 SslConnection (org.eclipse.jetty.io.ssl.SslConnection)2 SslHandshakeListener (org.eclipse.jetty.io.ssl.SslHandshakeListener)2 DomainChangeMessage (com.yahoo.athenz.common.messaging.DomainChangeMessage)1 MetricFactory (com.yahoo.athenz.common.metrics.MetricFactory)1 Notification (com.yahoo.athenz.common.server.notification.Notification)1 NotificationMetric (com.yahoo.athenz.common.server.notification.NotificationMetric)1 NotificationToMetricConverter (com.yahoo.athenz.common.server.notification.NotificationToMetricConverter)1