Skip to content
Merged
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
11 changes: 10 additions & 1 deletion src/main/java/com/uid2/shared/util/HTTPPathMetricFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,16 @@ public static String filterPath(String actualPath, Set<String> pathSet) {
normalized = normalized.substring(0, normalized.length() - 1);
}
normalized = normalized.toLowerCase();
return pathSet == null || pathSet.isEmpty() || pathSet.contains(normalized) ? normalized : "/unknown";

if (pathSet == null || pathSet.isEmpty()) { return normalized; }

for (String path : pathSet) {
String pathRegex = path.replaceAll(":[^/]+", "[^/]+");
if (normalized.matches(pathRegex)) {
return path;
}
}
return "/unknown";
} catch (IllegalArgumentException e) {
return "/parsing_error";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

public class HTTPPathMetricFilterTest {
final Set<String> pathSet = Set.of("/v1/identity/map", "/token/refresh");
final Set<String> pathSet = Set.of("/v1/identity/map", "/token/refresh", "/list", "/list/:siteId/:keyId");

@ParameterizedTest
@ValueSource(strings = {
Expand All @@ -18,6 +18,7 @@ public class HTTPPathMetricFilterTest {
"/unknown-path",
"../",
"/v1/identity/map%55",
"/list/123",
})
void testPathFiltering_InvalidPaths_Unknown(String actualPath) {
String filteredPath = HTTPPathMetricFilter.filterPath(actualPath, pathSet);
Expand All @@ -28,6 +29,7 @@ void testPathFiltering_InvalidPaths_Unknown(String actualPath) {
@ValueSource(strings = {
"v1/identity/map?id=bad-escape-code%2",
"token/refresh?refresh_token=SOME_TOKEN<%=7485*4353%>",
"list/12%4/5435"
})
void testPathFiltering_InvalidPaths_ParsingError(String actualPath) {
String filteredPath = HTTPPathMetricFilter.filterPath(actualPath, pathSet);
Expand All @@ -44,6 +46,8 @@ void testPathFiltering_InvalidPaths_ParsingError(String actualPath) {
"/v1/identity/new/path/../../map, /v1/identity/map",
"token/refresh?refresh_token=123%20%23, /token/refresh",
"v1/identity/map?identity/../map/, /v1/identity/map",
"/list, /list",
"/list/123/key123, /list/:siteId/:keyId"

})
void testPathFiltering_ValidPaths_KnownEndpoints(String actualPath, String expectedFilteredPath) {
Expand Down
Loading