-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes #102: protect against metric tag explosion on unauthorized access
- Loading branch information
Ivan Senic
committed
Feb 14, 2023
1 parent
55bdf67
commit c83590b
Showing
4 changed files
with
91 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
src/test/java/io/stargate/sgv2/jsonapi/api/UnauthorizedMetricsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package io.stargate.sgv2.jsonapi.api; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.quarkus.test.junit.TestProfile; | ||
import io.restassured.http.ContentType; | ||
import io.stargate.sgv2.common.testprofiles.NoGlobalResourcesTestProfile; | ||
import io.stargate.sgv2.jsonapi.api.v1.CollectionResource; | ||
import io.stargate.sgv2.jsonapi.api.v1.NamespaceResource; | ||
import java.util.List; | ||
import org.junit.jupiter.api.Test; | ||
|
||
@QuarkusTest | ||
@TestProfile(NoGlobalResourcesTestProfile.Impl.class) | ||
public class UnauthorizedMetricsTest { | ||
|
||
@Test | ||
public void namespaceResource() { | ||
String json = | ||
""" | ||
{ | ||
"createCollection": { | ||
"name": "whatever" | ||
} | ||
} | ||
"""; | ||
|
||
// ensure namespace not in tags when no auth token used | ||
given() | ||
.contentType(ContentType.JSON) | ||
.body(json) | ||
.when() | ||
.post(NamespaceResource.BASE_PATH, "keyspace") | ||
.then() | ||
.statusCode(200); | ||
|
||
String metrics = given().when().get("/metrics").then().statusCode(200).extract().asString(); | ||
List<String> httpMetrics = | ||
metrics.lines().filter(line -> line.startsWith("http_server_requests_seconds")).toList(); | ||
|
||
assertThat(httpMetrics) | ||
.allSatisfy( | ||
line -> | ||
assertThat(line) | ||
.containsAnyOf( | ||
"uri=\"/v1\"", | ||
"uri=\"/v1/{namespace}\"", | ||
"uri=\"/v1/{namespace}/{collection}\"")); | ||
} | ||
|
||
@Test | ||
public void collectionResource() { | ||
String json = """ | ||
{ | ||
"find": { | ||
} | ||
} | ||
"""; | ||
|
||
// ensure namespace not in tags when no auth token used | ||
given() | ||
.contentType(ContentType.JSON) | ||
.body(json) | ||
.when() | ||
.post(CollectionResource.BASE_PATH, "keyspace", "collection") | ||
.then() | ||
.statusCode(200); | ||
|
||
String metrics = given().when().get("/metrics").then().statusCode(200).extract().asString(); | ||
List<String> httpMetrics = | ||
metrics.lines().filter(line -> line.startsWith("http_server_requests_seconds")).toList(); | ||
|
||
assertThat(httpMetrics) | ||
.allSatisfy( | ||
line -> | ||
assertThat(line) | ||
.containsAnyOf( | ||
"uri=\"/v1\"", | ||
"uri=\"/v1/{namespace}\"", | ||
"uri=\"/v1/{namespace}/{collection}\"")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,8 @@ | |
stargate: | ||
data-store: | ||
ignore-bridge: true | ||
|
||
# change test port from 8081 (used by other SG services) | ||
quarkus: | ||
http: | ||
test-port: 9080 | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
ivansenic
Contributor
|
can we make this 8083 please. I was going to do a PR for that.