Skip to content

Commit

Permalink
Replace TAOResponse.py with CustomCorsResponse.py
Browse files Browse the repository at this point in the history
*Deleted wpt/resource-timing/resources/TAOResponse.py
*Linked all the affecting tests to wpt/common/CustomCorsResponse.py

Bug: 1241646
Change-Id: I651cfc36afc8af76f8133ba113b6feb8ed11519b
  • Loading branch information
mrjoebcarvalho authored and chromium-wpt-export-bot committed Jan 18, 2024
1 parent 6333601 commit b925140
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 116 deletions.
5 changes: 5 additions & 0 deletions common/CustomCorsResponse.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ def query_parameter_or_default(param, default):
for k, v in headers.items():
response.headers.set(k, v)

img = request.GET.first(b'img') if b'img' in request.GET else None
if img:
response.headers.set(b"Content-Type", b"image/png")
with open(request.doc_root + "/resource-timing/resources/blue.png", "rb") as f:
response.content = f.read()
# Note that, in order to have out-of-the-box support for tests that don't call
# setup({'allow_uncaught_exception': true})
# we return a no-op JS payload. This approach will avoid syntax errors in
Expand Down
8 changes: 4 additions & 4 deletions resource-timing/TAO-port-mismatch-means-crossorigin.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
// have a Timing-Allow-Origin header value with the second port so this page's
// origin should not be a match.
const port_mismatch_url = `${location.protocol}//${ORIGINAL_HOST}:${PORT2}` +
`/resource-timing/resources/TAOResponse.py?` +
`tao=origin_port_${PORT2}`;
`/common/CustomCorsResponse.py?` +
`tao=origin_port_${PORT2}&headers=${encodeURIComponent('{"Access-Control-Allow-Origin":"*","Timing-Allow-Origin":"${PORT2}"}')}`;
attribute_test(
fetch, port_mismatch_url, invariants.assert_tao_failure_resource,
"A port mismatch must fail the TAO check");
Expand All @@ -29,8 +29,8 @@
// the Timing-Allow-Origin header's value. Therefore, the subresource's timings
// must be exposed.
const port_match_url = `${location.protocol}//${ORIGINAL_HOST}:${PORT2}` +
`/resource-timing/resources/TAOResponse.py?` +
`tao=origin_port_${PORT}`;
`/common/CustomCorsResponse.py?` +
`tao=origin_port_${PORT}&headers=${encodeURIComponent('{"Access-Control-Allow-Origin":"*","Timing-Allow-Origin":"*"}')}`;
attribute_test(
fetch, port_match_url, invariants.assert_tao_pass_no_redirect_http,
"An identical port must pass the TAO check");
Expand Down
2 changes: 1 addition & 1 deletion resource-timing/cross-origin-iframe.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
promise_test(async t => {
const iframe = document.createElement('iframe');
t.add_cleanup(() => iframe.remove());
iframe.src = `${REMOTE_ORIGIN}/resource-timing/resources/TAOResponse.py?tao=wildcard`;
iframe.src = `${REMOTE_ORIGIN}/common/CustomCorsResponse.py?headers=${encodeURIComponent('{"Timing-Allow-Origin": "*"}')}`;
document.body.appendChild(iframe);
const entry = await observe_entry(iframe.src);
invariants.assert_tao_pass_no_redirect_http(entry);
Expand Down
20 changes: 10 additions & 10 deletions resource-timing/opaque-origin.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ <h1>Description</h1>
<iframe id="frameContext"></iframe>
<script>
const {ORIGIN} = get_host_info();
const url = `${ORIGIN}/resource-timing/resources/TAOResponse.py`;
const url = `${ORIGIN}/common/CustomCorsResponse.py`;
const frame_content = `data:text/html;utf8,<body>
<script src="${ORIGIN}/resources/testharness.js"></` + `script>
<script src="${ORIGIN}/resource-timing/resources/entry-invariants.js">
</` + `script>
<script>
attribute_test(fetch, "${url}?tao=null",
invariants.assert_tao_pass_no_redirect_http,
"An opaque origin should be authorized to see resource timings when the" +
"TAO header is the string 'null'");
attribute_test(fetch, "${url}?tao=Null",
invariants.assert_tao_failure_resource,
"An opaque origin must not be authorized to see resource timings when " +
"the TAO header is the string 'Null'. (The check for 'null' must be " +
"case-sensitive)");
attribute_test(fetch, "${url}?tao=null&headers=${encodeURIComponent('{%22Access-Control-Allow-Origin%22:%22null%22,%22Timing-Allow-Origin%22:%22null%22}')}",
invariants.assert_tao_pass_no_redirect_http,
"An opaque origin should be authorized to see resource timings when the" +
"TAO header is the string 'null'");
attribute_test(fetch, "${url}?tao=Null&headers=${encodeURIComponent('{%22Access-Control-Allow-Origin%22:%22null%22,%22Timing-Allow-Origin%22:%22Null%22}')}",
invariants.assert_tao_failure_resource,
"An opaque origin must not be authorized to see resource timings when " +
"the TAO header is the string 'Null'. (The check for 'null' must be " +
"case-sensitive)");
</` + `script>
</body>`;

Expand Down
64 changes: 0 additions & 64 deletions resource-timing/resources/TAOResponse.py

This file was deleted.

40 changes: 21 additions & 19 deletions resource-timing/resources/iframe-TAO-crossorigin-port.sub.html
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
<!DOCTYPE html>
<html>
<body>
<script>
const url = '{{location[scheme]}}://{{host}}:{{ports[http][1]}}/resource-timing/resources/TAOResponse.py?tao=origin_port_{{ports[http][1]}}';
const observe = (list, observer) => {
<body>
<script>
var origin = window.location.origin;
const url =
"{{location[scheme]}}://{{host}}:{{ports[http][1]}}/common/CustomCorsResponse.py?tao=origin_port_{{ports[http][1]}}&headers="+encodeURIComponent('{"Timing-Allow-Origin": "' + origin + '"}') ;
const observe = (list, observer) => {
const entry = list.getEntries()[0];
const sum = entry.redirectStart +
entry.redirectEnd +
entry.domainLookupStart +
entry.domainLookupEnd +
entry.connectStart +
entry.connectEnd +
entry.secureConnectionStart +
entry.requestStart +
entry.responseStart +
entry.transferSize +
entry.encodedBodySize +
entry.decodedBodySize;
entry.redirectEnd +
entry.domainLookupStart +
entry.domainLookupEnd +
entry.connectStart +
entry.connectEnd +
entry.secureConnectionStart +
entry.requestStart +
entry.responseStart +
entry.transferSize +
entry.encodedBodySize +
entry.decodedBodySize;

const result = sum == 0 ? 'PASS' : 'FAIL';
window.top.postMessage(result, '*');
}
let observer = new PerformanceObserver(observe);
observer.observe({ entryTypes: ["resource"] });
let observer = new PerformanceObserver(observe);
observer.observe({ entryTypes: ["resource"] });
fetch(url).then(r => r.text());
</script>
</body>
</script>
</body>
</html>


3 changes: 2 additions & 1 deletion resource-timing/resources/iframe_TAO_match_origin.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
var dirName = dirname(location.href);
var client = new XMLHttpRequest,
// create a cross-origin request
url = dirName.replace('://', '://www.') + 'TAOResponse.py?tao=match_origin';
var origin = window.location.origin;
url = dirName.replace('://', '://www.') + `/common/CustomCorsResponse.py?tao=match_origin&headers=${encodeURIComponent('{"Timing-Allow-Origin": "' + origin + '"}')}`;
client.open("GET", url, false);
client.send(null);
}
Expand Down
4 changes: 2 additions & 2 deletions resource-timing/sizes-redirect-img.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
// don't, so this test covers extra code paths beyond those covered by
// resource-timing-sizes-redirect.html.

const baseUrl = new URL('/resource-timing/resources/TAOResponse.py?tao=wildcard&img=true', location.href).href;
const baseUrl = new URL(`/common/CustomCorsResponse.py?img=true&headers=${encodeURIComponent('{"Timing-Allow-Origin":"*","Access-Control-Allow-Origin":"*"}')}`, location.href).href;

const expectedSize = 1010;
const expectedSize = 35;

const hostInfo = get_host_info();

Expand Down
36 changes: 21 additions & 15 deletions resource-timing/sizes-redirect.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
// META: script=/resource-timing/resources/sizes-helper.js

const baseUrl =
new URL('/resource-timing/resources/TAOResponse.py?tao=wildcard', location.href).href;
const expectedSize = 4;
new URL(
`/common/CustomCorsResponse.py?tao=wildcard&headers=${
encodeURIComponent(
'{"Timing-Allow-Origin":"*","Access-Control-Allow-Origin":"*"}')}`,
location.href)
.href;
const expectedSize = 35;

const hostInfo = get_host_info();
performance.clearResourceTimings();
Expand All @@ -18,20 +23,21 @@ const accumulateEntry = () => {
});
};

const checkResourceSizes = () => {
const entries = performance.getEntriesByType('resource');
for (let entry of entries) {
checkSizeFields(entry, expectedSize, expectedSize + headerSize);
}
}
const checkResourceSizes =
() => {
const entries = performance.getEntriesByType('resource');
for (let entry of entries) {
checkSizeFields(entry, expectedSize, expectedSize + headerSize);
}
}

const redirectUrl = (redirectSourceOrigin, allowOrigin, targetUrl) => {
return redirectSourceOrigin +
'/resource-timing/resources/redirect-cors.py?allow_origin=' +
encodeURIComponent(allowOrigin) +
'&timing_allow_origin=*' +
'&location=' + encodeURIComponent(targetUrl);
}
const redirectUrl =
(redirectSourceOrigin, allowOrigin, targetUrl) => {
return redirectSourceOrigin +
'/resource-timing/resources/redirect-cors.py?allow_origin=*' +
'&timing_allow_origin=*' +
'&location=' + encodeURIComponent(targetUrl);
}

promise_test(() => {
// Use a different URL every time so that the cache behaviour does not
Expand Down

0 comments on commit b925140

Please sign in to comment.