Skip to content

Commit

Permalink
Add tests to verify origin headers sent by ping (web-platform-tests#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
rwlbuis authored Feb 5, 2020
1 parent 532ecd2 commit ef1a164
Show file tree
Hide file tree
Showing 10 changed files with 219 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Ping attribute Origin Header No Referrer When Downgrade Policy</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<meta name='referrer' content='no-referrer-when-downgrade'>
</head>
<body>
<a id="a" href="#">
<script src="/common/utils.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/resources/chromium/enable-hyperlink-auditing.js"></script>
<script src="header-origin.js"></script>
<script>
testOriginHeader(self.location.origin);
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Ping attribute Origin Header No Referrer Policy</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<meta name='referrer' content='no-referrer'>
</head>
<body>
<a id="a" href="#">
<script src="/common/utils.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/resources/chromium/enable-hyperlink-auditing.js"></script>
<script src="header-origin.js"></script>
<script>
testOriginHeader("null");
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Ping attribute Origin Header Origin When Cross Origin Policy</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<meta name='referrer' content='origin-when-cross-origin'>
</head>
<body>
<a id="a" href="#">
<script src="/common/utils.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/resources/chromium/enable-hyperlink-auditing.js"></script>
<script src="header-origin.js"></script>
<script>
testOriginHeader(self.location.origin);
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Ping attribute Origin Header Origin Policy</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<meta name='referrer' content='origin'>
</head>
<body>
<a id="a" href="#">
<script src="/common/utils.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/resources/chromium/enable-hyperlink-auditing.js"></script>
<script src="header-origin.js"></script>
<script>
testOriginHeader(self.location.origin);
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Ping attribute Origin Header Same Origin Policy</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<meta name='referrer' content='same-origin'>
</head>
<body>
<a id="a" href="#">
<script src="/common/utils.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/resources/chromium/enable-hyperlink-auditing.js"></script>
<script src="header-origin.js"></script>
<script>
testOriginHeader(self.location.origin);
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Ping attribute Origin Header Strict Origin When Cross Origin Policy</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<meta name='referrer' content='strict-origin-when-cross-origin'>
</head>
<body>
<a id="a" href="#">
<script src="/common/utils.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/resources/chromium/enable-hyperlink-auditing.js"></script>
<script src="header-origin.js"></script>
<script>
testOriginHeader(self.location.origin);
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Ping attribute Origin Header Strict Origin Policy</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<meta name='referrer' content='strict-origin'>
</head>
<body>
<a id="a" href="#">
<script src="/common/utils.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/resources/chromium/enable-hyperlink-auditing.js"></script>
<script src="header-origin.js"></script>
<script>
testOriginHeader(self.location.origin);
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Ping attribute Origin Header Unsafe Url Policy</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<meta name='referrer' content='unsafe-url'>
</head>
<body>
<a id="a" href="#">
<script src="/common/utils.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/resources/chromium/enable-hyperlink-auditing.js"></script>
<script src="header-origin.js"></script>
<script>
testOriginHeader(self.location.origin);
</script>
</body>
</html>
19 changes: 19 additions & 0 deletions html/semantics/links/downloading-resources/header-origin.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Ping attribute Origin no Referrer Policy</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<a id="a" href="#">
<script src="/common/utils.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/resources/chromium/enable-hyperlink-auditing.js"></script>
<script src="header-origin.js"></script>
<script>
testOriginHeader(self.location.origin);
</script>
</body>
</html>
40 changes: 40 additions & 0 deletions html/semantics/links/downloading-resources/header-origin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const RESOURCES_DIR = "/html/semantics/links/downloading-resources/resources/";

function testOriginHeader(expectedOrigin) {
var id = self.token();
let testUrl = RESOURCES_DIR + "inspect-header.py?header=origin&cmd=put&id=" + id;

promise_test(function(test) {
const anchor = document.getElementById("a");
anchor.setAttribute("ping", testUrl);
anchor.click();
return pollResult(id) .then(result => {
assert_equals(result, expectedOrigin, "Correct origin header result");
});
}, "Test origin header " + RESOURCES_DIR);
}

// Sending a ping is an asynchronous and non-blocking request to a web server.
// We may have to create a poll loop to get result from server
function pollResult(id) {
let checkUrl = RESOURCES_DIR + "inspect-header.py?header=origin&cmd=get&id=" + id;

return new Promise(resolve => {
function checkResult() {
fetch(checkUrl).then(
function(response) {
assert_equals(response.status, 200, "Inspect header response's status is 200");
let result = response.headers.get("x-request-origin");

if (result != undefined) {
resolve(result);
} else {
step_timeout(checkResult.bind(this), 100);
}
});
}

checkResult();
});

}

0 comments on commit ef1a164

Please sign in to comment.