()
| 1052 | |
| 1053 | |
| 1054 | async def test_should_work_with_glob() -> None: |
| 1055 | def glob_to_regex(pattern: str) -> re.Pattern: |
| 1056 | return re.compile(glob_to_regex_pattern(pattern)) |
| 1057 | |
| 1058 | assert glob_to_regex("**/*.js").match("https://localhost:8080/foo.js") |
| 1059 | assert not glob_to_regex("**/*.css").match("https://localhost:8080/foo.js") |
| 1060 | assert not glob_to_regex("*.js").match( |
| 1061 | "https://localhost:8080/foo.js" |
| 1062 | ) # Doesn"t match path separator |
| 1063 | assert glob_to_regex("https://**/*.js").match("https://localhost:8080/foo.js") |
| 1064 | assert glob_to_regex("http://localhost:8080/simple/path.js").match( |
| 1065 | "http://localhost:8080/simple/path.js" |
| 1066 | ) |
| 1067 | assert glob_to_regex("**/{a,b}.js").match("https://localhost:8080/a.js") |
| 1068 | assert glob_to_regex("**/{a,b}.js").match("https://localhost:8080/b.js") |
| 1069 | assert not glob_to_regex("**/{a,b}.js").match("https://localhost:8080/c.js") |
| 1070 | |
| 1071 | assert glob_to_regex("**/*.{png,jpg,jpeg}").match("https://localhost:8080/c.jpg") |
| 1072 | assert glob_to_regex("**/*.{png,jpg,jpeg}").match("https://localhost:8080/c.jpeg") |
| 1073 | assert glob_to_regex("**/*.{png,jpg,jpeg}").match("https://localhost:8080/c.png") |
| 1074 | assert not glob_to_regex("**/*.{png,jpg,jpeg}").match( |
| 1075 | "https://localhost:8080/c.css" |
| 1076 | ) |
| 1077 | assert glob_to_regex("foo*").match("foo.js") |
| 1078 | assert not glob_to_regex("foo*").match("foo/bar.js") |
| 1079 | assert not glob_to_regex("http://localhost:3000/signin-oidc*").match( |
| 1080 | "http://localhost:3000/signin-oidc/foo" |
| 1081 | ) |
| 1082 | assert glob_to_regex("http://localhost:3000/signin-oidc*").match( |
| 1083 | "http://localhost:3000/signin-oidcnice" |
| 1084 | ) |
| 1085 | |
| 1086 | assert glob_to_regex("**/*.js").match("/foo.js") |
| 1087 | assert not glob_to_regex("asd/**.js").match("/foo.js") |
| 1088 | assert not glob_to_regex("**/*.js").match("bar_foo.js") |
| 1089 | |
| 1090 | # range [] is NOT supported |
| 1091 | assert glob_to_regex("**/api/v[0-9]").fullmatch("http://example.com/api/v[0-9]") |
| 1092 | assert not glob_to_regex("**/api/v[0-9]").fullmatch( |
| 1093 | "http://example.com/api/version" |
| 1094 | ) |
| 1095 | assert not glob_to_regex("**/api/v[0-9]").fullmatch( |
| 1096 | "http://example.com/api/v1" |
| 1097 | ) # Should not match if [] is literal |
| 1098 | |
| 1099 | # query params |
| 1100 | assert glob_to_regex("**/api\\?param").match("http://example.com/api?param") |
| 1101 | assert not glob_to_regex("**/api\\?param").match("http://example.com/api-param") |
| 1102 | |
| 1103 | assert glob_to_regex("**/three-columns/settings.html\\?**id=settings-**").match( |
| 1104 | "http://mydomain:8080/blah/blah/three-columns/settings.html?id=settings-e3c58efe-02e9-44b0-97ac-dd138100cf7c&blah" |
| 1105 | ) |
| 1106 | |
| 1107 | assert glob_to_regex("\\?").pattern == r"^\?$" |
| 1108 | assert glob_to_regex("\\").pattern == r"^\\$" |
| 1109 | assert glob_to_regex("\\\\").pattern == r"^\\$" |
| 1110 | assert glob_to_regex("\\[").pattern == r"^\[$" |
| 1111 | assert glob_to_regex("[a-z]").pattern == r"^\[a-z\]$" |
nothing calls this directly
no test coverage detected