|
8 | 8 |
|
9 | 9 | import static org.junit.jupiter.api.Assertions.assertEquals; |
10 | 10 |
|
11 | | -public class HTTPPathMetricFilterTest { |
| 11 | +public class HTTPPathMetricFilterTest { |
| 12 | + /* filterPathTests */ |
12 | 13 | final Set<String> pathSet = Set.of("/v1/identity/map", "/token/refresh", "/list", "/list/:siteId/:keyId"); |
13 | 14 |
|
14 | 15 | @ParameterizedTest |
@@ -54,4 +55,49 @@ void testPathFiltering_ValidPaths_KnownEndpoints(String actualPath, String expec |
54 | 55 | String filteredPath = HTTPPathMetricFilter.filterPath(actualPath, pathSet); |
55 | 56 | assertEquals(expectedFilteredPath, filteredPath); |
56 | 57 | } |
| 58 | + |
| 59 | + /* filterPathWithoutPathParameters tests */ |
| 60 | + final Set<String> pathSetWithoutParams = Set.of("/v1/identity/map", "/token/refresh", "/list"); |
| 61 | + |
| 62 | + @ParameterizedTest |
| 63 | + @ValueSource(strings = { |
| 64 | + "", |
| 65 | + "/", |
| 66 | + "/unknown-path", |
| 67 | + "../", |
| 68 | + "/v1/identity/map%55", |
| 69 | + "/list/123", |
| 70 | + }) |
| 71 | + void testPathFilteringWithoutPathParameters_InvalidPaths_Unknown(String actualPath) { |
| 72 | + String filteredPath = HTTPPathMetricFilter.filterPathWithoutPathParameters(actualPath, pathSetWithoutParams); |
| 73 | + assertEquals("/unknown", filteredPath); |
| 74 | + } |
| 75 | + |
| 76 | + @ParameterizedTest |
| 77 | + @ValueSource(strings = { |
| 78 | + "v1/identity/map?id=bad-escape-code%2", |
| 79 | + "token/refresh?refresh_token=SOME_TOKEN<%=7485*4353%>", |
| 80 | + "list/12%4/5435" |
| 81 | + }) |
| 82 | + void testPathFilteringWithoutPathParameters_InvalidPaths_ParsingError(String actualPath) { |
| 83 | + String filteredPath = HTTPPathMetricFilter.filterPathWithoutPathParameters(actualPath, pathSetWithoutParams); |
| 84 | + assertEquals("/parsing_error", filteredPath); |
| 85 | + } |
| 86 | + |
| 87 | + @ParameterizedTest |
| 88 | + @CsvSource(value = { |
| 89 | + "/v1/identity/map, /v1/identity/map", |
| 90 | + "v1/identity/map, /v1/identity/map", |
| 91 | + "V1/IdenTity/mAp, /v1/identity/map", |
| 92 | + "./v1//identity//map/, /v1/identity/map", |
| 93 | + "../v1/identity/./map, /v1/identity/map", |
| 94 | + "/v1/identity/new/path/../../map, /v1/identity/map", |
| 95 | + "token/refresh?refresh_token=123%20%23, /token/refresh", |
| 96 | + "v1/identity/map?identity/../map/, /v1/identity/map", |
| 97 | + "/list, /list" |
| 98 | + }) |
| 99 | + void testPathFilteringWithoutPathParameters_ValidPaths_KnownEndpoints(String actualPath, String expectedFilteredPath) { |
| 100 | + String filteredPath = HTTPPathMetricFilter.filterPathWithoutPathParameters(actualPath, pathSetWithoutParams); |
| 101 | + assertEquals(expectedFilteredPath, filteredPath); |
| 102 | + } |
57 | 103 | } |
0 commit comments