Skip to content

Commit

Permalink
Make paths to expected results more explicit by adding the /test/ p…
Browse files Browse the repository at this point in the history
…refix to expected results.

Fixes #8

PiperOrigin-RevId: 497965760
Change-Id: Ib52163b5b14bc9a17f9f9f14f2dc7eae07a1a39b
  • Loading branch information
Maciej Trzos authored and Copybara-Service committed Dec 27, 2022
1 parent fd55f14 commit e2a2367
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 90 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ returns:

```
[
"/html/body/form/action.found",
"/html/body/form/button/formaction.found"
"/test/html/body/form/action.found",
"/test/html/body/form/button/formaction.found"
]
```

Expand Down
15 changes: 10 additions & 5 deletions blueprints/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,28 @@
EXPECTED_RESULTS_FILE = open(
os.path.join(ROOT_DIR, "resources/expected-results.json"), "r")
EXPECTED_RESULTS = json.load(EXPECTED_RESULTS_FILE)
# Remove trailing slash, join expexted paths with "|" and escape dots.
PATHS_REGEX_STRING = "|".join(
[re.sub(r"^/", "", item) for item in EXPECTED_RESULTS]).replace(".", r"\.")
# Results that don't start with '/test' should not
# be handled by the valid_resource route.
EXPECTED_RESULTS_WITH_TEST_PREFIX = filter(lambda r: r.startswith("/test/"),
EXPECTED_RESULTS)
# Remove the '/test/' prefix, join expexted paths with "|" and escape dots.
PATHS_REGEX_STRING = "|".join([
re.sub(r"^/test/", "", item) for item in EXPECTED_RESULTS_WITH_TEST_PREFIX
]).replace(".", r"\.")
PATH_REGEX = re.compile("^(" + PATHS_REGEX_STRING + ")$")


@utils_module.route("/fetch-expected-results")
def fetch_expected_results():
"""Returns a list of expected findings from a starting path."""
response_results = []
path = request.args.get("path", "")
path = request.args.get("path", "").lstrip("/")

if not path:
return Response("Please, provide the path parameter.", 400)

for result in EXPECTED_RESULTS:
if result.startswith(path):
if result.lstrip("/test").startswith(path):
response_results.append(result)

return jsonify(response_results)
Expand Down
166 changes: 83 additions & 83 deletions blueprints/utils/resources/expected-results.json
Original file line number Diff line number Diff line change
@@ -1,93 +1,93 @@
[
"/css/font-face.found",
"/headers/content-location.found",
"/headers/link.found",
"/headers/location.found",
"/headers/refresh.found",
"/html/doctype.found",
"/html/manifest.found",
"/html/body/background.found",
"/html/body/a/href.found",
"/html/body/a/ping.found",
"/html/body/audio/src.found",
"/html/body/audio/source/src.found",
"/html/body/audio/source/srcset1x.found",
"/html/body/audio/source/srcset2x.found",
"/html/body/applet/archive.found",
"/html/body/applet/codebase.found",
"/html/body/blockquote/cite.found",
"/html/body/embed/src.found",
"/html/body/form/action-get.found",
"/html/body/form/action-post.found",
"/html/body/form/button/formaction.found",
"/html/body/frameset/frame/src.found",
"/html/body/iframe/src.found",
"/html/body/iframe/srcdoc.found",
"/html/body/img/dynsrc.found",
"/html/body/img/lowsrc.found",
"/html/body/img/longdesc.found",
"/html/body/img/src-data.found",
"/html/body/img/src.found",
"/html/body/img/srcset1x.found",
"/html/body/img/srcset2x.found",
"/html/body/input/src.found",
"/html/body/isindex/action.found",
"/html/body/map/area/ping.found",
"/html/body/object/data.found",
"/html/body/object/codebase.found",
"/html/body/object/param/value.found",
"/html/body/script/src.found",
"/html/body/svg/image/xlink.found",
"/html/body/svg/script/xlink.found",
"/html/body/table/background.found",
"/html/body/table/td/background.found",
"/html/body/video/src.found",
"/html/body/video/track/src.found",
"/html/body/video/poster.found",
"/html/head/profile.found",
"/html/head/base/href.found",
"/html/head/comment-conditional.found",
"/html/head/import/implementation.found",
"/html/head/link/href.found",
"/html/head/meta/content-csp.found",
"/html/head/meta/content-pinned-websites.found",
"/html/head/meta/content-reading-view.found",
"/html/head/meta/content-redirect.found",
"/html/misc/url/full-url.found",
"/html/misc/url/path-relative-url.found",
"/html/misc/url/protocol-relative-url.found",
"/html/misc/url/root-relative-url.found",
"/html/misc/string/dot-dot-slash-prefix.found",
"/html/misc/string/dot-slash-prefix.found",
"/html/misc/string/url-string.found",
"/html/misc/string/string-known-extension.pdf",
"/javascript/misc/automatic-post.found",
"/javascript/misc/comment.found",
"/javascript/misc/string-variable.found",
"/javascript/misc/string-concat-variable.found",
"/javascript/frameworks/angular/event-handler.found",
"/javascript/frameworks/angular/router-outlet.found",
"/javascript/frameworks/angularjs/ng-href.found",
"/javascript/frameworks/polymer/event-handler.found",
"/javascript/frameworks/polymer/polymer-router.found",
"/javascript/frameworks/react/route-path.found",
"/javascript/frameworks/react/index.html/search.found",
"/javascript/interactive/js-delete.found",
"/javascript/interactive/js-post.found",
"/javascript/interactive/js-post-event-listener.found",
"/javascript/interactive/js-put.found",
"/javascript/interactive/listener-and-event-attribute-first.found",
"/javascript/interactive/listener-and-event-attribute-second.found",
"/javascript/interactive/multi-step-request-event-attribute.found",
"/javascript/frameworks/react/route-path.found",
"/test/css/font-face.found",
"/test/headers/content-location.found",
"/test/headers/link.found",
"/test/headers/location.found",
"/test/headers/refresh.found",
"/test/html/body/a/href.found",
"/test/html/body/a/ping.found",
"/test/html/body/applet/archive.found",
"/test/html/body/applet/codebase.found",
"/test/html/body/audio/source/src.found",
"/test/html/body/audio/source/srcset1x.found",
"/test/html/body/audio/source/srcset2x.found",
"/test/html/body/audio/src.found",
"/test/html/body/background.found",
"/test/html/body/blockquote/cite.found",
"/test/html/body/embed/src.found",
"/test/html/body/form/action-get.found",
"/test/html/body/form/action-post.found",
"/test/html/body/form/button/formaction.found",
"/test/html/body/frameset/frame/src.found",
"/test/html/body/iframe/src.found",
"/test/html/body/iframe/srcdoc.found",
"/test/html/body/img/dynsrc.found",
"/test/html/body/img/longdesc.found",
"/test/html/body/img/lowsrc.found",
"/test/html/body/img/src-data.found",
"/test/html/body/img/src.found",
"/test/html/body/img/srcset1x.found",
"/test/html/body/img/srcset2x.found",
"/test/html/body/input/src.found",
"/test/html/body/isindex/action.found",
"/test/html/body/map/area/ping.found",
"/test/html/body/object/codebase.found",
"/test/html/body/object/data.found",
"/test/html/body/object/param/value.found",
"/test/html/body/script/src.found",
"/test/html/body/svg/image/xlink.found",
"/test/html/body/svg/script/xlink.found",
"/test/html/body/table/background.found",
"/test/html/body/table/td/background.found",
"/test/html/body/video/poster.found",
"/test/html/body/video/src.found",
"/test/html/body/video/track/src.found",
"/test/html/doctype.found",
"/test/html/head/base/href.found",
"/test/html/head/comment-conditional.found",
"/test/html/head/import/implementation.found",
"/test/html/head/link/href.found",
"/test/html/head/meta/content-csp.found",
"/test/html/head/meta/content-pinned-websites.found",
"/test/html/head/meta/content-reading-view.found",
"/test/html/head/meta/content-redirect.found",
"/test/html/head/profile.found",
"/test/html/manifest.found",
"/test/html/misc/string/dot-dot-slash-prefix.found",
"/test/html/misc/string/dot-slash-prefix.found",
"/test/html/misc/string/string-known-extension.pdf",
"/test/html/misc/string/url-string.found",
"/test/html/misc/url/full-url.found",
"/test/html/misc/url/path-relative-url.found",
"/test/html/misc/url/protocol-relative-url.found",
"/test/html/misc/url/root-relative-url.found",
"/test/javascript/interactive/js-delete.found",
"/test/javascript/interactive/js-post-event-listener.found",
"/test/javascript/interactive/js-post.found",
"/test/javascript/interactive/js-put.found",
"/test/javascript/interactive/listener-and-event-attribute-first.found",
"/test/javascript/interactive/listener-and-event-attribute-second.found",
"/test/javascript/interactive/multi-step-request-event-attribute.found",
"/test/javascript/interactive/multi-step-request-event-listener-div-dom.found",
"/test/javascript/interactive/multi-step-request-event-listener-div.found",
"/javascript/interactive/multi-step-request-event-listener-dom.found",
"/javascript/interactive/multi-step-request-event-listener.found",
"/javascript/interactive/multi-step-request-redefine-event-attribute.found",
"/javascript/interactive/multi-step-request-remove-button.found",
"/javascript/interactive/multi-step-request-remove-event-listener.found",
"/javascript/interactive/two-listeners-first.found",
"/javascript/interactive/two-listeners-second.found",
"/misc/known-files/robots.txt.found",
"/misc/known-files/sitemap.xml.found"
"/test/javascript/interactive/multi-step-request-event-listener-dom.found",
"/test/javascript/interactive/multi-step-request-event-listener.found",
"/test/javascript/interactive/multi-step-request-redefine-event-attribute.found",
"/test/javascript/interactive/multi-step-request-remove-button.found",
"/test/javascript/interactive/multi-step-request-remove-event-listener.found",
"/test/javascript/interactive/two-listeners-first.found",
"/test/javascript/interactive/two-listeners-second.found",
"/test/javascript/misc/automatic-post.found",
"/test/javascript/misc/comment.found",
"/test/javascript/misc/string-concat-variable.found",
"/test/javascript/misc/string-variable.found",
"/test/misc/known-files/robots.txt.found",
"/test/misc/known-files/sitemap.xml.found"
]

0 comments on commit e2a2367

Please sign in to comment.