-
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
Adding redirect count tests in case of cross origin redirections #4102
base: master
Are you sure you want to change the base?
Adding redirect count tests in case of cross origin redirections #4102
Conversation
Could you rebase this? I'll review. |
0cff7cc
to
c1f2a66
Compare
Firefox (nightly channel)Testing web-platform-tests at revision d4b422b All results5 tests ran/fetch/api/redirect/redirect-count-cross-origin.html
/fetch/api/redirect/redirect-count.html
/fetch/api/redirect/redirect-count-cross-origin-worker.html
/fetch/api/redirect/redirect-count-worker.html
/fetch/api/redirect/redirect-schemes.html
|
Chrome (unstable channel)Testing web-platform-tests at revision d4b422b All results5 tests ran/fetch/api/redirect/redirect-count-cross-origin.html
/fetch/api/redirect/redirect-count.html
/fetch/api/redirect/redirect-count-cross-origin-worker.html
/fetch/api/redirect/redirect-count-worker.html
/fetch/api/redirect/redirect-schemes.html
|
These look good. They also provide tests for #204, right? |
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? |
Link (#204) is probably not the right one. Some of these tests should trigger using preflight after redirections. Not sure why you say cors/redirect-preflight.htm is wrong. Can you elaborate? |
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. |
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.
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; |
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.
This should move up so you don't need to do this addition twice.
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
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); |
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.
It seems you're adding allow_headers and max_age twice. Also max_age is never used in the Python resource.
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.
You also set max_count twice.
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.
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.
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.
Sorry, yeah, that probably works.
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.
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"); |
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.
It's always 200, no? The only difference seems to be whether the contents are "1" or "0".
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.
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) |
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.
redirectUrl and redirectLocation could probably be removed since they're always the same.
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.
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.
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.
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.
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.
redirect-count.py is expected to do that (is_final_redirection check or something like that)
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.
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); |
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.
Should we also test 307/308?
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.
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(); |
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.
Can you explain this call? I never quite understood that in the Fetch API tests.
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.
Isn't it needed for worker-environment tests?
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 think it works without.
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.
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: |
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.
Is redirect_preflight ever passed?
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.
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; |
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.
This seems rather redundant renaming?
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
Also, let's start using the .any.js convention as per #5129. |
@youennf, this PR is one of a few that's been inactive for over a year. Do you plan to take this up again? |
Splitting redirect.py in two so that the scripts are easier to understand