Skip to content
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

Add test for response headers #14074

Merged
merged 7 commits into from
Feb 28, 2019

Conversation

christian-bromann
Copy link
Contributor

@christian-bromann christian-bromann commented Nov 15, 2018

The WebDriver spec defines the response header in the processing modal section as follows:

  1. Set the response’s header with name and value with the following values:

Content-Type
"application/json; charset=utf-8"
Cache-Control
"no-cache"

This patch adds tests for this case.

Question: the RFC defines header names as case insensitive. Should be lowercase header keys and values by default?

Note:: Geckodriver returns a wrong response value for content-type, so I created a bug here: https://bugzilla.mozilla.org/show_bug.cgi?id=1507428

@@ -0,0 +1,6 @@
def test_missing_first_match(new_session, add_browser_capabilities):
response, _ = new_session({"capabilities": {"alwaysMatch": add_browser_capabilities({})}})
assert 'cache-control' in response.headers
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you should lowercase the recieved values here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jgraham see PR question: shall we by default lowercase key and value pairs since headers are case insensitive?

webdriver/tests/new_session/headers.py Outdated Show resolved Hide resolved
@christian-bromann
Copy link
Contributor Author

@jgraham given the fact that this test should be applied to every response I moved the assertion into the Session class. I also converted header key/value pairs into lowercase per default.

@andreastt
Copy link
Member

I sort of feel we should return headers unmodified as they are presented to us, and only convert them to lowercase during assertion.

@andreastt
Copy link
Member

There also appears to be some test failures after one of the recent fixups:
https://travis-ci.org/web-platform-tests/wpt/builds/455470716?utm_source=github_status&utm_medium=notification

@andreastt andreastt removed their request for review November 16, 2018 15:09
@foolip foolip mentioned this pull request Nov 16, 2018
@christian-bromann
Copy link
Contributor Author

@andreastt addressed outstanding issues

@andreastt
Copy link
Member

Retriggered some of the jobs and dismissed @jgraham’s old review.

@christian-bromann
Copy link
Contributor Author

Azure Pipeline is failing due to

  • Chrome not having cache-control in command response header
  • FF Nightly returning application/json; charset=utf8 in response header

continuous-integration/travis-ci/pr failing due to

  • FF Nightly returning application/json; charset=utf8 in response header

@andreastt
Copy link
Member

@jgraham Aren’t those jobs supposed to run stability tests, like Travis?

@jugglinmike
Copy link
Contributor

Yup, but only for tests that it recognizes as being somehow affected by the change set.

2018-11-16 17:23:10,943 - tc-run - INFO - Identifying tests affected in range 'HEAD^'...
2018-11-16 17:23:19,970 - tc-run - INFO - Identified 0 affected tests
2018-11-16 17:23:19,971 - tc-run - INFO - Quitting because no tests were affected.

@jugglinmike
Copy link
Contributor

@jgraham given the fact that this test should be applied to every response I
moved the assertion into the Session class.

This library is used by the WPT infrastructure to run all the other conformance
tests in browsers that implement the W3C WebDriver protocol. Enforcing strict
conformance criteria here could have severe effects on the rest of the test
suite. For instance, it may be wrong for an implementation to omit the
'Content-Type' header, but if we assert its presence in these bindings, then
that implementation will fail every test in WPT. This is unavoidable in severe
cases, but in cases where the tool can be permissive (e.g. just assuming the
body is JSON), doing so gives folks a better picture of the issue: a failing
WebDriver spec test. That's why I recommend making assertions like these within
the WebDriver conformance test suite itself, as per your original commit.

If we want to make this assertion for every WebDriver test, we could:

  • Keep the asserts here and update wptrunner to ignore assert statements in
    wptrunner's subprocess for reftests and testharness tests. In that case, we'd
    also have to update the existing infrastructure assertions to ensure they
    persist.
  • Add a generic "on response" hook to the library and attach an assertion in
    the wdspec test suite's setup code

Although either would suffer from the problem above, just on a smaller scale.

@andreastt
Copy link
Member

Or we could keep the checks in the client and emit a warning when the headers do not conform. I support the idea of moving the hard assertions to a separate test.

Copy link
Member

@andreastt andreastt left a comment

Choose a reason for hiding this comment

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

See comment above.

@christian-bromann
Copy link
Contributor Author

@andreastt @jugglinmike I moved the assertions into the assert_error and assert_success assertion helpers which are only used in the webdriver test harness. What do you think?

Copy link
Contributor

@jugglinmike jugglinmike left a comment

Choose a reason for hiding this comment

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

Good idea! Unlike the alternatives we've been considering, this may allow some responses to go untested. Those cases seem rare, so I think the simplicity of this approach wins out.

As for the timeout reported by Taskcluster: unlike with the previous solution, the system is now capable of identifying the affected tests:

2018-11-19 12:17:10,747 - tc-run - INFO - Identifying tests affected in range 'HEAD^'...
2018-11-19 12:17:26,483 - tc-run - INFO - Identified 138 affected tests

That's a lot of tests, possibly enough to exceed our 2-hour limit, though the logs for Chrome are suspiciously short...

@whimboo
Copy link
Contributor

whimboo commented Jan 28, 2019

The newly added assertion has failures:
https://tools.taskcluster.net/groups/cZgXyDz3T0S0m1Sh4X024w/tasks/Ub-qkzjxRoCtmPoz6V_PNg/runs/1/logs/public%2Flogs%2Flive.log#L96762

TypeError: assert_response_headers() takes exactly 2 arguments (1 given)

@christian-bromann can you please fix that? Thanks

@christian-bromann
Copy link
Contributor Author

@whimboo done

  • FF still fails because content type is application/json; charset=utf8 instead of application/json; charset=utf-8
  • Chrome still fails as it doesn't have a cache control header

@whimboo
Copy link
Contributor

whimboo commented Feb 26, 2019

I don't know why it fails with Firefox given that we shipped the fix for utf-8 with geckodriver 0.24.0. @jugglinmike do we still have to manually change the version number of the driver?

@jugglinmike
Copy link
Contributor

Nope

@whimboo
Copy link
Contributor

whimboo commented Feb 26, 2019

Oh wait. The Firefox job with the patch applied doesn't fail! What's failing is the verify job, which is killed by taskcluster after a runtime of 7200s.

@christian-bromann
Copy link
Contributor Author

@whimboo would closing and reopening the PR help?

@whimboo
Copy link
Contributor

whimboo commented Feb 27, 2019

Not sure. Running all the tests simply take that long. Someone might take a bit of time to check how long those verify tasks run in general, and maybe we have to bump up the maximum allowed time.

@gsnedders
Copy link
Member

@whimboo I'm not sure we can while we're using the GitHub Taskcluster integration, but @jgraham would know better. There are a few cases where we end up running lots of tests, but I think the longer term plan is to do something smarter and dynamically shard them.

In either case, if you think this looks good, we should just force-merge this.

@jgraham jgraham merged commit d4320a3 into web-platform-tests:master Feb 28, 2019
@christian-bromann christian-bromann deleted the cb-header-checks branch February 28, 2019 15:59
@mustjab
Copy link
Contributor

mustjab commented Feb 28, 2019

@jgraham I see WPT WebDriver tests failing in Chrome on Windows and Linux runs with this change, and pass after reverting it locally. Anyone else seeing this?

  Γöé webdriver\tests\add_cookie\add.py:17:
  Γöé _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  Γöé webdriver\tests\support\asserts.py:55: in assert_error
  Γöé     assert_response_headers(response.headers)
  Γöé _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  Γöé
  Γöé headers = {'content-length': '3243', 'content-type': 'application/json; charset=utf-8'}
  Γöé
  Γöé     def assert_response_headers(headers):
  Γöé         """
  Γöé         Method to assert response headers for WebDriver requests
  Γöé
  Γöé         :param headers: dict with header data
  Γöé         """
  Γöé >       assert 'cache-control' in headers
  Γöé E       AssertionError: assert 'cache-control' in {'content-length': '3243', 'content-type': 'application/json; charset=utf-8'}
  Γöé
  Γöé headers    = {'content-length': '3243', 'content-type': 'application/json; charset=utf-8'}
  Γöé
  Γöö webdriver\tests\support\asserts.py:82: AssertionError

@andreastt
Copy link
Member

@mustjab I think that would be expected, since chromedriver doesn’t return the mandated Cache-Control header.

See send a response in the spec.

@mustjab
Copy link
Contributor

mustjab commented Feb 28, 2019

@andreastt So should we change the way we run these tests? We run them on a daily basis and at this moment most of the tests fail due to this error.

@andreastt
Copy link
Member

Right, the assertion was added as a step to assert_success(), causing most—if not all!—of the wdspec tests to fail because the driver doesn’t return the mandated headers.

In order to avoid numerous workarounds, I think the best fix here is to insert a new line into https://cs.chromium.org/chromium/src/chrome/test/chromedriver/server/http_handler.cc?l=1125 and fix chromedriver. Alternatively we could back this change out temporarily to give you time to fix this.

@mustjab
Copy link
Contributor

mustjab commented Feb 28, 2019

Thank you! I'll outreach to ChromeDriver team to fix this and for now, we'll run with this fix internally.

@jgraham
Copy link
Contributor

jgraham commented Mar 1, 2019

I should have read the patch before merging it. I fully agree that this shouldn't be tested for every test but should be a specific set of tests or otherwise isolated from testing other features.

@christian-bromann
Copy link
Contributor Author

@jgraham I will tweak the patch and make it so that it is handled in a single test instead of being part of all assertions.

@whimboo
Copy link
Contributor

whimboo commented Mar 4, 2019

@jgraham, so we want to backout the already landed patch for a clean base? I don't think patching on top of the current patch is that great.

@andreastt
Copy link
Member

If @mustjab is fixing chromedriver, I don’t necessarily see the need to move the assertion to separate test, nor a reason to back this out.

@Hexcles
Copy link
Member

Hexcles commented Mar 5, 2019

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.

9 participants