@@ -871,3 +871,104 @@ func Test_handleError(t *testing.T) {
871
871
})
872
872
}
873
873
}
874
+
875
+ func Test_wildcardMatch (t * testing.T ) {
876
+ tests := []struct {
877
+ name string
878
+ pattern string
879
+ target string
880
+ want bool
881
+ }{
882
+ // basic cases
883
+ {"empty pattern and empty target" , "" , "" , true },
884
+ {"empty pattern and non-empty target" , "" , "test" , false },
885
+ {"non-empty pattern and empty target" , "test" , "" , false },
886
+ {"exact match" , "test" , "test" , true },
887
+ {"no match" , "test" , "different" , false },
888
+
889
+ // wildcard cases
890
+ {"single wildcard" , "*" , "anything" , true },
891
+ {"single wildcard empty" , "*" , "" , true },
892
+ {"prefix wildcard" , "test*" , "testing" , true },
893
+ {"prefix wildcard no match" , "test*" , "other" , false },
894
+ {"suffix wildcard" , "*test" , "mytest" , true },
895
+ {"suffix wildcard match" , "*test" , "testing" , true },
896
+ {"middle wildcard" , "te*st" , "test" , true },
897
+ {"middle wildcard complex" , "te*st" , "teXXXst" , true },
898
+ {"multiple wildcards" , "*test*" , "mytestcase" , true },
899
+
900
+ // edge cases
901
+ {"pattern with consecutive wildcards" , "test**case" , "testcase" , true },
902
+ {"pattern starting with wildcard" , "*test" , "test" , true },
903
+ {"pattern ending with wildcard" , "test*" , "test" , true },
904
+ {"complex pattern" , "a*b*c" , "aXbYc" , true },
905
+ {"complex pattern no match" , "a*b*c" , "aXcYb" , false },
906
+
907
+ // security-related path examples
908
+ {"API path wildcard" , "/api/*/users" , "/api/v1/users" , true },
909
+ {"health check path" , "/health*" , "/healthz" , true },
910
+ {"domain wildcard" , "*.example.com" , "api.example.com" , true },
911
+ }
912
+
913
+ for _ , tt := range tests {
914
+ t .Run (tt .name , func (t * testing.T ) {
915
+ if got := wildcardMatch (tt .pattern , tt .target ); got != tt .want {
916
+ t .Errorf ("wildcardMatch(%q, %q) = %v, want %v" ,
917
+ tt .pattern , tt .target , got , tt .want )
918
+ }
919
+ })
920
+ }
921
+ }
922
+
923
+ func Test_trimBearer (t * testing.T ) {
924
+ tests := []struct {
925
+ name string
926
+ in string
927
+ want string
928
+ }{
929
+ {
930
+ name : "Uppercase Bearer" ,
931
+ in : "Bearer abc123" ,
932
+ want : "abc123" ,
933
+ },
934
+ {
935
+ name : "Lowercase bearer" ,
936
+ in : "bearer xyz456" ,
937
+ want : "xyz456" ,
938
+ },
939
+ {
940
+ name : "Not a bearer prefix" ,
941
+ in : "ABC abc123" ,
942
+ want : "ABC abc123" ,
943
+ },
944
+ {
945
+ name : "Too short string" ,
946
+ in : "Beare " ,
947
+ want : "Beare " ,
948
+ },
949
+ {
950
+ name : "Bearer but no space after" ,
951
+ in : "Bearerabc123" ,
952
+ want : "Bearerabc123" ,
953
+ },
954
+ {
955
+ name : "bearer but no token" ,
956
+ in : "bearer " ,
957
+ want : "" ,
958
+ },
959
+ {
960
+ name : "Bearer but no token" ,
961
+ in : "Bearer " ,
962
+ want : "" ,
963
+ },
964
+ }
965
+
966
+ for _ , tt := range tests {
967
+ t .Run (tt .name , func (t * testing.T ) {
968
+ got := trimBearer (tt .in )
969
+ if got != tt .want {
970
+ t .Errorf ("trimBearer(%q) = %q; want %q" , tt .in , got , tt .want )
971
+ }
972
+ })
973
+ }
974
+ }
0 commit comments