-
Notifications
You must be signed in to change notification settings - Fork 35
fix(tests/redirection): check HTTPS redirects properly #495
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
base: main
Are you sure you want to change the base?
Changes from all commits
91bffde
25e016f
976b935
2f8f43e
05d2fd5
9dc3151
e26aca6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,7 +55,7 @@ export async function retrieve(site, options = {}) { | |
|
|
||
| // use the http redirect chain | ||
| retrievals.responses.httpRedirects = httpSession.redirectHistory; | ||
| retrievals.responses.httpsRedirects = httpSession.redirectHistory; | ||
| retrievals.responses.httpsRedirects = httpsSession.redirectHistory; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add a test for this change specifically? |
||
|
|
||
| if (httpsSession.clientInstanceRecordingRedirects) { | ||
| retrievals.responses.auto = httpsSession.response; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -141,6 +141,77 @@ describe("Redirections", () => { | |
| assert.isFalse(res.pass); | ||
| }); | ||
|
|
||
| it("uses https redirects as fallback for destination and route when http redirects are empty", function () { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is possible in practice, if |
||
| reqs.responses.httpRedirects = []; | ||
| reqs.responses.httpsRedirects = [ | ||
| { | ||
| url: new URL("https://mozilla.org/"), | ||
| status: 301, | ||
| }, | ||
| { | ||
| url: new URL("https://www.mozilla.org/"), | ||
| status: 200, | ||
| }, | ||
| ]; | ||
|
|
||
| const res = redirectionTest(reqs); | ||
| assert.equal(res.destination, "https://www.mozilla.org/"); | ||
| assert.deepEqual(res.route, [ | ||
| "https://mozilla.org/", | ||
| "https://www.mozilla.org/", | ||
| ]); | ||
| }); | ||
|
|
||
| it("fails when https redirects back to http even if http redirects look fine", function () { | ||
| // HTTP chain correctly redirects to HTTPS on the same hostname | ||
| reqs.responses.httpRedirects = [ | ||
| { | ||
| url: new URL("http://mozilla.org/"), | ||
| status: 301, | ||
| }, | ||
| { | ||
| url: new URL("https://mozilla.org/"), | ||
| status: 200, | ||
| }, | ||
| ]; | ||
| // But the independent HTTPS session ends on HTTP — that should be an error | ||
| reqs.responses.httpsRedirects = [ | ||
| { | ||
| url: new URL("https://mozilla.org/"), | ||
| status: 301, | ||
| }, | ||
| { | ||
| url: new URL("http://mozilla.org/"), | ||
| status: 200, | ||
| }, | ||
| ]; | ||
|
|
||
| const res = redirectionTest(reqs); | ||
| assert.equal(res.result, Expectation.RedirectionNotToHttps); | ||
| assert.isFalse(res.pass); | ||
| }); | ||
|
|
||
| it("fails with redirection-missing when http redirects are empty but http response exists", function () { | ||
| // The OR fallback previously caused httpsRedirects to be used for pass/fail | ||
| // logic when httpRedirects is empty, which could produce a spurious pass. | ||
| reqs.responses.httpRedirects = []; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this possible? Wouldn't a site returning a http response have at least one value in this array with a 200 status? |
||
| reqs.responses.httpsRedirects = [ | ||
| { | ||
| url: new URL("https://mozilla.org/"), | ||
| status: 301, | ||
| }, | ||
| { | ||
| url: new URL("https://www.mozilla.org/"), | ||
| status: 200, | ||
| }, | ||
| ]; | ||
| // responses.http is still set (from emptyRequests), so the site is reachable over HTTP | ||
|
|
||
| const res = redirectionTest(reqs); | ||
| assert.equal(res.result, Expectation.RedirectionMissing); | ||
| assert.isFalse(res.pass); | ||
| }); | ||
|
|
||
| it("checks for all redirections preloaded", function () { | ||
| reqs.responses.httpRedirects = [ | ||
| { | ||
|
|
||
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.
Could we add a test for the "route is 1" condition here?