Search in sources :

Example 1 with RESTAPISecurityInterceptor

use of org.wso2.carbon.apimgt.rest.api.common.interceptors.RESTAPISecurityInterceptor in project carbon-apimgt by wso2.

the class RESTAPISecurityInterceptorTestCase method testGetApisSuccess.

@Test
public void testGetApisSuccess() throws APIManagementException {
    HTTPCarbonMessage carbonMessage = Mockito.mock(HTTPCarbonMessage.class);
    Request requestObj = Mockito.mock(Request.class);
    try {
        PowerMockito.whenNew(Request.class).withArguments(carbonMessage).thenReturn(requestObj);
    } catch (Exception e) {
        throw new APIMgtSecurityException("Error while mocking Request Object ", e);
    }
    Response responseObj = Mockito.mock(Response.class);
    Mockito.when(requestObj.getHeader(RestApiConstants.AUTHORIZATION_HTTP_HEADER)).thenReturn("Authorization:  053d68ee-12bc-36b0-ab9c-31752ef5bda9");
    Mockito.when(requestObj.getHeader("REQUEST_URL")).thenReturn("http://localhost:9090/api/am/publisher/v1/api");
    ServiceMethodInfo serviceMethodInfoObj = Mockito.mock(ServiceMethodInfo.class);
    RESTAPISecurityInterceptor interceptor = Mockito.mock(RESTAPISecurityInterceptor.class);
    boolean isAuthorized = interceptor.preCall(requestObj, responseObj, serviceMethodInfoObj);
    if (isAuthorized) {
        Assert.assertEquals(isAuthorized, true);
    } else {
        Assert.assertEquals(isAuthorized, false);
    }
}
Also used : Response(org.wso2.msf4j.Response) HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) APIMgtSecurityException(org.wso2.carbon.apimgt.rest.api.common.exception.APIMgtSecurityException) ServiceMethodInfo(org.wso2.msf4j.ServiceMethodInfo) Request(org.wso2.msf4j.Request) RESTAPISecurityInterceptor(org.wso2.carbon.apimgt.rest.api.common.interceptors.RESTAPISecurityInterceptor) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) APIMgtSecurityException(org.wso2.carbon.apimgt.rest.api.common.exception.APIMgtSecurityException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)1 APIMgtSecurityException (org.wso2.carbon.apimgt.rest.api.common.exception.APIMgtSecurityException)1 RESTAPISecurityInterceptor (org.wso2.carbon.apimgt.rest.api.common.interceptors.RESTAPISecurityInterceptor)1 Request (org.wso2.msf4j.Request)1 Response (org.wso2.msf4j.Response)1 ServiceMethodInfo (org.wso2.msf4j.ServiceMethodInfo)1 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)1