Browse Source

fix(rules): use get_path when testing url against rule and data (#48227)

Resolves SENTRY-10TJ
Gilbert Szeto 1 year ago
parent
commit
b40c911384
2 changed files with 6 additions and 7 deletions
  1. 1 4
      src/sentry/ownership/grammar.py
  2. 5 3
      tests/sentry/ownership/test_grammar.py

+ 1 - 4
src/sentry/ownership/grammar.py

@@ -163,10 +163,7 @@ class Matcher(namedtuple("Matcher", "type pattern")):
         if not isinstance(data, Mapping):
             return False
 
-        try:
-            url = data["request"]["url"]
-        except KeyError:
-            return False
+        url = get_path(data, "request", "url")
         return url and bool(glob_match(url, self.pattern, ignorecase=True))
 
     def test_frames(

+ 5 - 3
tests/sentry/ownership/test_grammar.py

@@ -132,9 +132,11 @@ def test_matcher_test_url():
     assert not Matcher("url", "*.js").test({})
 
 
-def test_matcher_test_none():
-    data = {"request": {"url": None}}
-    assert not Matcher("url", "").test(data)
+def test_matcher_test_url_none():
+    assert not Matcher("url", "doesnt_matter").test(None)
+    assert not Matcher("url", "doesnt_matter").test({})
+    assert not Matcher("url", "doesnt_matter").test({"request": None})
+    assert not Matcher("url", "doesnt_matter").test({"request": {"url": None}})
 
 
 def test_matcher_test_exception():