diff --git a/malicious-site-protection/README.md b/malicious-site-protection/README.md index ac921ce..b71bca3 100644 --- a/malicious-site-protection/README.md +++ b/malicious-site-protection/README.md @@ -16,13 +16,14 @@ Test suite specific fields: - `featureName` - string - name of the privacy feature as defined in the config - `siteURL` - string - the URL of the site we are testing protections for +- `canonicalURL` - string - the expected canonicalized URL - `expectBlock` - bool - true if expected to be blocked, false otherwise ## Pseudo-code implementation ### Block Test ``` -for $testSet in test.json +for $testSet in block_tests.json loadReferenceHashPrefixes('hashPrefixes_reference.json') loadReferenceFilterSet('filterSet_reference.json') @@ -37,6 +38,18 @@ for $testSet in test.json expect($blocked === $test.expectBlock) ``` +### Canonicalization Test +for $testSet in canonicalization_tests.json + for $test in $testSet + if $test.exceptPlatforms includes 'current-platform' + skip + + $canonicalURL = URL.canonicalize( + url=$test.siteURL, + ) + + expect($canonicalURL === $test.canonicalURL) + ## Platform exceptions - Currently, malicious site protection is only available on the browser platforms: diff --git a/malicious-site-protection/tests.json b/malicious-site-protection/block_tests.json similarity index 62% rename from malicious-site-protection/tests.json rename to malicious-site-protection/block_tests.json index 63916b1..55b1f83 100644 --- a/malicious-site-protection/tests.json +++ b/malicious-site-protection/block_tests.json @@ -136,83 +136,5 @@ ] } ] - }, - "urlTests": { - "name": "Should normalize URLs", - "desc": "All browser platforms should sufficiently canonicalize URLs consitently.", - "tests": [ - { - "name": "malware wildcard regex test", - "siteURL": "https://broken.third-party.site/path/to/resource#fragment", - "canonicalURL": "https://broken.third-party.site/path/to/resource", - "exceptPlatforms": [ - "web-extension", - "safari-extension" - ] - }, - { - "name": "double slashes in path", - "siteURL": "https://broken.third-party.site//path//to//resource", - "canonicalURL": "https://broken.third-party.site/path/to/resource", - "exceptPlatforms": [ - "web-extension", - "safari-extension" - ] - }, - { - "name": "spaces in path", - "siteURL": "https://broken.third-party.site/path/to/resource%20with%20spaces%20%20%20%20", - "canonicalURL": "https://broken.third-party.site/path/to/resource%20with%20spaces%20%20%20%20", - "exceptPlatforms": [ - "web-extension", - "safari-extension" - ] - }, - { - "name": "encoded fragment", - "siteURL": "https://broken.third-party.site/path/to/resource%23encodedfragment", - "canonicalURL": "https://broken.third-party.site/path/to/resource%23encodedfragment", - "exceptPlatforms": [ - "web-extension", - "safari-extension" - ] - }, - { - "name": "dot segments in path", - "siteURL": "https://broken.third-party.site/path/./to/./resource", - "canonicalURL": "https://broken.third-party.site/path/to/resource", - "exceptPlatforms": [ - "web-extension", - "safari-extension" - ] - }, - { - "name": "spaces in path without trailing spaces", - "siteURL": "https://broken.third-party.site/path/to/resource%20with%20spaces", - "canonicalURL": "https://broken.third-party.site/path/to/resource%20with%20spaces", - "exceptPlatforms": [ - "web-extension", - "safari-extension" - ] - }, - { - "name": "encoded dot segments in path", - "siteURL": "https://broken.third-party.site/path/to/%2E%2E/%2E%2E/resource", - "canonicalURL": "https://broken.third-party.site/resource", - "exceptPlatforms": [ - "web-extension", - "safari-extension" - ] - }, - { - "name": "multiple encoded slashes in path", - "siteURL": "https://broken.third-party.site/path/to/%2F%2F%2F%2F%2F%2F%2F%2F%2F", - "canonicalURL": "https://broken.third-party.site/path/to", - "exceptPlatforms": [ - "web-extension", - "safari-extension" - ] - } - } } \ No newline at end of file diff --git a/malicious-site-protection/url_tests.json b/malicious-site-protection/url_tests.json new file mode 100644 index 0000000..ba2de03 --- /dev/null +++ b/malicious-site-protection/url_tests.json @@ -0,0 +1,80 @@ +{ + "urlTests": { + "name": "Should normalize URLs", + "desc": "All browser platforms should sufficiently canonicalize URLs consitently.", + "tests": [ + { + "name": "fragment in URL", + "siteURL": "https://broken.third-party.site/path/to/resource#fragment", + "canonicalURL": "https://broken.third-party.site/path/to/resource", + "exceptPlatforms": [ + "web-extension", + "safari-extension" + ] + }, + { + "name": "double slashes in path", + "siteURL": "https://broken.third-party.site//path//to//resource", + "canonicalURL": "https://broken.third-party.site/path/to/resource", + "exceptPlatforms": [ + "web-extension", + "safari-extension" + ] + }, + { + "name": "trailing spaces in path", + "siteURL": "https://broken.third-party.site/path/to/resource%20with%20spaces%20%20%20%20", + "canonicalURL": "https://broken.third-party.site/path/to/resource%20with%20spaces%20%20%20%20", + "exceptPlatforms": [ + "web-extension", + "safari-extension" + ] + }, + { + "name": "encoded fragment", + "siteURL": "https://broken.third-party.site/path/to/resource%23encodedfragment", + "canonicalURL": "https://broken.third-party.site/path/to/resource%23encodedfragment", + "exceptPlatforms": [ + "web-extension", + "safari-extension" + ] + }, + { + "name": "dot segments in path", + "siteURL": "https://broken.third-party.site/path/./to/./resource", + "canonicalURL": "https://broken.third-party.site/path/to/resource", + "exceptPlatforms": [ + "web-extension", + "safari-extension" + ] + }, + { + "name": "spaces in path without trailing spaces", + "siteURL": "https://broken.third-party.site/path/to/resource%20with%20spaces", + "canonicalURL": "https://broken.third-party.site/path/to/resource%20with%20spaces", + "exceptPlatforms": [ + "web-extension", + "safari-extension" + ] + }, + { + "name": "encoded dot segments in path", + "siteURL": "https://broken.third-party.site/path/to/%2E%2E/%2E%2E/resource", + "canonicalURL": "https://broken.third-party.site/resource", + "exceptPlatforms": [ + "web-extension", + "safari-extension" + ] + }, + { + "name": "multiple encoded slashes in path", + "siteURL": "https://broken.third-party.site/path/to/%2F%2F%2F%2F%2F%2F%2F%2F%2F", + "canonicalURL": "https://broken.third-party.site/path/to", + "exceptPlatforms": [ + "web-extension", + "safari-extension" + ] + } + ] + } +} \ No newline at end of file