use of javax.ws.rs.container.ContainerRequestContext in project ff4j by ff4j.
the class SecurityAuthorizationFilterTest method testRoleAllowed.
@Test
public void testRoleAllowed() throws IOException {
// Given
FF4jAuthorizationFilter faf = new FF4jAuthorizationFilter();
ContainerRequestContext mockRequest = mock(ContainerRequestContext.class);
UriInfo mockUriInfo = mock(UriInfo.class);
ResourceInfo mockResInfo = new ResourceInfo() {
public Method getResourceMethod() {
return methodRole;
}
public Class<?> getResourceClass() {
return targetResource;
}
};
faf.setInfo(mockResInfo);
when(mockUriInfo.getPath()).thenReturn("localhost");
when(mockRequest.getSecurityContext()).thenReturn(new FF4jSecurityContext("user", "", Util.set("USER")));
when(mockRequest.getUriInfo()).thenReturn(mockUriInfo);
// When
faf.filter(mockRequest);
// Then expecte 403
}
use of javax.ws.rs.container.ContainerRequestContext in project ff4j by ff4j.
the class ApiKeyValidatorFilterTest method testFilterApiKeyExpired.
@Test(expected = WebApplicationException.class)
public void testFilterApiKeyExpired() throws Exception {
ContainerRequestContext mockRequest = mock(ContainerRequestContext.class);
MultivaluedMap<String, String> mvm = new MultivaluedHashMap<>();
mvm.putSingle(ApiKeyValidatorFilter.HEADER_APIKEY, "12");
when(mockRequest.getHeaders()).thenReturn(mvm);
// create valid KEY to test against
Map<String, ApiKey> initMap = new HashMap<>();
ApiKey ak1 = new ApiKey();
ak1.setUserId("user1");
ak1.setValue("12");
ak1.setExpirationTime(new Date(System.currentTimeMillis() - 100000));
initMap.put(ak1.getValue(), ak1);
ApiKeyValidatorFilter.setValidApiKeysMap(initMap);
ApiKeyValidatorFilter f1 = new ApiKeyValidatorFilter();
f1.filter(mockRequest);
}
use of javax.ws.rs.container.ContainerRequestContext in project ff4j by ff4j.
the class ApiKeyValidatorFilterTest method testFilterOK.
@Test
public void testFilterOK() throws Exception {
ContainerRequestContext mockRequest = mock(ContainerRequestContext.class);
MultivaluedMap<String, String> mvm = new MultivaluedHashMap<>();
mvm.putSingle(ApiKeyValidatorFilter.HEADER_APIKEY, "12");
when(mockRequest.getHeaders()).thenReturn(mvm);
// create valid KEY to test against
Map<String, ApiKey> initMap = new HashMap<>();
ApiKey ak1 = new ApiKey();
ak1.setUserId("user1");
ak1.setValue("12");
ak1.setExpirationTime(new Date(System.currentTimeMillis() + 100000));
initMap.put(ak1.getValue(), ak1);
ApiKeyValidatorFilter.setValidApiKeysMap(initMap);
ApiKeyValidatorFilter f1 = new ApiKeyValidatorFilter();
f1.filter(mockRequest);
}
use of javax.ws.rs.container.ContainerRequestContext in project ff4j by ff4j.
the class ApiKeyValidatorFilterTest method testFilterNondeader.
@Test(expected = WebApplicationException.class)
public void testFilterNondeader() throws Exception {
ContainerRequestContext mockRequest = mock(ContainerRequestContext.class);
MultivaluedMap<String, String> mvm = new MultivaluedHashMap<>();
when(mockRequest.getHeaders()).thenReturn(mvm);
ApiKeyValidatorFilter f1 = new ApiKeyValidatorFilter();
f1.filter(mockRequest);
}
use of javax.ws.rs.container.ContainerRequestContext in project ff4j by ff4j.
the class SecurityAuthenticationFilterTest method testUnAuthorizedInvalidValue.
@Test(expected = WebApplicationException.class)
public void testUnAuthorizedInvalidValue() throws IOException {
// Given
FF4jAuthenticationFilter faf = new FF4jAuthenticationFilter();
ContainerRequestContext mockRequest = mock(ContainerRequestContext.class);
when(mockRequest.getHeaderString("Authorization")).thenReturn("12");
when(mockRequest.getMethod()).thenReturn("GET");
UriInfo mockUriInfo = mock(UriInfo.class);
when(mockUriInfo.getPath()).thenReturn("someURL");
when(mockRequest.getUriInfo()).thenReturn(mockUriInfo);
faf.filter(mockRequest);
}
Aggregations