-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rewrite Trusted types tests for CSP violations #50124
Conversation
Currently the listener to "securitypolicyviolation" is added before actually running the statement that triggers violations, so it could be possible that some violations are not caught. This bad pattern is duplicated in several `trusted-types*reporting*` tests. This patch adds a new helper file to properly wrap the listener registration and statement execution in a promise, and reuses it in existing tests. w3c/trusted-types#576
cc @lukewarlow This gives much better results for me in Firefox. Still need to convert the other reporting files and though. |
It seems there are more tests for violation but they use a slightly different approach, so probably will handle them in separate PRs. (also, some of these tests will probably need review and updates too, but for now let's keep the current expectations) |
@lukewarlow I fixed more tests this morning. The remaining ones using securitypolicyviolation are:
|
@@ -50,9 +44,9 @@ | |||
let script_src = script_origin + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this isn't directly related to this PR but the way this URL is constructed doesn't work if you access WPT through https
let script_src = new URL("/trusted-types/support/set-inner-html.js", location.href).href;
This would be better I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm but that might be wrong for the below tests? Maybe leave it as is for now but with a note explaining this mgiht not be ideal?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I guess we should try to fix that, but this PR is already big and we are not going to fix all existing issues in these tests. I'll try to fix that in a follow-up PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checking https://github.com/web-platform-tests/wpt/blob/master/common/get-host-info.sub.js it seems we want ORIGIN and REMOTE_ORIGIN instead, but I'm not really sure so let's handle this separately
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming the assertions inside the helper function are enough for violation object (though idk that they are see comment below), this LGTM
…ting script's src Double slashes were added in #50124 to work around testharness errors due to a HTML page being used as a script but the actual fix is to use a JS file instead.
Currently the listener to "securitypolicyviolation" is added before actually running the statement that triggers violations, so it could be possible that some violations are not caught. This bad pattern is duplicated in several
trusted-types*reporting*
tests.This patch adds a new helper file to properly wrap the listener registration and statement execution in a promise, and reuses it in existing tests.
w3c/trusted-types#576