|
| 1 | +package com.uid2.shared.util; |
| 2 | + |
| 3 | +import org.junit.jupiter.params.ParameterizedTest; |
| 4 | +import org.junit.jupiter.params.provider.CsvSource; |
| 5 | +import org.junit.jupiter.params.provider.ValueSource; |
| 6 | + |
| 7 | +import java.util.Set; |
| 8 | + |
| 9 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 10 | + |
| 11 | +public class HTTPPathMetricFilterTest { |
| 12 | + final Set<String> pathSet = Set.of("/v1/identity/map", "/token/refresh"); |
| 13 | + |
| 14 | + @ParameterizedTest |
| 15 | + @ValueSource(strings = { |
| 16 | + "", |
| 17 | + "/", |
| 18 | + "/unknown-path", |
| 19 | + "../", |
| 20 | + "/v1/identity/map%55", |
| 21 | + }) |
| 22 | + void testPathFiltering_InvalidPaths_Unknown(String actualPath) { |
| 23 | + String filteredPath = HTTPPathMetricFilter.filterPath(actualPath, pathSet); |
| 24 | + assertEquals("/unknown", filteredPath); |
| 25 | + } |
| 26 | + |
| 27 | + @ParameterizedTest |
| 28 | + @ValueSource(strings = { |
| 29 | + "v1/identity/map?id=bad-escape-code%2", |
| 30 | + "token/refresh?refresh_token=SOME_TOKEN<%=7485*4353%>", |
| 31 | + }) |
| 32 | + void testPathFiltering_InvalidPaths_ParsingError(String actualPath) { |
| 33 | + String filteredPath = HTTPPathMetricFilter.filterPath(actualPath, pathSet); |
| 34 | + assertEquals("/parsing_error", filteredPath); |
| 35 | + } |
| 36 | + |
| 37 | + @ParameterizedTest |
| 38 | + @CsvSource(value = { |
| 39 | + "/v1/identity/map, /v1/identity/map", |
| 40 | + "v1/identity/map, /v1/identity/map", |
| 41 | + "V1/IdenTity/mAp, /v1/identity/map", |
| 42 | + "./v1//identity//map/, /v1/identity/map", |
| 43 | + "../v1/identity/./map, /v1/identity/map", |
| 44 | + "/v1/identity/new/path/../../map, /v1/identity/map", |
| 45 | + "token/refresh?refresh_token=123%20%23, /token/refresh", |
| 46 | + "v1/identity/map?identity/../map/, /v1/identity/map", |
| 47 | + |
| 48 | + }) |
| 49 | + void testPathFiltering_ValidPaths_KnownEndpoints(String actualPath, String expectedFilteredPath) { |
| 50 | + String filteredPath = HTTPPathMetricFilter.filterPath(actualPath, pathSet); |
| 51 | + assertEquals(expectedFilteredPath, filteredPath); |
| 52 | + } |
| 53 | +} |
0 commit comments