Skip to content

Commit f71b1ea

Browse files
zenhackmoz-wptsync-bot
authored andcommitted
Bug 1756328 [wpt PR 32914] - Test webrtc/content-security-policy integration, a=testonly
Automatic update from web-platform-tests Test webrtc/content-security-policy integration (#32914) * Test webrtc/content-security-policy integration ...as specified in: - w3c/webappsec-csp#457 - w3c/webrtc-extensions#81 * Fix typos in comment. Co-authored-by: Jan-Ivar Bruaroey <[email protected]> * Fix ice candidate exchange in CSP webrtc tests. we should be passing each candidate to the *other* pc. Tests now behave as expected. * CSP webrtc tests: listen for connection state change, not gathering. See web-platform-tests/wpt#32914 (comment) * CSP webrtc tests: drop unnecessary stun server. * webrtc csp: simplify state checking "new" is the initial state. Co-authored-by: Jan-Ivar Bruaroey <[email protected]> Co-authored-by: Jan-Ivar Bruaroey <[email protected]> -- wpt-commits: 0abba58602758eb8be11c38788c6f51fed2529e4 wpt-pr: 32914
1 parent 3e4b204 commit f71b1ea

File tree

6 files changed

+152
-0
lines changed

6 files changed

+152
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<meta
6+
http-equiv="Content-Security-Policy"
7+
content="default-src 'none'; script-src 'self' 'unsafe-inline'">
8+
<title>webrtc allowed with default-src 'none'</title>
9+
<script src="/resources/testharness.js"></script>
10+
<script src="/resources/testharnessreport.js"></script>
11+
<script src="webrtc.js"></script>
12+
</head>
13+
14+
<body>
15+
<script>
16+
expectAllow();
17+
</script>
18+
<div id="log"></div>
19+
</body>
20+
21+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<meta http-equiv="Content-Security-Policy" content="webrtc 'allow';">
6+
<title>webrtc allowed with an explicit webrtc allowed policy</title>
7+
<script src="/resources/testharness.js"></script>
8+
<script src="/resources/testharnessreport.js"></script>
9+
<script src="webrtc.js"></script>
10+
</head>
11+
12+
<body>
13+
<script>
14+
expectAllow();
15+
</script>
16+
<div id="log"></div>
17+
</body>
18+
19+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<title>webrtc allowed with no policy</title>
6+
<script src="/resources/testharness.js"></script>
7+
<script src="/resources/testharnessreport.js"></script>
8+
<script src="webrtc.js"></script>
9+
</head>
10+
11+
<body>
12+
<script>
13+
expectAllow();
14+
</script>
15+
<div id="log"></div>
16+
</body>
17+
18+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<meta http-equiv="Content-Security-Policy" content="webrtc 'block';">
6+
<title>webrtc blocked with an explicit webrtc blocked policy</title>
7+
<script src="/resources/testharness.js"></script>
8+
<script src="/resources/testharnessreport.js"></script>
9+
<script src="webrtc.js"></script>
10+
</head>
11+
12+
<body>
13+
<script>
14+
expectBlock();
15+
</script>
16+
<div id="log"></div>
17+
</body>
18+
19+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<meta http-equiv="Content-Security-Policy" content="webrtc 'unrecognized';">
6+
<title>webrtc blocked with an unrecognized explicit webrtc policy</title>
7+
<script src="/resources/testharness.js"></script>
8+
<script src="/resources/testharnessreport.js"></script>
9+
<script src="webrtc.js"></script>
10+
</head>
11+
12+
<body>
13+
<script>
14+
expectBlock();
15+
</script>
16+
<div id="log"></div>
17+
</body>
18+
19+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
// Creates two RTCPeerConnection and tries to connect them. Returns
3+
// "allowed" if the connection is permitted, "blocked" if it is
4+
// blocked on both sides and "inconsistent" in the event that the
5+
// result is not the same on both sides (should never happen).
6+
async function tryConnect() {
7+
const pc1 = new RTCPeerConnection();
8+
const pc2 = new RTCPeerConnection();
9+
10+
// Returns a promise which resolves to a boolean which is true
11+
// if and only if pc.iceConnectionState settles in the "failed"
12+
// state, and never transitions to any state other than "new"
13+
// or "failed."
14+
const pcFailed = (pc) => {
15+
return new Promise((resolve, _reject) => {
16+
pc.oniceconnectionstatechange = (e) => {
17+
resolve(pc.iceConnectionState == "failed");
18+
};
19+
});
20+
}
21+
pc1Failed = pcFailed(pc1);
22+
pc2Failed = pcFailed(pc2);
23+
24+
// Creating a data channel is necessary to induce negotiation:
25+
const channel = pc1.createDataChannel('test');
26+
27+
// Usual webrtc signaling dance:
28+
pc1.onicecandidate = ({candidate}) => pc2.addIceCandidate(candidate);
29+
pc2.onicecandidate = ({candidate}) => pc1.addIceCandidate(candidate);
30+
const offer = await pc1.createOffer();
31+
await pc1.setLocalDescription(offer);
32+
await pc2.setRemoteDescription(pc1.localDescription);
33+
const answer = await pc2.createAnswer();
34+
await pc2.setLocalDescription(answer);
35+
await pc1.setRemoteDescription(pc2.localDescription);
36+
37+
const failed1 = await pc1Failed;
38+
const failed2 = await pc2Failed;
39+
if(failed1 && failed2) {
40+
return 'blocked';
41+
} else if(!failed1 && !failed2) {
42+
return 'allowed';
43+
} else {
44+
return 'inconsistent';
45+
}
46+
}
47+
48+
async function expectAllow() {
49+
promise_test(async () => assert_equals(await tryConnect(), 'allowed'));
50+
}
51+
52+
async function expectBlock() {
53+
promise_test(async () => assert_equals(await tryConnect(), 'blocked'));
54+
}
55+
56+
// vim: set ts=4 sw=4 et :

0 commit comments

Comments
 (0)