Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: expect resposne code for positive cases #3990

Open
wants to merge 5 commits into
base: v3.x.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.test.web.reactive.server.WebTestClient;
import org.zowe.apiml.util.categories.RateLimitTest;
import org.zowe.apiml.util.config.ConfigReader;
import org.zowe.apiml.util.http.HttpRequestUtils;
import reactor.netty.http.client.HttpClient;

Expand All @@ -31,7 +32,7 @@ public class InMemoryRateLimiterFilterFactoryIntegrationTest {

private static WebTestClient client;

final int bucketCapacity = 60;
final int bucketCapacity = ConfigReader.environmentConfiguration().getGatewayServiceConfiguration().getBucketCapacity();

@BeforeAll
static void setUpTester() {
Expand Down Expand Up @@ -67,22 +68,23 @@ void testRateLimitingWhenAllowedWithCookie() {
void testRateLimitingWhenExceeded() {
IntStream.range(0, bucketCapacity).parallel().forEach(i -> client.get()
.cookie("apimlAuthenticationToken", "validTokenValue")
.exchange());
.exchange().expectStatus().isOk());


client.get()
.cookie("apimlAuthenticationToken", "validTokenValue")
.exchange()
.expectStatus().isEqualTo(HttpStatus.TOO_MANY_REQUESTS)
.expectBody()
.jsonPath("$.messages[0].messageReason").isEqualTo("Connections limit exceeded.");;
.jsonPath("$.messages[0].messageReason").isEqualTo("Connections limit exceeded.");
}

@Test
void testRateLimiterAllowsAccessToAnotherUser() {
// the first user requires access
IntStream.range(0, bucketCapacity).parallel().forEach(i -> client.get()
.cookie("apimlAuthenticationToken", "theFirstUser")
.exchange());
.exchange().expectStatus().isOk());
//access should be denied
client.get()
.cookie("apimlAuthenticationToken", "theFirstUser")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static EnvironmentConfiguration environmentConfiguration() {
log.warn("Can't read service configuration from resource file, using default: http://localhost:10010", e);
Credentials credentials = new Credentials("user", "user");
GatewayServiceConfiguration gatewayServiceConfiguration
= new GatewayServiceConfiguration("https", "localhost", null, 10010, 10017, 1, "10010", ROUTED_SERVICE);
= new GatewayServiceConfiguration("https", "localhost", null, 10010, 10017, 1, "10010", ROUTED_SERVICE, 20);
CentralGatewayServiceConfiguration centralGatewayServiceConfiguration = new CentralGatewayServiceConfiguration("https", "localhost", 10010);
ZaasConfiguration zaasConfiguration = new ZaasConfiguration("https", "localhost", 10023, 1);
DiscoveryServiceConfiguration discoveryServiceConfiguration = new DiscoveryServiceConfiguration("https", "eureka", "password", "localhost","localhost", 10011,10021, 1);
Expand Down Expand Up @@ -115,6 +115,7 @@ public static EnvironmentConfiguration environmentConfiguration() {
configuration.getGatewayServiceConfiguration().setExternalPort(parseInt(System.getProperty("gateway.externalPort", String.valueOf(configuration.getGatewayServiceConfiguration().getExternalPort()))));
configuration.getGatewayServiceConfiguration().setInstances(parseInt(System.getProperty("gateway.instances", String.valueOf(configuration.getGatewayServiceConfiguration().getInstances()))));
configuration.getGatewayServiceConfiguration().setServicesEndpoint(System.getProperty("gateway.servicesEndpoint", configuration.getGatewayServiceConfiguration().getServicesEndpoint()));
configuration.getGatewayServiceConfiguration().setBucketCapacity(parseInt(System.getProperty("gateway.bucketCapacity", String.valueOf(configuration.getGatewayServiceConfiguration().getBucketCapacity()))));

CentralGatewayServiceConfiguration config = configuration.getCentralGatewayServiceConfiguration();
Optional.ofNullable(config).ifPresent(c -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ public class GatewayServiceConfiguration implements ServiceConfiguration {
private int instances;
private String internalPorts;
private String servicesEndpoint;
private int bucketCapacity;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ gatewayServiceConfiguration:
externalPort: 10030
instances: 1
servicesEndpoint: gateway/api/v1/services
bucketCapacity: 20
zaasConfiguration:
scheme: https
host: zaas-service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ gatewayServiceConfiguration:
externalPort: 10010
instances: 1
servicesEndpoint: gateway/api/v1/services
bucketCapacity: 20
centralGatewayServiceConfiguration:
scheme: https
host: central-gateway-service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ gatewayServiceConfiguration:
externalPort: 10010
instances: 2
servicesEndpoint: gateway/api/v1/services
bucketCapacity: 20
zaasConfiguration:
scheme: https
host: zaas-service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ gatewayServiceConfiguration:
externalPort: 10010
instances: 1
servicesEndpoint: gateway/api/v1/services
bucketCapacity: 20
centralGatewayServiceConfiguration:
scheme: https
host: localhost
Expand Down
Loading