Commit 52536633 authored by Hiroshige Hayashizaki's avatar Hiroshige Hayashizaki Committed by Commit Bot

[WPT/common/security-features] Move per-project config into spec.src.json

[1] will enable sub projects inheriting parent's `spec.src.json`,
in order to generate similar but subtlely different tests.
As a preparation for [1],
this CL centralizes per-project configs into `spec.src.json`,
by moving config values from per-project `generate.py` into `spec.src.json`.

- `spec_directory` is now the current directory,
  or specified by the `--spec` command line option,
  while previously it is calculated based on the per-project `generate.py`'s path.
- Script paths (`helper_js`, `sanity_checker_js`, `spec_json_js`) are now hard-coded
  (using `spec_directory`) in `common/security-features/tools/generate.py`.
- Other config values are moved into `spec.src.json`.
- `spec_json.js` is moved under `generic/`, to a little centralize
  generator-related files into `generic/`.

Generated files are affected because:

- Scripts (like `test-case.sub.js`) are now referenced as relative paths
  from generated test HTMLs.
- `disclaimer.template` is updated.

Generated files will be updated in a separate CL [2].

[1] https://chromium-review.googlesource.com/c/chromium/src/+/1991066/
[2] https://chromium-review.googlesource.com/c/chromium/src/+/1992955/

Bug: 906850
Change-Id: Id3b2a26b67296a1de2b682e07bdcf473f666cd25
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1989718
Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org>
Reviewed-by: default avatarHiroki Nakagawa <nhiroki@chromium.org>
Cr-Commit-Position: refs/heads/master@{#731858}
parent e2b21b06
......@@ -39,28 +39,25 @@ project-directory/ (e.g. referrer-policy/)
├── spec.src.json
├── generic/
│ ├── test-case.sub.js - Per-project test helper
└── tools/
└── generator.py - Per-project generator script
├── sanity-checker.js (Used by debug target only)
└── spec_json.js (Used by debug target only)
└── gen/ - generated tests
```
Invoking `project-directory/generic/tools/generate.py` will parse the spec JSON and determine which tests to generate (or skip) while using templates.
## Generating the tests
The repository already contains generated tests, so if you're making changes, see the [Removing all generated tests](#removing-all-generated-tests) section below, on how to remove them before you start generating tests which include your changes.
Note: When the repository already contains generated tests, [remove all generated tests](#removing-all-generated-tests) first.
```bash
# Chdir into the project directory.
cd ~/web-platform-tests/project-directory
# Generate the test files under gen/ (HTMLs and .headers files).
./generic/tools/generate.py
path/to/common/security-features/tools/generate.py --spec path/to/project-directory/
# Add all generated tests to the repo.
git add gen/ && git commit -m "Add generated tests"
git add path/to/project-directory/gen/ && git commit -m "Add generated tests"
```
This will parse the spec JSON (`project-directory/spec.src.json`) and determine which tests to generate (or skip) while using templates.
During the generation, the spec is validated by ```common/security-features/tools/spec_validator.py```. This is specially important when you're making changes to `spec.src.json`. Make sure it's a valid JSON (no comments or trailing commas). The validator reports specific errors (missing keys etc.), if any.
### Removing all generated tests
......@@ -68,18 +65,14 @@ During the generation, the spec is validated by ```common/security-features/tool
Simply remove all files under `project-directory/gen/`.
```bash
# Chdir into the project directory.
cd ~/web-platform-tests/project-directory
# Remove all generated tests.
rm -r gen/
rm -r path/to/project-directory/gen/
```
### Options for generating tests
Note: this section is currently obsolete. Only the release template is working.
The generator script ```./generic/tools/generate.py``` has two targets: ```release``` and ```debug```.
The generator script has two targets: ```release``` and ```debug```.
* Using **release** for the target will produce tests using a template for optimizing size and performance. The release template is intended for the official web-platform-tests and possibly other test suites. No sanity checking is done in release mode. Use this option whenever you're checking into web-platform-tests.
......
#!/usr/bin/env python
from __future__ import print_function
import argparse
......@@ -64,7 +66,7 @@ def dump_test_parameters(selection):
cls=util.CustomEncoder)
def get_test_filename(config, selection):
def get_test_filename(spec_directory, spec_json, selection):
'''Returns the filname for the main test HTML file'''
selection_for_filename = copy.deepcopy(selection)
......@@ -72,8 +74,9 @@ def get_test_filename(config, selection):
if selection_for_filename['delivery_value'] is None:
selection_for_filename['delivery_value'] = 'unset'
return os.path.join(config.spec_directory,
config.test_file_path_pattern % selection_for_filename)
return os.path.join(
spec_directory,
spec_json['test_file_path_pattern'] % selection_for_filename)
def handle_deliveries(policy_deliveries):
......@@ -127,9 +130,9 @@ def handle_deliveries(policy_deliveries):
return {"meta": meta, "headers": headers}
def generate_selection(spec_json, config, selection, spec,
def generate_selection(spec_directory, spec_json, selection, spec,
test_html_template_basename):
test_filename = get_test_filename(config, selection)
test_filename = get_test_filename(spec_directory, spec_json, selection)
target_policy_delivery = util.PolicyDelivery(selection['delivery_type'],
selection['delivery_key'],
......@@ -175,17 +178,24 @@ def generate_selection(spec_json, config, selection, spec,
"\n", indent)
selection['spec_name'] = spec['name']
selection[
'test_page_title'] = config.test_page_title_template % spec['title']
selection['test_page_title'] = spec_json['test_page_title_template'] % spec
selection['spec_description'] = spec['description']
selection['spec_specification_url'] = spec['specification_url']
selection['helper_js'] = config.helper_js
selection['sanity_checker_js'] = config.sanity_checker_js
selection['spec_json_js'] = config.spec_json_js
test_headers_filename = test_filename + ".headers"
test_directory = os.path.dirname(test_filename)
selection['helper_js'] = os.path.relpath(
os.path.join(spec_directory, 'generic', 'test-case.sub.js'),
test_directory)
selection['sanity_checker_js'] = os.path.relpath(
os.path.join(spec_directory, 'generic', 'sanity-checker.js'),
test_directory)
selection['spec_json_js'] = os.path.relpath(
os.path.join(spec_directory, 'generic', 'spec_json.js'),
test_directory)
test_headers_filename = test_filename + ".headers"
test_html_template = util.get_template(test_html_template_basename)
disclaimer_template = util.get_template('disclaimer.template')
......@@ -194,13 +204,13 @@ def generate_selection(spec_json, config, selection, spec,
generated_disclaimer = disclaimer_template \
% {'generating_script_filename': os.path.relpath(sys.argv[0],
util.test_root_directory),
'html_template_filename': os.path.relpath(html_template_filename,
util.test_root_directory)}
'spec_directory': os.path.relpath(spec_directory,
util.test_root_directory)}
# Adjust the template for the test invoking JS. Indent it to look nice.
selection['generated_disclaimer'] = generated_disclaimer.rstrip()
selection[
'test_description'] = config.test_description_template % selection
selection['test_description'] = spec_json[
'test_description_template'] % selection
selection['test_description'] = \
selection['test_description'].rstrip().replace("\n", "\n" + " " * 33)
......@@ -227,12 +237,12 @@ def generate_selection(spec_json, config, selection, spec,
util.write_file(test_filename, test_html_template % selection)
def generate_test_source_files(config, spec_json, target):
def generate_test_source_files(spec_directory, spec_json, target):
test_expansion_schema = spec_json['test_expansion_schema']
specification = spec_json['specification']
spec_json_js_template = util.get_template('spec_json.js.template')
generated_spec_json_filename = os.path.join(config.spec_directory,
generated_spec_json_filename = os.path.join(spec_directory, "generic",
"spec_json.js")
util.write_file(
generated_spec_json_filename,
......@@ -251,7 +261,8 @@ def generate_test_source_files(config, spec_json, target):
expand_pattern(excluded_pattern, test_expansion_schema)
for excluded_selection in permute_expansion(excluded_expansion,
artifact_order):
excluded_selection_path = config.selection_pattern % excluded_selection
excluded_selection_path = spec_json[
'selection_pattern'] % excluded_selection
exclusion_dict[excluded_selection_path] = True
for spec in specification:
......@@ -264,7 +275,7 @@ def generate_test_source_files(config, spec_json, target):
test_expansion_schema)
for selection in permute_expansion(expansion, artifact_order):
selection['delivery_key'] = spec_json['delivery_key']
selection_path = config.selection_pattern % selection
selection_path = spec_json['selection_pattern'] % selection
if not selection_path in exclusion_dict:
if selection_path in output_dict:
if expansion_pattern['expansion'] != 'override':
......@@ -280,13 +291,13 @@ def generate_test_source_files(config, spec_json, target):
for selection_path in output_dict:
selection = output_dict[selection_path]
try:
generate_selection(spec_json, config, selection, spec,
generate_selection(spec_directory, spec_json, selection, spec,
html_template)
except util.ShouldSkip:
continue
def main(config):
def main():
parser = argparse.ArgumentParser(
description='Test suite generator utility')
parser.add_argument(
......@@ -300,16 +311,19 @@ def main(config):
'-s',
'--spec',
type=str,
default=None,
default=os.getcwd(),
help='Specify a file used for describing and generating the tests')
# TODO(kristijanburnik): Add option for the spec_json file.
args = parser.parse_args()
if args.spec:
config.spec_directory = args.spec
spec_directory = os.path.abspath(args.spec)
spec_filename = os.path.join(config.spec_directory, "spec.src.json")
spec_filename = os.path.join(spec_directory, "spec.src.json")
spec_json = util.load_spec_json(spec_filename)
spec_validator.assert_valid_spec_json(spec_json)
generate_test_source_files(config, spec_json, args.target)
generate_test_source_files(spec_directory, spec_json, args.target)
if __name__ == '__main__':
main()
......@@ -87,6 +87,8 @@ def validate(spec_json, details):
details['object'] = spec_json
assert_contains_only_fields(spec_json, [
"selection_pattern", "test_file_path_pattern",
"test_description_template", "test_page_title_template",
"specification", "delivery_key", "subresource_schema",
"source_context_schema", "source_context_list_schema",
"test_expansion_schema", "excluded_tests"
......
<!-- DO NOT EDIT! Generated by %(generating_script_filename)s using %(html_template_filename)s. -->
<!-- DO NOT EDIT! Generated by `%(generating_script_filename)s --spec %(spec_directory)s/` -->
var SPEC_JSON = {"subresource_schema": {"supported_delivery_type": {"picture-tag": [], "worklet-layout": [], "worklet-paint": [], "img-tag": [], "a-tag": [], "worklet-layout-import-data": [], "worklet-audio-import-data": [], "worklet-animation": [], "websocket": [], "worklet-paint-import-data": [], "video-tag": [], "object-tag": [], "worklet-audio": [], "beacon": [], "worker-module": [], "worker-import-data": [], "script-tag": [], "worklet-animation-import-data": [], "link-css-tag": [], "xhr": [], "worker-classic": [], "link-prefetch-tag": [], "audio-tag": [], "fetch": []}}, "source_context_list_schema": {"worker-classic-data": {"subresourcePolicyDeliveries": [], "sourceContextList": [{"sourceContextType": "top", "policyDeliveries": ["policy"]}, {"sourceContextType": "worker-classic-data", "policyDeliveries": []}]}, "top": {"subresourcePolicyDeliveries": [], "description": "Policy set by the top-level Document", "sourceContextList": [{"sourceContextType": "top", "policyDeliveries": ["policy"]}]}, "worker-module-data": {"subresourcePolicyDeliveries": [], "sourceContextList": [{"sourceContextType": "top", "policyDeliveries": ["policy"]}, {"sourceContextType": "worker-module-data", "policyDeliveries": []}]}}, "test_page_title_template": "Mixed-Content: %(title)s", "test_expansion_schema": {"delivery_value": [null, "opt-in"], "origin": ["same-https", "same-http", "cross-https", "cross-http", "same-wss", "same-ws", "cross-wss", "cross-ws"], "delivery_type": ["http-rp", "meta"], "subresource": {"blockable": ["script-tag", "link-css-tag", "xhr", "worker-classic", "worker-module", "worker-import-data", "worklet-animation", "worklet-audio", "worklet-layout", "worklet-paint", "worklet-animation-import-data", "worklet-audio-import-data", "worklet-layout-import-data", "worklet-paint-import-data", "fetch", "a-tag", "object-tag", "picture-tag", "websocket", "link-prefetch-tag", "beacon"], "optionally-blockable": ["img-tag", "audio-tag", "video-tag"]}, "expectation": ["allowed", "blocked"], "expansion": ["default", "override"], "redirection": ["no-redirect", "keep-scheme", "swap-scheme"], "source_context_list": ["top", "worker-classic-data", "worker-module-data"], "source_scheme": ["http", "https"]}, "selection_pattern": "%(source_context_list)s.%(delivery_type)s/%(delivery_value)s/%(subresource)s/%(origin)s.%(redirection)s.%(source_scheme)s", "specification": [{"test_expansion": [{"delivery_value": "opt-in", "origin": ["cross-http", "same-http"], "delivery_type": "*", "name": "opt-in-blocks", "expectation": "blocked", "expansion": "default", "redirection": "*", "source_context_list": "*", "source_scheme": "https", "subresource": {"blockable": [], "optionally-blockable": "*"}}, {"delivery_value": null, "origin": ["cross-http", "same-http"], "delivery_type": "*", "name": "no-opt-in-allows", "expectation": "allowed", "expansion": "default", "redirection": "*", "source_context_list": "*", "source_scheme": "https", "subresource": {"blockable": [], "optionally-blockable": "*"}}], "description": "Test behavior of optionally-blockable content", "specification_url": "http://www.w3.org/TR/mixed-content/#category-optionally-blockable", "name": "optionally-blockable", "title": "Optionally-blockable content"}, {"test_expansion": [{"delivery_value": "opt-in", "origin": ["cross-http", "same-http"], "delivery_type": "*", "name": "opt-in-blocks", "expectation": "blocked", "expansion": "default", "redirection": "*", "source_context_list": "*", "source_scheme": "https", "subresource": {"blockable": "*", "optionally-blockable": []}}, {"delivery_value": null, "origin": ["cross-http", "same-http"], "delivery_type": "*", "name": "no-opt-in-blocks", "expectation": "blocked", "expansion": "default", "redirection": "*", "source_context_list": "*", "source_scheme": "https", "subresource": {"blockable": "*", "optionally-blockable": []}}, {"delivery_value": "*", "origin": ["cross-ws", "same-ws"], "delivery_type": "*", "name": "ws-downgrade-blocks", "expectation": "blocked", "expansion": "default", "redirection": "*", "source_context_list": "*", "source_scheme": "https", "subresource": {"blockable": "websocket", "optionally-blockable": []}}], "description": "Test behavior of blockable content.", "specification_url": "http://www.w3.org/TR/mixed-content/#category-blockable", "name": "blockable", "title": "Blockable content"}, {"test_expansion": [{"delivery_value": "*", "origin": ["same-https"], "delivery_type": "*", "name": "allowed", "expectation": "allowed", "expansion": "default", "redirection": ["no-redirect", "keep-scheme"], "source_context_list": "*", "source_scheme": "https", "subresource": {"blockable": "*", "optionally-blockable": "*"}}, {"delivery_value": "*", "origin": ["same-wss"], "delivery_type": "*", "name": "websocket-allowed", "expectation": "allowed", "expansion": "default", "redirection": ["no-redirect", "keep-scheme"], "source_context_list": "*", "source_scheme": "https", "subresource": {"blockable": "websocket", "optionally-blockable": []}}], "description": "Test behavior of allowed content.", "specification_url": "http://www.w3.org/TR/mixed-content/", "name": "allowed", "title": "Allowed content"}], "test_file_path_pattern": "gen/%(source_context_list)s.%(delivery_type)s/%(delivery_value)s/%(subresource)s/%(origin)s.%(redirection)s.%(source_scheme)s.html", "excluded_tests": [{"delivery_value": null, "origin": "*", "delivery_type": "http-rp", "name": "Skip-redundant-no-opt-in", "expectation": "*", "expansion": "*", "redirection": "*", "source_context_list": "*", "source_scheme": "*", "subresource": {"blockable": "*", "optionally-blockable": "*"}}, {"delivery_value": "*", "origin": "*", "delivery_type": "*", "name": "Redundant-subresources", "expectation": "*", "expansion": "*", "redirection": "*", "source_context_list": "*", "source_scheme": "*", "subresource": {"blockable": ["a-tag"], "optionally-blockable": []}}, {"delivery_value": "*", "origin": ["same-https", "same-http", "cross-https", "cross-http"], "delivery_type": "*", "name": "Skip-origins-not-applicable-to-websockets", "expectation": "*", "expansion": "*", "redirection": "*", "source_context_list": "*", "source_scheme": "*", "subresource": {"blockable": ["websocket"], "optionally-blockable": []}}, {"delivery_value": "opt-in", "origin": "*", "delivery_type": "meta", "name": "Skip-redundant-for-opt-in-method", "expectation": "*", "expansion": "*", "redirection": ["keep-scheme", "swap-scheme"], "source_context_list": "*", "source_scheme": "*", "subresource": {"blockable": "*", "optionally-blockable": "*"}}], "delivery_key": "mixedContent", "test_description_template": "Mixed-Content: Expects %(expectation)s for %(subresource)s to %(origin)s origin and %(redirection)s redirection from %(source_scheme)s context.", "source_context_schema": {"supported_delivery_type": {"iframe": ["http-rp", "meta"], "worker-module-data": [], "worker-classic-data": [], "top": ["http-rp", "meta"], "worker-classic": ["http-rp"], "iframe-blank": ["meta"], "worker-module": ["http-rp"], "srcdoc": ["meta"]}, "supported_subresource": {"iframe": "*", "worker-module-data": ["xhr", "fetch", "websocket"], "worker-classic-data": ["xhr", "fetch", "websocket"], "top": "*", "worker-classic": ["xhr", "fetch", "websocket"], "iframe-blank": "*", "worker-module": ["xhr", "fetch", "websocket"], "srcdoc": "*"}}};
#!/usr/bin/env python
import os
import sys
sys.path.insert(
0,
os.path.join(
os.path.dirname(os.path.abspath(__file__)), '..', '..', '..', 'common',
'security-features', 'tools'))
import generate
class MixedContentConfig(object):
def __init__(self):
self.selection_pattern = \
'%(source_context_list)s.%(delivery_type)s/' + \
'%(delivery_value)s/' + \
'%(subresource)s/' + \
'%(origin)s.%(redirection)s.%(source_scheme)s'
self.test_file_path_pattern = 'gen/' + self.selection_pattern + '.html'
self.test_description_template = 'Mixed-Content: Expects %(expectation)s for %(subresource)s to %(origin)s origin and %(redirection)s redirection from %(source_scheme)s context.'
self.test_page_title_template = 'Mixed-Content: %s'
self.helper_js = '/mixed-content/generic/test-case.sub.js'
# For debug target only.
self.sanity_checker_js = '/mixed-content/generic/sanity-checker.js'
self.spec_json_js = '/mixed-content/spec_json.js'
script_directory = os.path.dirname(os.path.abspath(__file__))
self.spec_directory = os.path.abspath(
os.path.join(script_directory, '..', '..'))
if __name__ == '__main__':
generate.main(MixedContentConfig())
{
"selection_pattern": "%(source_context_list)s.%(delivery_type)s/%(delivery_value)s/%(subresource)s/%(origin)s.%(redirection)s.%(source_scheme)s",
"test_file_path_pattern": "gen/%(source_context_list)s.%(delivery_type)s/%(delivery_value)s/%(subresource)s/%(origin)s.%(redirection)s.%(source_scheme)s.html",
"test_description_template": "Mixed-Content: Expects %(expectation)s for %(subresource)s to %(origin)s origin and %(redirection)s redirection from %(source_scheme)s context.",
"test_page_title_template": "Mixed-Content: %(title)s",
"specification": [
{
"name": "optionally-blockable",
......
var SPEC_JSON = {"subresource_schema": {"supported_delivery_type": {"picture-tag": [], "worklet-layout": [], "worklet-paint": [], "img-tag": [], "a-tag": [], "worklet-layout-import-data": [], "worklet-audio-import-data": [], "worklet-animation": [], "websocket": [], "worklet-paint-import-data": [], "video-tag": [], "object-tag": [], "worklet-audio": [], "beacon": [], "worker-module": [], "worker-import-data": [], "script-tag": [], "worklet-animation-import-data": [], "link-css-tag": [], "xhr": [], "worker-classic": [], "link-prefetch-tag": [], "audio-tag": [], "fetch": []}}, "excluded_tests": [{"delivery_value": null, "origin": "*", "delivery_type": "http-rp", "name": "Skip-redundant-no-opt-in", "expectation": "*", "expansion": "*", "redirection": "*", "source_context_list": "*", "source_scheme": "*", "subresource": {"blockable": "*", "optionally-blockable": "*"}}, {"delivery_value": "*", "origin": "*", "delivery_type": "*", "name": "Redundant-subresources", "expectation": "*", "expansion": "*", "redirection": "*", "source_context_list": "*", "source_scheme": "*", "subresource": {"blockable": ["a-tag"], "optionally-blockable": []}}, {"delivery_value": "*", "origin": ["same-https", "same-http", "cross-https", "cross-http"], "delivery_type": "*", "name": "Skip-origins-not-applicable-to-websockets", "expectation": "*", "expansion": "*", "redirection": "*", "source_context_list": "*", "source_scheme": "*", "subresource": {"blockable": ["websocket"], "optionally-blockable": []}}, {"delivery_value": "opt-in", "origin": "*", "delivery_type": "meta", "name": "Skip-redundant-for-opt-in-method", "expectation": "*", "expansion": "*", "redirection": ["keep-scheme", "swap-scheme"], "source_context_list": "*", "source_scheme": "*", "subresource": {"blockable": "*", "optionally-blockable": "*"}}], "specification": [{"test_expansion": [{"delivery_value": "opt-in", "origin": ["cross-http", "same-http"], "delivery_type": "*", "name": "opt-in-blocks", "expectation": "blocked", "expansion": "default", "redirection": "*", "source_context_list": "*", "source_scheme": "https", "subresource": {"blockable": [], "optionally-blockable": "*"}}, {"delivery_value": null, "origin": ["cross-http", "same-http"], "delivery_type": "*", "name": "no-opt-in-allows", "expectation": "allowed", "expansion": "default", "redirection": "*", "source_context_list": "*", "source_scheme": "https", "subresource": {"blockable": [], "optionally-blockable": "*"}}], "description": "Test behavior of optionally-blockable content", "specification_url": "http://www.w3.org/TR/mixed-content/#category-optionally-blockable", "name": "optionally-blockable", "title": "Optionally-blockable content"}, {"test_expansion": [{"delivery_value": "opt-in", "origin": ["cross-http", "same-http"], "delivery_type": "*", "name": "opt-in-blocks", "expectation": "blocked", "expansion": "default", "redirection": "*", "source_context_list": "*", "source_scheme": "https", "subresource": {"blockable": "*", "optionally-blockable": []}}, {"delivery_value": null, "origin": ["cross-http", "same-http"], "delivery_type": "*", "name": "no-opt-in-blocks", "expectation": "blocked", "expansion": "default", "redirection": "*", "source_context_list": "*", "source_scheme": "https", "subresource": {"blockable": "*", "optionally-blockable": []}}, {"delivery_value": "*", "origin": ["cross-ws", "same-ws"], "delivery_type": "*", "name": "ws-downgrade-blocks", "expectation": "blocked", "expansion": "default", "redirection": "*", "source_context_list": "*", "source_scheme": "https", "subresource": {"blockable": "websocket", "optionally-blockable": []}}], "description": "Test behavior of blockable content.", "specification_url": "http://www.w3.org/TR/mixed-content/#category-blockable", "name": "blockable", "title": "Blockable content"}, {"test_expansion": [{"delivery_value": "*", "origin": ["same-https"], "delivery_type": "*", "name": "allowed", "expectation": "allowed", "expansion": "default", "redirection": ["no-redirect", "keep-scheme"], "source_context_list": "*", "source_scheme": "https", "subresource": {"blockable": "*", "optionally-blockable": "*"}}, {"delivery_value": "*", "origin": ["same-wss"], "delivery_type": "*", "name": "websocket-allowed", "expectation": "allowed", "expansion": "default", "redirection": ["no-redirect", "keep-scheme"], "source_context_list": "*", "source_scheme": "https", "subresource": {"blockable": "websocket", "optionally-blockable": []}}], "description": "Test behavior of allowed content.", "specification_url": "http://www.w3.org/TR/mixed-content/", "name": "allowed", "title": "Allowed content"}], "test_expansion_schema": {"delivery_value": [null, "opt-in"], "origin": ["same-https", "same-http", "cross-https", "cross-http", "same-wss", "same-ws", "cross-wss", "cross-ws"], "delivery_type": ["http-rp", "meta"], "subresource": {"blockable": ["script-tag", "link-css-tag", "xhr", "worker-classic", "worker-module", "worker-import-data", "worklet-animation", "worklet-audio", "worklet-layout", "worklet-paint", "worklet-animation-import-data", "worklet-audio-import-data", "worklet-layout-import-data", "worklet-paint-import-data", "fetch", "a-tag", "object-tag", "picture-tag", "websocket", "link-prefetch-tag", "beacon"], "optionally-blockable": ["img-tag", "audio-tag", "video-tag"]}, "expectation": ["allowed", "blocked"], "expansion": ["default", "override"], "redirection": ["no-redirect", "keep-scheme", "swap-scheme"], "source_context_list": ["top", "worker-classic-data", "worker-module-data"], "source_scheme": ["http", "https"]}, "source_context_list_schema": {"worker-classic-data": {"subresourcePolicyDeliveries": [], "sourceContextList": [{"sourceContextType": "top", "policyDeliveries": ["policy"]}, {"sourceContextType": "worker-classic-data", "policyDeliveries": []}]}, "top": {"subresourcePolicyDeliveries": [], "description": "Policy set by the top-level Document", "sourceContextList": [{"sourceContextType": "top", "policyDeliveries": ["policy"]}]}, "worker-module-data": {"subresourcePolicyDeliveries": [], "sourceContextList": [{"sourceContextType": "top", "policyDeliveries": ["policy"]}, {"sourceContextType": "worker-module-data", "policyDeliveries": []}]}}, "delivery_key": "mixedContent", "source_context_schema": {"supported_delivery_type": {"iframe": ["http-rp", "meta"], "worker-module-data": [], "worker-classic-data": [], "top": ["http-rp", "meta"], "worker-classic": ["http-rp"], "iframe-blank": ["meta"], "worker-module": ["http-rp"], "srcdoc": ["meta"]}, "supported_subresource": {"iframe": "*", "worker-module-data": ["xhr", "fetch", "websocket"], "worker-classic-data": ["xhr", "fetch", "websocket"], "top": "*", "worker-classic": ["xhr", "fetch", "websocket"], "iframe-blank": "*", "worker-module": ["xhr", "fetch", "websocket"], "srcdoc": "*"}}};
#!/usr/bin/env python
import os
import sys
sys.path.insert(
0,
os.path.join(
os.path.dirname(os.path.abspath(__file__)), '..', '..', '..', 'common',
'security-features', 'tools'))
import generate
class ReferrerPolicyConfig(object):
def __init__(self):
self.selection_pattern = \
'%(source_context_list)s.%(delivery_type)s/' + \
'%(delivery_value)s/' + \
'%(subresource)s/' + \
'%(origin)s.%(redirection)s.%(source_scheme)s'
self.test_file_path_pattern = 'gen/' + self.selection_pattern + '.html'
self.test_description_template = 'Referrer Policy: Expects %(expectation)s for %(subresource)s to %(origin)s origin and %(redirection)s redirection from %(source_scheme)s context.'
self.test_page_title_template = 'Referrer-Policy: %s'
self.helper_js = '/referrer-policy/generic/test-case.sub.js'
# For debug target only.
self.sanity_checker_js = '/referrer-policy/generic/sanity-checker.js'
self.spec_json_js = '/referrer-policy/spec_json.js'
script_directory = os.path.dirname(os.path.abspath(__file__))
self.spec_directory = os.path.abspath(
os.path.join(script_directory, '..', '..'))
if __name__ == '__main__':
generate.main(ReferrerPolicyConfig())
{
"selection_pattern": "%(source_context_list)s.%(delivery_type)s/%(delivery_value)s/%(subresource)s/%(origin)s.%(redirection)s.%(source_scheme)s",
"test_file_path_pattern": "gen/%(source_context_list)s.%(delivery_type)s/%(delivery_value)s/%(subresource)s/%(origin)s.%(redirection)s.%(source_scheme)s.html",
"test_description_template": "Referrer Policy: Expects %(expectation)s for %(subresource)s to %(origin)s origin and %(redirection)s redirection from %(source_scheme)s context.",
"test_page_title_template": "Referrer-Policy: %(title)s",
"specification": [
{
"name": "unset-referrer-policy",
......
var SPEC_JSON = {"subresource_schema": {"supported_delivery_type": {"worklet-layout": [], "worklet-paint": [], "worker-module": [], "sharedworker-classic": [], "worklet-paint-import-data": [], "worklet-animation-import-data": [], "fetch": [], "xhr": [], "worker-classic": [], "worklet-layout-import-data": [], "worklet-audio-import-data": [], "worklet-animation": [], "worker-import-data": [], "websocket": [], "worklet-audio": [], "iframe-tag": [], "img-tag": []}}, "source_context_list_schema": {"worker-classic-data": {"subresourcePolicyDeliveries": [], "description": "CSP set by the top-level Document is inherited to dedicated workers", "sourceContextList": [{"sourceContextType": "top", "policyDeliveries": ["policy"]}, {"sourceContextType": "worker-classic-data", "policyDeliveries": []}]}, "top": {"subresourcePolicyDeliveries": [], "description": "CSP set by the top-level Document", "sourceContextList": [{"sourceContextType": "top", "policyDeliveries": ["policy"]}]}, "srcdoc-inherit": {"subresourcePolicyDeliveries": [], "description": "srcdoc iframe should inherit parent Document's policy", "sourceContextList": [{"sourceContextType": "top", "policyDeliveries": ["policy"]}, {"sourceContextType": "srcdoc"}]}, "iframe-blank-inherit": {"subresourcePolicyDeliveries": [], "description": "blank iframe should inherit parent Document's policy", "sourceContextList": [{"sourceContextType": "top", "policyDeliveries": ["policy"]}, {"sourceContextType": "iframe-blank"}]}}, "test_page_title_template": "Upgrade-Insecure-Requests: %(title)s", "test_expansion_schema": {"delivery_value": [null, "upgrade"], "origin": ["same-https", "same-http-downgrade", "cross-https", "cross-http-downgrade", "same-wss", "same-ws-downgrade", "cross-wss", "cross-ws-downgrade"], "delivery_type": ["http-rp", "meta"], "subresource": ["iframe-tag", "img-tag", "xhr", "fetch", "websocket", "worker-classic", "worker-module", "worker-import-data", "sharedworker-classic", "worklet-animation", "worklet-audio", "worklet-layout", "worklet-paint", "worklet-animation-import-data", "worklet-audio-import-data", "worklet-layout-import-data", "worklet-paint-import-data"], "expectation": ["allowed", "blocked"], "expansion": ["default", "override"], "redirection": ["no-redirect", "downgrade"], "source_context_list": ["top", "srcdoc-inherit", "iframe-blank-inherit", "worker-classic-data"], "source_scheme": ["https"]}, "selection_pattern": "%(source_context_list)s.%(delivery_type)s/%(delivery_value)s/%(subresource)s/%(origin)s.%(redirection)s.%(source_scheme)s", "specification": [{"test_expansion": [{"delivery_value": null, "origin": "*", "delivery_type": "meta", "name": "Without upgrade-insecure-request, all requests are blocked ...", "expectation": "blocked", "expansion": "default", "redirection": "*", "source_context_list": "*", "source_scheme": "https", "subresource": "*"}, {"delivery_value": null, "origin": ["same-https", "cross-https", "same-wss", "cross-wss"], "delivery_type": "meta", "name": "... except for the secure requests listed here", "expectation": "allowed", "expansion": "override", "redirection": "no-redirect", "source_context_list": "*", "source_scheme": "https", "subresource": "*"}], "description": "No upgrade-insecure-request", "specification_url": "https://w3c.github.io/webappsec-upgrade-insecure-requests/", "name": "No upgrade-insecure-request", "title": "No upgrade-insecure-request"}, {"test_expansion": [{"delivery_value": "upgrade", "origin": "*", "delivery_type": "*", "name": "With upgrade-insecure-request, all insecure requests are upgraded and allowed.", "expectation": "allowed", "expansion": "default", "redirection": "*", "source_context_list": "*", "source_scheme": "https", "subresource": "*"}], "description": "With upgrade-insecure-request", "specification_url": "https://w3c.github.io/webappsec-upgrade-insecure-requests/", "name": "With upgrade-insecure-request", "title": "With upgrade-insecure-request"}], "test_file_path_pattern": "gen/%(source_context_list)s.%(delivery_type)s/%(delivery_value)s/%(subresource)s/%(origin)s.%(redirection)s.%(source_scheme)s.html", "excluded_tests": [{"delivery_value": "*", "origin": ["same-https", "cross-https", "same-wss", "cross-wss"], "delivery_type": "*", "name": "Omit secure requests", "expectation": "allowed", "expansion": "*", "redirection": "no-redirect", "source_context_list": "*", "source_scheme": "*", "subresource": "*"}, {"delivery_value": "*", "origin": "*", "delivery_type": "http-rp", "name": "For inheriting tests skip http-rp because we already have <meta> tests", "expectation": "*", "expansion": "*", "redirection": "*", "source_context_list": ["srcdoc-inherit", "iframe-blank-inherit", "worker-classic-data"], "source_scheme": "*", "subresource": "*"}, {"delivery_value": "*", "origin": ["cross-https", "cross-http-downgrade", "cross-wss", "cross-ws-downgrade"], "delivery_type": "*", "name": "Workers are same-origin only", "expectation": "*", "expansion": "*", "redirection": "*", "source_context_list": "*", "source_scheme": "*", "subresource": ["worker-classic", "worker-module", "sharedworker-classic"]}, {"delivery_value": "*", "origin": ["same-https", "same-http-downgrade", "cross-https", "cross-http-downgrade"], "delivery_type": "*", "name": "Websockets are ws/wss-only", "expectation": "*", "expansion": "*", "redirection": "*", "source_context_list": "*", "source_scheme": "*", "subresource": "websocket"}, {"delivery_value": "*", "origin": "*", "delivery_type": "*", "name": "Websockets is no-redirect only", "expectation": "*", "expansion": "*", "redirection": ["downgrade"], "source_context_list": "*", "source_scheme": "*", "subresource": "websocket"}, {"delivery_value": "*", "origin": ["same-wss", "same-ws-downgrade", "cross-wss", "cross-ws-downgrade"], "delivery_type": "*", "name": "ws/wss are websocket-only", "expectation": "*", "expansion": "*", "redirection": "*", "source_context_list": "*", "source_scheme": "*", "subresource": ["iframe-tag", "img-tag", "xhr", "fetch", "worker-classic", "worker-module", "worker-import-data", "sharedworker-classic", "worklet-animation", "worklet-audio", "worklet-layout", "worklet-paint", "worklet-animation-import-data", "worklet-audio-import-data", "worklet-layout-import-data", "worklet-paint-import-data"]}], "delivery_key": "upgradeInsecureRequests", "test_description_template": "Upgrade-Insecure-Requests: Expects %(expectation)s for %(subresource)s to %(origin)s origin and %(redirection)s redirection from %(source_scheme)s context.", "source_context_schema": {"supported_delivery_type": {"iframe": ["http-rp", "meta"], "worker-module-data": [], "worker-classic-data": [], "top": ["http-rp", "meta"], "worker-classic": ["http-rp"], "iframe-blank": ["meta"], "worker-module": ["http-rp"], "srcdoc": ["meta"]}, "supported_subresource": {"iframe": "*", "worker-module-data": ["xhr", "fetch", "websocket"], "worker-classic-data": ["xhr", "fetch", "websocket"], "top": "*", "worker-classic": ["xhr", "fetch", "websocket"], "iframe-blank": "*", "worker-module": ["xhr", "fetch", "websocket"], "srcdoc": "*"}}};
#!/usr/bin/env python
import os
import sys
sys.path.insert(
0,
os.path.join(
os.path.dirname(os.path.abspath(__file__)), '..', '..', '..', 'common',
'security-features', 'tools'))
import generate
class UpgradeInsecureRequestsConfig(object):
def __init__(self):
self.selection_pattern = \
'%(source_context_list)s.%(delivery_type)s/' + \
'%(delivery_value)s/' + \
'%(subresource)s/' + \
'%(origin)s.%(redirection)s.%(source_scheme)s'
self.test_file_path_pattern = 'gen/' + self.selection_pattern + '.html'
self.test_description_template = 'Upgrade-Insecure-Requests: Expects %(expectation)s for %(subresource)s to %(origin)s origin and %(redirection)s redirection from %(source_scheme)s context.'
self.test_page_title_template = 'Upgrade-Insecure-Requests: %s'
self.helper_js = '/upgrade-insecure-requests/generic/test-case.sub.js'
# For debug target only.
self.sanity_checker_js = '/upgrade-insecure-requests/generic/sanity-checker.js'
self.spec_json_js = '/upgrade-insecure-requests/spec_json.js'
script_directory = os.path.dirname(os.path.abspath(__file__))
self.spec_directory = os.path.abspath(
os.path.join(script_directory, '..', '..'))
if __name__ == '__main__':
generate.main(UpgradeInsecureRequestsConfig())
{
"selection_pattern": "%(source_context_list)s.%(delivery_type)s/%(delivery_value)s/%(subresource)s/%(origin)s.%(redirection)s.%(source_scheme)s",
"test_file_path_pattern": "gen/%(source_context_list)s.%(delivery_type)s/%(delivery_value)s/%(subresource)s/%(origin)s.%(redirection)s.%(source_scheme)s.html",
"test_description_template": "Upgrade-Insecure-Requests: Expects %(expectation)s for %(subresource)s to %(origin)s origin and %(redirection)s redirection from %(source_scheme)s context.",
"test_page_title_template": "Upgrade-Insecure-Requests: %(title)s",
"specification": [
{
"name": "No upgrade-insecure-request",
......
var SPEC_JSON = {"subresource_schema": {"supported_delivery_type": {"worklet-layout": [], "worklet-paint": [], "worker-module": [], "sharedworker-classic": [], "worklet-paint-import-data": [], "worklet-animation-import-data": [], "fetch": [], "xhr": [], "worker-classic": [], "worklet-layout-import-data": [], "worklet-audio-import-data": [], "worklet-animation": [], "worker-import-data": [], "websocket": [], "worklet-audio": [], "iframe-tag": [], "img-tag": []}}, "excluded_tests": [{"delivery_value": "*", "origin": ["same-https", "cross-https", "same-wss", "cross-wss"], "delivery_type": "*", "name": "Omit secure requests", "expectation": "allowed", "expansion": "*", "redirection": "no-redirect", "source_context_list": "*", "source_scheme": "*", "subresource": "*"}, {"delivery_value": "*", "origin": "*", "delivery_type": "http-rp", "name": "For inheriting tests skip http-rp because we already have <meta> tests", "expectation": "*", "expansion": "*", "redirection": "*", "source_context_list": ["srcdoc-inherit", "iframe-blank-inherit", "worker-classic-data"], "source_scheme": "*", "subresource": "*"}, {"delivery_value": "*", "origin": ["cross-https", "cross-http-downgrade", "cross-wss", "cross-ws-downgrade"], "delivery_type": "*", "name": "Workers are same-origin only", "expectation": "*", "expansion": "*", "redirection": "*", "source_context_list": "*", "source_scheme": "*", "subresource": ["worker-classic", "worker-module", "sharedworker-classic"]}, {"delivery_value": "*", "origin": ["same-https", "same-http-downgrade", "cross-https", "cross-http-downgrade"], "delivery_type": "*", "name": "Websockets are ws/wss-only", "expectation": "*", "expansion": "*", "redirection": "*", "source_context_list": "*", "source_scheme": "*", "subresource": "websocket"}, {"delivery_value": "*", "origin": "*", "delivery_type": "*", "name": "Websockets is no-redirect only", "expectation": "*", "expansion": "*", "redirection": ["downgrade"], "source_context_list": "*", "source_scheme": "*", "subresource": "websocket"}, {"delivery_value": "*", "origin": ["same-wss", "same-ws-downgrade", "cross-wss", "cross-ws-downgrade"], "delivery_type": "*", "name": "ws/wss are websocket-only", "expectation": "*", "expansion": "*", "redirection": "*", "source_context_list": "*", "source_scheme": "*", "subresource": ["iframe-tag", "img-tag", "xhr", "fetch", "worker-classic", "worker-module", "worker-import-data", "sharedworker-classic", "worklet-animation", "worklet-audio", "worklet-layout", "worklet-paint", "worklet-animation-import-data", "worklet-audio-import-data", "worklet-layout-import-data", "worklet-paint-import-data"]}], "specification": [{"test_expansion": [{"delivery_value": null, "origin": "*", "delivery_type": "meta", "name": "Without upgrade-insecure-request, all requests are blocked ...", "expectation": "blocked", "expansion": "default", "redirection": "*", "source_context_list": "*", "source_scheme": "https", "subresource": "*"}, {"delivery_value": null, "origin": ["same-https", "cross-https", "same-wss", "cross-wss"], "delivery_type": "meta", "name": "... except for the secure requests listed here", "expectation": "allowed", "expansion": "override", "redirection": "no-redirect", "source_context_list": "*", "source_scheme": "https", "subresource": "*"}], "description": "No upgrade-insecure-request", "specification_url": "https://w3c.github.io/webappsec-upgrade-insecure-requests/", "name": "No upgrade-insecure-request", "title": "No upgrade-insecure-request"}, {"test_expansion": [{"delivery_value": "upgrade", "origin": "*", "delivery_type": "*", "name": "With upgrade-insecure-request, all insecure requests are upgraded and allowed.", "expectation": "allowed", "expansion": "default", "redirection": "*", "source_context_list": "*", "source_scheme": "https", "subresource": "*"}], "description": "With upgrade-insecure-request", "specification_url": "https://w3c.github.io/webappsec-upgrade-insecure-requests/", "name": "With upgrade-insecure-request", "title": "With upgrade-insecure-request"}], "test_expansion_schema": {"delivery_value": [null, "upgrade"], "origin": ["same-https", "same-http-downgrade", "cross-https", "cross-http-downgrade", "same-wss", "same-ws-downgrade", "cross-wss", "cross-ws-downgrade"], "delivery_type": ["http-rp", "meta"], "subresource": ["iframe-tag", "img-tag", "xhr", "fetch", "websocket", "worker-classic", "worker-module", "worker-import-data", "sharedworker-classic", "worklet-animation", "worklet-audio", "worklet-layout", "worklet-paint", "worklet-animation-import-data", "worklet-audio-import-data", "worklet-layout-import-data", "worklet-paint-import-data"], "expectation": ["allowed", "blocked"], "expansion": ["default", "override"], "redirection": ["no-redirect", "downgrade"], "source_context_list": ["top", "srcdoc-inherit", "iframe-blank-inherit", "worker-classic-data"], "source_scheme": ["https"]}, "source_context_list_schema": {"worker-classic-data": {"subresourcePolicyDeliveries": [], "description": "CSP set by the top-level Document is inherited to dedicated workers", "sourceContextList": [{"sourceContextType": "top", "policyDeliveries": ["policy"]}, {"sourceContextType": "worker-classic-data", "policyDeliveries": []}]}, "top": {"subresourcePolicyDeliveries": [], "description": "CSP set by the top-level Document", "sourceContextList": [{"sourceContextType": "top", "policyDeliveries": ["policy"]}]}, "srcdoc-inherit": {"subresourcePolicyDeliveries": [], "description": "srcdoc iframe should inherit parent Document's policy", "sourceContextList": [{"sourceContextType": "top", "policyDeliveries": ["policy"]}, {"sourceContextType": "srcdoc"}]}, "iframe-blank-inherit": {"subresourcePolicyDeliveries": [], "description": "blank iframe should inherit parent Document's policy", "sourceContextList": [{"sourceContextType": "top", "policyDeliveries": ["policy"]}, {"sourceContextType": "iframe-blank"}]}}, "delivery_key": "upgradeInsecureRequests", "source_context_schema": {"supported_delivery_type": {"iframe": ["http-rp", "meta"], "worker-module-data": [], "worker-classic-data": [], "top": ["http-rp", "meta"], "worker-classic": ["http-rp"], "iframe-blank": ["meta"], "worker-module": ["http-rp"], "srcdoc": ["meta"]}, "supported_subresource": {"iframe": "*", "worker-module-data": ["xhr", "fetch", "websocket"], "worker-classic-data": ["xhr", "fetch", "websocket"], "top": "*", "worker-classic": ["xhr", "fetch", "websocket"], "iframe-blank": "*", "worker-module": ["xhr", "fetch", "websocket"], "srcdoc": "*"}}};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment