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;
}
}));
}
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;
}
}));
}
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);
}
Aggregations