File tree Expand file tree Collapse file tree 2 files changed +28
-4
lines changed
main/java/dev/aikido/agent_api/helpers/url Expand file tree Collapse file tree 2 files changed +28
-4
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ private BuildRouteFromUrl() {}
1212 private static final Pattern UUID_REGEX = Pattern .compile (
1313 "[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff" ,
1414 Pattern .CASE_INSENSITIVE );
15+ private static final Pattern OBJECT_ID_REGEX = Pattern .compile ("^[0-9a-f]{24}$" , Pattern .CASE_INSENSITIVE );
16+ private static final Pattern ULID_REGEX = Pattern .compile ("^[0-9A-HJKMNP-TV-Z]{26}$" , Pattern .CASE_INSENSITIVE );
1517 private static final Pattern NUMBER_REGEX = Pattern .compile ("^\\ d+$" );
1618 private static final Pattern DATE_REGEX = Pattern .compile ("^\\ d{4}-\\ d{2}-\\ d{2}|\\ d{2}-\\ d{2}-\\ d{4}$" );
1719 private static final Pattern EMAIL_REGEX = Pattern .compile (
@@ -57,6 +59,10 @@ private static String replaceUrlSegmentWithParam(String segment) {
5759 return ":number" ;
5860 } else if (segment .length () == 36 && UUID_REGEX .matcher (segment ).matches ()) {
5961 return ":uuid" ;
62+ } else if (segment .length () == 26 && ULID_REGEX .matcher (segment ).matches ()) {
63+ return ":ulid" ;
64+ } else if (segment .length () == 24 && OBJECT_ID_REGEX .matcher (segment ).matches ()) {
65+ return ":objectId" ;
6066 } else if (startsWithNumber && DATE_REGEX .matcher (segment ).matches ()) {
6167 return ":date" ;
6268 } else if (segment .contains ("@" ) && EMAIL_REGEX .matcher (segment ).matches ()) {
@@ -82,4 +88,4 @@ private static boolean isHash(String segment) {
8288 }
8389 return false ;
8490 }
85- }
91+ }
Original file line number Diff line number Diff line change 66import java .security .NoSuchAlgorithmException ;
77
88import static dev .aikido .agent_api .helpers .url .BuildRouteFromUrl .buildRouteFromUrl ;
9- import static org .junit .jupiter .api .Assertions .assertEquals ;
10- import static org .junit .jupiter .api .Assertions .assertNull ;
9+ import static org .junit .jupiter .api .Assertions .*;
1110
1211public class BuildRouteFromUrlTest {
1312
@@ -126,4 +125,23 @@ public void testReplaceHashes() {
126125 public void testReplaceSecrets () {
127126 assertEquals ("/confirm/:secret" , buildRouteFromUrl ("/confirm/CnJ4DunhYfv2db6T1FRfciRBHtlNKOYrjoz" ));
128127 }
129- }
128+
129+ @ Test
130+ public void testReplacesBsonObjectIds () {
131+ assertEquals ("/posts/:objectId" , buildRouteFromUrl ("/posts/66ec29159d00113616fc7184" ));
132+ // 25 characters :
133+ assertNotEquals ("/posts/:objectId" , buildRouteFromUrl ("/posts/66ec29159d00113616fc71845" ));
134+ // 23 characters :
135+ assertNotEquals ("/posts/:objectId" , buildRouteFromUrl ("/posts/66ec29159d00113616fc718" ));
136+ }
137+
138+ @ Test
139+ public void testReplacesUlidStrings () {
140+ assertEquals ("/posts/:ulid" , buildRouteFromUrl ("/posts/01ARZ3NDEKTSV4RRFFQ69G5FAV" ));
141+ assertEquals ("/posts/:ulid" , buildRouteFromUrl ("/posts/01arz3ndektsv4rrffq69g5fav" ));
142+ // 27 characters :
143+ assertNotEquals ("/posts/:ulid" , buildRouteFromUrl ("/posts/01arz3ndektsv4rrffq69g5favv" ));
144+ // 25 characters :
145+ assertNotEquals ("/posts/:ulid" , buildRouteFromUrl ("/posts/01arz3ndektsv4rrffq69g5fa" ));
146+ }
147+ }
You can’t perform that action at this time.
0 commit comments