Skip to content

Commit

Permalink
Separate URL tests into new file
Browse files Browse the repository at this point in the history
  • Loading branch information
not-a-rootkit committed Jan 20, 2025
1 parent 17f9a5d commit 5801989
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 79 deletions.
15 changes: 14 additions & 1 deletion malicious-site-protection/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}

}
}
80 changes: 80 additions & 0 deletions malicious-site-protection/url_tests.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
]
}
}

0 comments on commit 5801989

Please sign in to comment.