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

Adding redirect count tests in case of cross origin redirections #4102

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

youennf
Copy link
Contributor

@youennf youennf commented Oct 28, 2016

Splitting redirect.py in two so that the scripts are easier to understand

@wpt-pr-bot
Copy link
Collaborator

Reviewers for this pull request are: @jdm and @youennf.

@annevk
Copy link
Member

annevk commented Feb 20, 2017

Could you rebase this? I'll review.

@youennf youennf force-pushed the add-redirect-count-cross-origin-tests branch from 0cff7cc to c1f2a66 Compare February 20, 2017 18:16
@ghost
Copy link

ghost commented Feb 20, 2017

View the complete job log.

Firefox (nightly channel)

Testing web-platform-tests at revision d4b422b
Using browser at version BuildID 20170123125947; SourceStamp 36486fdc3813ef7943ae5b07b4128866d1938a6c
Starting 10 test iterations
All results were stable

All results

5 tests ran
/fetch/api/redirect/redirect-count-cross-origin.html
Subtest Results
OK
Redirect 21 times, going to cross-origin after 10 PASS
Redirect 20 times, going to cross-origin after 10 with preflight FAIL
Redirect 20 times, last redirection to cross-origin PASS
Redirect 21 times, last redirection to cross-origin with preflight PASS
Redirect 21 times, going to cross-origin after 10 with preflight PASS
Redirect 20 times, last redirection to cross-origin with preflight PASS
Redirect 20 times, going to cross-origin after 10 PASS
Redirect 21 times, last redirection to cross-origin PASS
/fetch/api/redirect/redirect-count.html
Subtest Results
OK
Redirect 308 20 times PASS
Redirect 308 21 times PASS
Redirect 301 21 times PASS
Redirect 302 21 times PASS
Redirect 307 21 times PASS
Redirect 307 20 times PASS
Redirect 302 20 times PASS
Redirect 303 21 times PASS
Redirect 303 20 times PASS
Redirect 301 20 times PASS
/fetch/api/redirect/redirect-count-cross-origin-worker.html
Subtest Results
OK
Redirect 21 times, going to cross-origin after 10 PASS
Redirect 20 times, going to cross-origin after 10 with preflight FAIL
Redirect 20 times, last redirection to cross-origin PASS
Redirect 21 times, last redirection to cross-origin with preflight PASS
Redirect 21 times, going to cross-origin after 10 with preflight PASS
Redirect 20 times, last redirection to cross-origin with preflight PASS
Redirect 20 times, going to cross-origin after 10 PASS
Redirect 21 times, last redirection to cross-origin PASS
/fetch/api/redirect/redirect-count-worker.html
Subtest Results
OK
Redirect 308 20 times PASS
Redirect 308 21 times PASS
Redirect 301 21 times PASS
Redirect 302 21 times PASS
Redirect 307 21 times PASS
Redirect 307 20 times PASS
Redirect 302 20 times PASS
Redirect 303 21 times PASS
Redirect 303 20 times PASS
Redirect 301 20 times PASS
/fetch/api/redirect/redirect-schemes.html
Subtest Results
OK
Fetch: handling different schemes in redirects PASS
Fetch: handling different schemes in redirects 1 PASS
Fetch: handling different schemes in redirects 2 PASS
Fetch: handling different schemes in redirects 3 PASS
Fetch: handling different schemes in redirects 4 PASS
Fetch: handling different schemes in redirects 5 PASS

@ghost
Copy link

ghost commented Feb 20, 2017

View the complete job log.

Chrome (unstable channel)

Testing web-platform-tests at revision d4b422b
Using browser at version 58.0.3013.3 dev
Starting 10 test iterations
All results were stable

All results

5 tests ran
/fetch/api/redirect/redirect-count-cross-origin.html
Subtest Results
OK
Redirect 21 times, going to cross-origin after 10 FAIL
Redirect 20 times, going to cross-origin after 10 with preflight PASS
Redirect 20 times, last redirection to cross-origin PASS
Redirect 21 times, last redirection to cross-origin with preflight FAIL
Redirect 21 times, going to cross-origin after 10 with preflight FAIL
Redirect 20 times, last redirection to cross-origin with preflight PASS
Redirect 20 times, going to cross-origin after 10 PASS
Redirect 21 times, last redirection to cross-origin FAIL
/fetch/api/redirect/redirect-count.html
Subtest Results
OK
Redirect 308 20 times PASS
Redirect 308 21 times PASS
Redirect 301 21 times PASS
Redirect 302 21 times PASS
Redirect 307 21 times PASS
Redirect 307 20 times PASS
Redirect 302 20 times PASS
Redirect 303 21 times PASS
Redirect 303 20 times PASS
Redirect 301 20 times PASS
/fetch/api/redirect/redirect-count-cross-origin-worker.html
Subtest Results
OK
Redirect 21 times, going to cross-origin after 10 FAIL
Redirect 20 times, going to cross-origin after 10 with preflight PASS
Redirect 20 times, last redirection to cross-origin PASS
Redirect 21 times, last redirection to cross-origin with preflight FAIL
Redirect 21 times, going to cross-origin after 10 with preflight FAIL
Redirect 20 times, last redirection to cross-origin with preflight PASS
Redirect 20 times, going to cross-origin after 10 PASS
Redirect 21 times, last redirection to cross-origin FAIL
/fetch/api/redirect/redirect-count-worker.html
Subtest Results
OK
Redirect 308 20 times PASS
Redirect 308 21 times PASS
Redirect 301 21 times PASS
Redirect 302 21 times PASS
Redirect 307 21 times PASS
Redirect 307 20 times PASS
Redirect 302 20 times PASS
Redirect 303 21 times PASS
Redirect 303 20 times PASS
Redirect 301 20 times PASS
/fetch/api/redirect/redirect-schemes.html
Subtest Results
OK
Fetch: handling different schemes in redirects PASS
Fetch: handling different schemes in redirects 1 PASS
Fetch: handling different schemes in redirects 2 PASS
Fetch: handling different schemes in redirects 3 PASS
Fetch: handling different schemes in redirects 4 PASS
Fetch: handling different schemes in redirects 5 PASS

@annevk
Copy link
Member

annevk commented Feb 21, 2017

These look good. They also provide tests for #204, right?

@annevk
Copy link
Member

annevk commented Feb 21, 2017

I guess it's not testing that since cors/redirect-preflight.htm passes in Safari TP and is obviously wrong per allowing redirects after preflights.

How does requirePreflight in your test work then?

@youennf
Copy link
Contributor Author

youennf commented Feb 22, 2017

Link (#204) is probably not the right one.
requirePreflight should add a not-safe header and trigger preflight.
I do not think these tests check redirections as reponses to preflight.

Some of these tests should trigger using preflight after redirections.
Maybe we should add a check that preflight is done like for cors/redirect-preflight.htm.

Not sure why you say cors/redirect-preflight.htm is wrong. Can you elaborate?

@annevk
Copy link
Member

annevk commented Feb 22, 2017

Sorry, I meant whatwg/fetch#204. We changed CORS to allow redirects after a successful preflight, which would typically (not if you redirect to yourself I suppose) result in another preflight for the new destination.

That's why that test is wrong. Unfortunately when we made the change in Fetch we didn't have the policy of updating tests, but I'm trying to clean all that up now.

Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

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

Having looked at these tests once more I found several mistakes and I also still don't really understand the max1/max2 parameters and how they actually end up doing anything.

The other questions still stand of course.

urlParameters += allow_headers;
urlParameters += "&location=" + encodeURIComponent(redirectLocation + "?token=" + uuid_token + "&max_age=0&max_count=" + (maxCount1 + maxCount2) + allow_headers);

var maxCount = maxCount1 + maxCount2;
Copy link
Member

Choose a reason for hiding this comment

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

This should move up so you don't need to do this addition twice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

urlParameters += "&redirect_status=" + redirectStatus;
urlParameters += "&max_count=" + maxCount1;
urlParameters += allow_headers;
urlParameters += "&location=" + encodeURIComponent(redirectLocation + "?token=" + uuid_token + "&max_age=0&max_count=" + (maxCount1 + maxCount2) + allow_headers);
Copy link
Member

Choose a reason for hiding this comment

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

It seems you're adding allow_headers and max_age twice. Also max_age is never used in the Python resource.

Copy link
Member

Choose a reason for hiding this comment

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

You also set max_count twice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are added to the first looped URL and the second looped URL.
Might need to check though whether this is working using a web inspector.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, yeah, that probably works.

Copy link
Member

Choose a reason for hiding this comment

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

But max_age should probably still be removed.

var url = redirectUrl;
promise_test(function(test) {
return fetch(RESOURCES_DIR + "clean-stash.py?token=" + uuid_token).then(function(resp) {
assert_equals(resp.status, 200, "Clean stash response's status is 200");
Copy link
Member

Choose a reason for hiding this comment

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

It's always 200, no? The only difference seems to be whether the contents are "1" or "0".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is just a safety check that the overall test env is correct.

importScripts("/common/get-host-info.sub.js");
}

function redirectCount(desc, redirectUrl, redirectLocation, redirectStatus, maxCount1, maxCount2, requirePreflight)
Copy link
Member

Choose a reason for hiding this comment

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

redirectUrl and redirectLocation could probably be removed since they're always the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They should not always be the same.
The principle of the test is that we will redirect macCount1 times on redirectUrl.
On the last redirect to redirectUrl, we should be redirected to redirectLocation (bad name probably)
And we again are redirected macCount2 on redirectLocation.

Copy link
Member

Choose a reason for hiding this comment

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

But you always pass the same values as arguments here. There is no method call to redirectCount where they have a different value as far as I can tell.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

redirect-count.py is expected to do that (is_final_redirection check or something like that)

Copy link
Member

Choose a reason for hiding this comment

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

Maybe you're misunderstanding my feedback. My point was that they don't have to be arguments to the redirectCount() function as the redirectCount() function is never invoked with different values for them. Surely redirect-count.py is not invoking JavaScript?

redirectCount("Redirect 21 times, last redirection to cross-origin with preflight", redirUrl, crossOriginRedirUrl, 301, 20, 1, true);

redirectCount("Redirect 20 times, going to cross-origin after 10 with preflight", redirUrl, crossOriginRedirUrl, 303, 10, 10, true);
redirectCount("Redirect 21 times, going to cross-origin after 10 with preflight", redirUrl, crossOriginRedirUrl, 303, 10, 11, true);
Copy link
Member

Choose a reason for hiding this comment

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

Should we also test 307/308?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right

redirectCount("Redirect 20 times, going to cross-origin after 10 with preflight", redirUrl, crossOriginRedirUrl, 303, 10, 10, true);
redirectCount("Redirect 21 times, going to cross-origin after 10 with preflight", redirUrl, crossOriginRedirUrl, 303, 10, 11, true);

done();
Copy link
Member

Choose a reason for hiding this comment

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

Can you explain this call? I never quite understood that in the Fetch API tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Isn't it needed for worker-environment tests?

Copy link
Member

Choose a reason for hiding this comment

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

I think it works without.

Copy link
Member

Choose a reason for hiding this comment

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

Is it not for Single Page Tests?

headers.append(("Access-Control-Allow-Headers", request.GET['allow_headers']))
stashed_data['preflight'] = "1"
#Preflight is not redirected: return 200
if not "redirect_preflight" in request.GET:
Copy link
Member

Choose a reason for hiding this comment

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

Is redirect_preflight ever passed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do not remember. I can check to remove it.

urlParameters += "&location=" + encodeURIComponent(redirectLocation + "?token=" + uuid_token + "&max_age=0&max_count=" + (maxCount1 + maxCount2) + allow_headers);

var maxCount = maxCount1 + maxCount2;
var url = redirectUrl;
Copy link
Member

Choose a reason for hiding this comment

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

This seems rather redundant renaming?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

@annevk
Copy link
Member

annevk commented Mar 14, 2017

Also, let's start using the .any.js convention as per #5129.

@foolip
Copy link
Member

foolip commented Aug 16, 2018

@youennf, this PR is one of a few that's been inactive for over a year. Do you plan to take this up again?

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