Search in sources :

Example 11 with Plan

use of io.gravitee.gateway.handlers.api.definition.Plan in project gravitee-gateway by gravitee-io.

the class ApiKeyRepositoryRefresherTest method shouldInitWithNonRevokedApiKey_lowerCase.

@Test
public void shouldInitWithNonRevokedApiKey_lowerCase() throws TechnicalException {
    Mockito.when(plan.getSecurity()).thenReturn(io.gravitee.repository.management.model.Plan.PlanSecurityType.API_KEY.name().toLowerCase());
    List<Plan> plans = Collections.singletonList(plan);
    Mockito.when(api.getPlans()).thenReturn(plans);
    refresher.initialize();
    refresher.run();
    Mockito.verify(apiKeyRepository).findByCriteria(Matchers.argThat(new ArgumentMatcher<ApiKeyCriteria>() {

        @Override
        public boolean matches(Object arg) {
            ApiKeyCriteria criteria = (ApiKeyCriteria) arg;
            return !criteria.isIncludeRevoked() && criteria.getFrom() == 0 && criteria.getTo() == 0 && criteria.getPlans().size() == 1;
        }
    }));
}
Also used : ApiKeyCriteria(io.gravitee.repository.management.api.search.ApiKeyCriteria) Plan(io.gravitee.gateway.handlers.api.definition.Plan) Test(org.junit.Test)

Example 12 with Plan

use of io.gravitee.gateway.handlers.api.definition.Plan in project gravitee-gateway by gravitee-io.

the class ApiKeyRepositoryRefresherTest method shouldInitWithNonRevokedApiKey.

@Test
public void shouldInitWithNonRevokedApiKey() throws TechnicalException {
    Mockito.when(plan.getSecurity()).thenReturn(io.gravitee.repository.management.model.Plan.PlanSecurityType.API_KEY.name());
    List<Plan> plans = Collections.singletonList(plan);
    Mockito.when(api.getPlans()).thenReturn(plans);
    refresher.initialize();
    refresher.run();
    Mockito.verify(apiKeyRepository).findByCriteria(Matchers.argThat(new ArgumentMatcher<ApiKeyCriteria>() {

        @Override
        public boolean matches(Object arg) {
            ApiKeyCriteria criteria = (ApiKeyCriteria) arg;
            return !criteria.isIncludeRevoked() && criteria.getFrom() == 0 && criteria.getTo() == 0 && criteria.getPlans().size() == 1;
        }
    }));
}
Also used : ApiKeyCriteria(io.gravitee.repository.management.api.search.ApiKeyCriteria) Plan(io.gravitee.gateway.handlers.api.definition.Plan) Test(org.junit.Test)

Example 13 with Plan

use of io.gravitee.gateway.handlers.api.definition.Plan in project gravitee-gateway by gravitee-io.

the class ApiKeyRepositoryRefresherTest method shouldRefreshWithRevokedApiKeyAndRemoveFromCache.

@Test
public void shouldRefreshWithRevokedApiKeyAndRemoveFromCache() throws TechnicalException {
    String apiKey = "1234-4567-7890";
    Mockito.when(plan.getSecurity()).thenReturn(io.gravitee.repository.management.model.Plan.PlanSecurityType.API_KEY.name());
    List<Plan> plans = Collections.singletonList(plan);
    Mockito.when(api.getPlans()).thenReturn(plans);
    ApiKey apiKey1 = Mockito.mock(ApiKey.class);
    Mockito.when(apiKey1.getKey()).thenReturn(apiKey);
    Mockito.when(apiKey1.isRevoked()).thenReturn(false);
    ApiKey apiKey2 = Mockito.mock(ApiKey.class);
    Mockito.when(apiKey2.getKey()).thenReturn(apiKey);
    Mockito.when(apiKey2.isRevoked()).thenReturn(true);
    Mockito.when(apiKeyRepository.findByCriteria(Mockito.any(ApiKeyCriteria.class))).thenReturn(Collections.singletonList(apiKey1)).thenReturn(Collections.singletonList(apiKey2));
    refresher.initialize();
    refresher.run();
    refresher.run();
    InOrder inOrder = Mockito.inOrder(apiKeyRepository, apiKeyRepository);
    inOrder.verify(apiKeyRepository).findByCriteria(Matchers.argThat(new ArgumentMatcher<ApiKeyCriteria>() {

        @Override
        public boolean matches(Object arg) {
            ApiKeyCriteria criteria = (ApiKeyCriteria) arg;
            return !criteria.isIncludeRevoked() && criteria.getFrom() == 0 && criteria.getTo() == 0 && criteria.getPlans().size() == 1;
        }
    }));
    inOrder.verify(apiKeyRepository).findByCriteria(Matchers.argThat(new ArgumentMatcher<ApiKeyCriteria>() {

        @Override
        public boolean matches(Object arg) {
            ApiKeyCriteria criteria = (ApiKeyCriteria) arg;
            return criteria.isIncludeRevoked() && criteria.getFrom() != 0 && criteria.getTo() != 0 && criteria.getPlans().size() == 1;
        }
    }));
    InOrder inOrderCache = Mockito.inOrder(cache, cache);
    inOrderCache.verify(cache).put(Matchers.any(Element.class));
    inOrderCache.verify(cache).remove(apiKey);
}
Also used : ApiKeyCriteria(io.gravitee.repository.management.api.search.ApiKeyCriteria) ApiKey(io.gravitee.repository.management.model.ApiKey) Element(net.sf.ehcache.Element) Plan(io.gravitee.gateway.handlers.api.definition.Plan) Test(org.junit.Test)

Aggregations

Plan (io.gravitee.gateway.handlers.api.definition.Plan)13 Test (org.junit.Test)8 ApiKeyCriteria (io.gravitee.repository.management.api.search.ApiKeyCriteria)5 Path (io.gravitee.definition.model.Path)2 Api (io.gravitee.gateway.handlers.api.definition.Api)2 ValidationException (io.gravitee.gateway.handlers.api.validator.ValidationException)2 AuthenticationHandler (io.gravitee.gateway.security.core.AuthenticationHandler)2 ApiKey (io.gravitee.repository.management.model.ApiKey)2 Element (net.sf.ehcache.Element)2 HttpStatusCode (io.gravitee.common.http.HttpStatusCode)1 ExecutionContext (io.gravitee.gateway.api.ExecutionContext)1 Request (io.gravitee.gateway.api.Request)1 Response (io.gravitee.gateway.api.Response)1 ApiDefinitionBuilder (io.gravitee.gateway.handlers.api.builders.ApiDefinitionBuilder)1 ProxyDefinitionBuilder (io.gravitee.gateway.handlers.api.builders.ProxyDefinitionBuilder)1 io.gravitee.gateway.policy (io.gravitee.gateway.policy)1 PolicyChain (io.gravitee.gateway.policy.impl.PolicyChain)1 RequestPolicyChain (io.gravitee.gateway.policy.impl.RequestPolicyChain)1 ResponsePolicyChain (io.gravitee.gateway.policy.impl.ResponsePolicyChain)1 PolicyResult (io.gravitee.policy.api.PolicyResult)1