use of org.ff4j.web.api.filter.ApiKey in project ff4j by ff4j.
the class ApiKeyBeanTest method ApiKeyinit.
@Test
public void ApiKeyinit() {
ApiKey ak = new ApiKey();
ak.setUserId("uid");
Assert.assertEquals("uid", ak.getUserId());
ak.setValue("val");
Assert.assertEquals("val", ak.getValue());
Date d = new Date();
ak.setExpirationTime(d);
Assert.assertEquals(d, ak.getExpirationTime());
}
use of org.ff4j.web.api.filter.ApiKey in project ff4j by ff4j.
the class ApiKeyValidatorFilterTest method testFilterApiKeyNotFound.
@Test(expected = WebApplicationException.class)
public void testFilterApiKeyNotFound() 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("13");
ak1.setExpirationTime(new Date(System.currentTimeMillis() + 100000));
initMap.put(ak1.getValue(), ak1);
ApiKeyValidatorFilter.setValidApiKeysMap(initMap);
ApiKeyValidatorFilter f1 = new ApiKeyValidatorFilter();
f1.filter(mockRequest);
}
use of org.ff4j.web.api.filter.ApiKey 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 org.ff4j.web.api.filter.ApiKey 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 org.ff4j.web.api.filter.ApiKey in project ff4j by ff4j.
the class ApiKeyValidatorFilterTest method testApiKeyValidaton.
@Test
public void testApiKeyValidaton() throws Exception {
Map<String, ApiKey> initMap = new HashMap<>();
ApiKey ak1 = new ApiKey();
ak1.setUserId("user1");
ak1.setValue("key1");
ak1.setExpirationTime(new Date(System.currentTimeMillis() + 20000));
initMap.put(ak1.getValue(), ak1);
new ApiKeyValidatorFilter(initMap);
Assert.assertTrue(ApiKeyValidatorFilter.getValidApiKeysMap().containsKey("key1"));
ApiKeyValidatorFilter.setValidApiKeysMap(initMap);
}
Aggregations