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

[html] Add tests for parsing COOP values #20873

Merged
merged 9 commits into from
Aug 25, 2020
52 changes: 52 additions & 0 deletions html/cross-origin-opener-policy/header-parsing.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<!doctype html>
<meta charset=utf-8>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="resources/common.js"></script>

<div id=log></div>
<script>

let tests = [
// popup Origin, popup COOP, expect opener

// None of the following should be recognized as "same-origin" (hence the
// "expected opener" value of `true`).
[SAME_ORIGIN, "same\u2014origin", true], // non-ASCII character (em dash)
Copy link
Member

Choose a reason for hiding this comment

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

Having seen the COEP comments I guess we should address here too what bytes are going to be emitted by the server. And what shortcomings this approach has (in that 0xFF isn't feasible). Perhaps we should change approach so we can effectively specify bytes?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, good point. I've changed it now for this PR to specify bytes.

Copy link
Member

Choose a reason for hiding this comment

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

Did you check that other users of common.js not rely on encodeURIComponent? Especially reporting tests might be impacted, perhaps?

Copy link
Member

Choose a reason for hiding this comment

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

Hmm yes, though it's not obvious from test results (chrome, firefox).

But instead of sprinkling encodeURIComponent everywhere, I'm thinking about doing it differently, like using an object for the 0xFF test case:

  [SAME_ORIGIN, { percentEscaped: "same%FForigin" }, true]

Copy link
Member

Choose a reason for hiding this comment

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

That seems reasonable, though I'd name it percentEncoded.

Copy link
Member

Choose a reason for hiding this comment

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

Done.

[SAME_ORIGIN, "same-origin;", true],
[SAME_ORIGIN, "\u000bsame-origin\u000b", true], // vertical tab
[SAME_ORIGIN, "\u000csame-origin\u000c", true], // form feed
[SAME_ORIGIN, "\u000dsame-origin\u000d", true], // carriage return
[SAME_ORIGIN, "Same-origin", true],
[SAME_ORIGIN, "same-origin;\tfoo=bar", true],
[SAME_ORIGIN, "same-origin ;foo=bar", true],
[SAME_ORIGIN, "same-origin; foo=bar;", true],
[SAME_ORIGIN, "\"same-origin\"", true], // HTTP structured fields "string" item
[SAME_ORIGIN, ":c2FtZS1vcmlnaW4=:", true], // HTTP structured fields "byte sequence" item
[SAME_ORIGIN, "?1", true], // HTTP structured fields "boolean" item
[SAME_ORIGIN, "1", true], // HTTP structured fields "integer or decimal" item
[SAME_ORIGIN, "$same-origin", true], // the item type is unrecognized
[SAME_ORIGIN, "same-origin same-origin", true],
[SAME_ORIGIN, "same-origin,same-origin", true],
[SAME_ORIGIN, "*same-origin ", true],

// All of the following should be recognized as "same-origin" (hence the
// "expected opener" value of `false`).
[SAME_ORIGIN, " same-origin", false],
[SAME_ORIGIN, "same-origin ", false],
[SAME_ORIGIN, "\tsame-origin", true],
[SAME_ORIGIN, "same-origin\t", true],
[SAME_ORIGIN, "same-origin;same-origin", false],
[SAME_ORIGIN, "same-origin; foo=bar", false],
];

run_coop_tests("unspecified", tests);

async_test((t) => {
const channelName = `none_to_${SAME_ORIGIN.name}_duplicated-header`;
const url = `${SAME_ORIGIN.origin}/html/cross-origin-opener-policy/resources/coop-same-origin-repeated.asis?channel=${channelName}`;

url_test(t, url, channelName, true);
}, `unspecified document opening popup to ${SAME_ORIGIN.origin} with repeated COOP header`);
</script>
6 changes: 3 additions & 3 deletions html/cross-origin-opener-policy/resources/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function run_coop_tests(documentCOOPValueTitle, testArray) {
coop_test(t, test[0], test[1],
`${documentCOOPValueTitle}_to_${test[0].name}_${test[1].replace(/ /g,"-")}`,
test[2], () => { t.done(); });
}, `${documentCOOPValueTitle} document opening popup to ${test[0].origin} with COOP: "${test[1]}"`);
}, `${documentCOOPValueTitle} document opening popup to ${test[0].origin} with COOP: ${format_value(test[1])}`);
}
}

Expand Down Expand Up @@ -91,5 +91,5 @@ function run_coop_test_iframe (documentTitle, iframe_origin, popup_origin, popup
assert_equals(payload.name, expects_name? name:"", 'name');
});
document.body.append(frame);
}, `${documentTitle} with ${iframe_origin.name} iframe opening popup a ${popup_origin.name} with COOP: ${popup_coop}`);
}
}, `${documentTitle} with ${iframe_origin.name} iframe opening popup a ${popup_origin.name} with COOP: ${format_value(popup_coop)}`);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
HTTP/1.1 200 OK
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Opener-Policy: same-origin
Server: BaseHTTP/0.3 Python/2.7.15+
Date: Wed, 18 Dec 2019 00:47:08 GMT

<!doctype html>
<meta charset=utf-8>
<script src="/common/get-host-info.sub.js"></script>
<iframe></iframe>
<script>
const navigate = new URL(location).searchParams.get("navigate");
if (navigate !== null) {
self.location = navigate;
} else {
const iframe = document.querySelector("iframe");
iframe.onload = () => {
const payload = { name: self.name, opener: !!self.opener };
iframe.contentWindow.postMessage(payload, "*");
};
const channelName = new URL(location).searchParams.get("channel");
iframe.src = `${get_host_info().HTTPS_ORIGIN}/html/cross-origin-opener-policy/resources/postback.html?channel=${channelName}`;
}
</script>