Skip to content

[wptserve] Add on-demand file hash computation - #8735

Merged
jgraham merged 4 commits into
web-platform-tests:masterfrom
bocoup:compute-file-hash
Apr 23, 2018
Merged

jgraham merged 4 commits into
web-platform-tests:masterfrom
bocoup:compute-file-hash

Conversation

@jugglinmike

@jugglinmike jugglinmike commented Dec 19, 2017 •

Copy link
Copy Markdown
Contributor

Certain tests require that all HTML <script> tags be declared with an
integrity attribute which specifies the cryptographic hash of the file
to be loaded. These tests were initially implemented with a static value
for the hash of the test harness files located in the shared "resources"
directory.

In order to support continued development of those shared files, the
tests should be authored in a way that is tolerant of such
modifications.

Introduce a new templating capability to the wptserve utility which
allows markup to be rendered with dynamically-computed hash values.
Allowing the shared resources to change independently of the tests that
rely on them.


Hi @gsnedders,

I'm working on an enhancement to testharness.js (see gh-6075), and I found
that my latest patch broke a few tests (specifically, those introduced via
gh-7684). I was surprised to find that the error had nothing to do with the
semantics of my change--just the fact that I had made any change at all.

This is an initial attempt to facilitate continued development of
testharness.js. It's pretty rough because it's based on an afternoon's review
of the wptserve internals. I'm requesting your review because I believe you
may have some vision for the overall direction of WPT's server. If you think
there is someone better to give direction, then I'm all ears!

(@annevk and @domenic: my hope is that if this lands, future tests that require
strict file integrity checking can be a little more resilient to change.)


This change is Reviewable

@ghost

ghost commented Dec 19, 2017 •

Copy link
Copy Markdown

Build PASSED

Started: 2017-12-23 01:38:56
Finished: 2017-12-23 01:51:39

View more information about this build on:

@jgraham

jgraham commented Dec 19, 2017

Copy link
Copy Markdown
Contributor

Review status: 0 of 3 files reviewed at latest revision, 1 unresolved discussion, all commit checks successful.


tools/wptserve/wptserve/pipes.py, line 376 at r1 (raw file):

        self.doc_root = doc_root

    def __getitem__(self, name):

I really think this should look more like a function call. I know that will make the patch bigger and mean a change to the tokenizer and the uuid function, but the current setup looks pretty odd.


Comments from Reviewable

@jugglinmike

Copy link
Copy Markdown
Contributor Author

@jgraham That sounds good to me. Do you think we could do that in a follow-up patch, or do you consider it a prerequisite for this fix?

@jugglinmike

Copy link
Copy Markdown
Contributor Author

(I'm asking because I'd like to limit the prerequisites to introducing the new testharness.js feature referenced in the pull request description.)


<script src="/resources/testharness.js" integrity="sha384-4Nybydhnr3tOpv1yrTkDxu3RFpnxWAxlU5kGn7c8ebKvh1iUdfVMjqP6jf0dacrV"></script>
<script src="/resources/testharnessreport.js" integrity="sha384-GOnHxuyo+nnsFAe4enY+RAl4/+w5NPMJPCQiDroTjxtR7ndRz7Uan8vNbM2qWKmU"></script>
<script src="/resources/testharness.js" integrity="sha384-{{sha384[resources/testharness.js]}}"></script>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than using testharness.js, could we not add another file that doesn't ever change?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@domenic, WDYT?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you misunderstand the test. If you have a CSP stating require-sri-for script all scripts in the document need to have integrity defined. That includes the harness scripts.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, didn't even know that was a thing or read very closely. Makes a lot more sense now.

@jgraham

jgraham commented Dec 20, 2017

Copy link
Copy Markdown
Contributor

I'm not too keen on introducing one syntax and then changing it immediately. And I'm even less keen on introducing one syntax and then changing it, but not immediately. So I would prefer to fix the syntax right from the start unless it's really too time consuming.

@jugglinmike

Copy link
Copy Markdown
Contributor Author

I've re-implemented the functionality on top of a slightly modified template parsing engine. I've also expanded the feature to support all the hashing algorithms that Python provides.

The surrounding code was missing some test coverage, so I added tests for that to help give us confidence that there are no regressions here. For the sake of clarity, I'd prefer it if we could merge this work using distinct commits like the ones submitted here.

@jgraham Does this look better to you?

(The original version of this branch is available here.)

@jgraham

jgraham commented Jan 8, 2018

Copy link
Copy Markdown
Contributor

Review status: 0 of 10 files reviewed at latest revision, 3 unresolved discussions, all commit checks successful.


tools/wptserve/wptserve/pipes.py, line 306 at r3 (raw file):

                          (r"\$?\w+", ident),
                          (r"\[[^\]]*\]", index),
                          (r"\(.*\)", arguments)])

This is a greedy regex I think, so it's going to break for cases like foo(bar)baz(foobar). Changing it to `r"([^)]*)" seems like it ought to fix the problem.


tools/wptserve/wptserve/pipes.py, line 393 at r3 (raw file):

    @staticmethod
    def file_hash(request, algorithm, path):
        assert algorithm in SubFunctions.supported_algorithms

A better error message here would be nice.


Comments from Reviewable

@jgraham

jgraham commented Jan 8, 2018

Copy link
Copy Markdown
Contributor

This looks very good, just a couple of minor things to fix before merge.

@jugglinmike

Copy link
Copy Markdown
Contributor Author

Changing it to `r"([^)]*)" seems like it ought to fix the problem.

Sounds good. I've made the change, but I can't think of a way to test that, though. Any ideas?

A better error message here would be nice.

You got it.

@ghost

ghost commented Jan 15, 2018 •

Copy link
Copy Markdown

Build PASSED

Started: 2018-02-05 16:46:19
Finished: 2018-02-05 16:58:30

View more information about this build on:

@jgraham

jgraham commented Mar 1, 2018

Copy link
Copy Markdown
Contributor

Reviewed 2 of 5 files at r1, 4 of 10 files at r2, 6 of 8 files at r3, 1 of 2 files at r4, 1 of 1 files at r5.
Review status: all files reviewed at latest revision, 2 unresolved discussions, all commit checks successful.


tools/wptserve/wptserve/pipes.py, line 394 at r5 (raw file):

    @staticmethod
    def file_hash(request, algorithm, path):
        assert algorithm in SubFunctions.supported_algorithms, (

Not a blocker, but in general using assert in this case isn't ideal because there is a python interpreter option to strip asserts. So if algorithm not in supported_algorithms seems preferable.


Comments from Reviewable

@jgraham

jgraham commented Mar 1, 2018

Copy link
Copy Markdown
Contributor

@jugglinmike Want to rebase this to reorganise the commits and then land it?

@jugglinmike

Copy link
Copy Markdown
Contributor Author

Sure thing, James. While implementing your last bit of feedback about assertions, I realized that that functionality wasn't tested. So in addition to explicitly raising a ValueError, this patch now also contains another functional test which verifies that the server responds with an HTTP error in this case.

The prior version of this change set is available on the following branch:

https://github.com/w3c/web-platform-tests/compare/master...bocoup:compute-file-hash-prebase?expand=1

Additionally, update the two Web Platform Tests which previously
specified static values for the expected hash of shared resource files.
@jugglinmike

Copy link
Copy Markdown
Contributor Author

I also had the pleasant surprise of failing a new test that didn't exist when I wrote this patch. Thanks, @gsnedders :) Updated that test accordingly.

@jgraham

jgraham commented Apr 23, 2018

Copy link
Copy Markdown
Contributor

Reviewed 4 of 4 files at r6.
Review status: all files reviewed at latest revision, 2 unresolved discussions, all commit checks successful.


Comments from Reviewable

@jgraham
jgraham merged commit e0ea063 into web-platform-tests:master Apr 23, 2018
@jugglinmike
jugglinmike deleted the compute-file-hash branch April 23, 2018 17:18
@jugglinmike

Copy link
Copy Markdown
Contributor Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants