Skip to content

Commit 40759f9

Browse files
thefrog-ghchromium-wpt-export-bot
authored andcommitted
Add WPT for scope_specification
New test: set-scope-specification.https.html Bug: 353767385 Change-Id: I3c6d43aa6bebec43caef7fc1285576edd112d534 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6333587 Commit-Queue: thefrog <[email protected]> Reviewed-by: Daniel Rubery <[email protected]> Cr-Commit-Position: refs/heads/main@{#1430905}
1 parent 1e5fd41 commit 40759f9

File tree

7 files changed

+108
-16
lines changed

7 files changed

+108
-16
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import importlib
2+
util = importlib.import_module('device-bound-session-credentials.verify_authenticated_util')
3+
4+
def main(request, response):
5+
return util.verify_authenticated(request, response)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import importlib
2+
util = importlib.import_module('device-bound-session-credentials.verify_authenticated_util')
3+
4+
def main(request, response):
5+
return util.verify_authenticated(request, response)

device-bound-session-credentials/session_manager.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def __init__(self):
2525
self.registration_sends_challenge = False
2626
self.cookie_name_and_value = "auth_cookie=abcdef0123"
2727
self.has_called_refresh = False
28+
self.scope_specification_items = []
2829

2930
def create_new_session(self):
3031
session_id = str(len(self.session_to_key_map))
@@ -72,6 +73,10 @@ def configure_state_for_test(self, configuration):
7273
if cookie_name_and_value is not None:
7374
self.cookie_name_and_value = cookie_name_and_value
7475

76+
scope_specification_items = configuration.get("scopeSpecificationItems")
77+
if scope_specification_items is not None:
78+
self.scope_specification_items = scope_specification_items
79+
7580
def get_should_refresh_end_session(self):
7681
return self.should_refresh_end_session
7782

@@ -113,7 +118,7 @@ def get_session_instructions_response(self, session_id, request):
113118
"scope": {
114119
"origin": scope_origin,
115120
"include_site": True,
116-
"scope_specification" : [
121+
"scope_specification" : self.scope_specification_items + [
117122
{ "type": "exclude", "domain": request.url_parts.hostname, "path": "/device-bound-session-credentials/request_early_challenge.py" },
118123
{ "type": "exclude", "domain": request.url_parts.hostname, "path": "/device-bound-session-credentials/end_session_via_clear_site_data.py" },
119124
{ "type": "exclude", "domain": request.url_parts.hostname, "path": "/device-bound-session-credentials/pull_server_state.py" },
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<!DOCTYPE html>
2+
<meta charset="utf-8">
3+
<title>DBSC scope specification set</title>
4+
<script src="/resources/testharness.js"></script>
5+
<script src="/resources/testharnessreport.js"></script>
6+
<script src="helper.js" type="module"></script>
7+
8+
<script type="module">
9+
import { expireCookie, waitForCookie, addCookieAndSessionCleanup, setupShardedServerState, configureServer} from "./helper.js";
10+
11+
promise_test(async t => {
12+
await setupShardedServerState();
13+
const expectedCookieAndValue = "auth_cookie=abcdef0123";
14+
const expectedCookieAndAttributes = `${expectedCookieAndValue};Domain=${location.hostname};Path=/device-bound-session-credentials`;
15+
addCookieAndSessionCleanup(t, expectedCookieAndAttributes);
16+
17+
// Configure server to set scope specification.
18+
configureServer({ scopeSpecificationItems: [{
19+
"type": "include",
20+
"domain": location.hostname,
21+
"path": "/device-bound-session-credentials/excludeInScopeSpecification/excluded_verify_authenticated.py"
22+
}, {
23+
"type": "exclude",
24+
"domain": location.hostname,
25+
"path": "/device-bound-session-credentials/excludeInScopeSpecification"
26+
}, {
27+
"type": "include",
28+
"domain": location.hostname,
29+
"path": "/device-bound-session-credentials/includeInScopeSpecification/included_verify_authenticated.py"
30+
}, {
31+
"type": "exclude",
32+
"domain": location.hostname,
33+
"path": "/device-bound-session-credentials/verify_authenticated.py"
34+
}, {
35+
"type": "include",
36+
"domain": location.hostname,
37+
"path": "/device-bound-session-credentials/verify_authenticated_alternate.py"
38+
}, {
39+
"type": "include",
40+
"domain": `www1.${location.hostname}`,
41+
"path": "/device-bound-session-credentials/verify_authenticated.py"
42+
}, {
43+
"type": "exclude",
44+
"domain": `www2.${location.hostname}`,
45+
"path": "/device-bound-session-credentials/verify_authenticated.py"
46+
}] });
47+
48+
// Prompt starting a session, and wait until registration completes.
49+
const login_response = await fetch('login.py');
50+
assert_equals(login_response.status, 200);
51+
assert_true(await waitForCookie(expectedCookieAndValue));
52+
53+
async function expireCookieAndTriggerRequest(endpoint, expectRefresh) {
54+
expireCookie(expectedCookieAndAttributes);
55+
const auth_response = await fetch(endpoint, { credentials: "include" });
56+
assert_equals(auth_response.status, expectRefresh ? 200 : 401);
57+
}
58+
59+
await expireCookieAndTriggerRequest("verify_authenticated.py", /*expectRefresh=*/false);
60+
await expireCookieAndTriggerRequest("verify_authenticated_alternate.py", /*expectRefresh=*/true);
61+
// This one is marked as included, but excludeInScopeSpecification/ is marked as excluded, and order matters.
62+
await expireCookieAndTriggerRequest("excludeInScopeSpecification/excluded_verify_authenticated.py", /*expectRefresh=*/false);
63+
await expireCookieAndTriggerRequest("includeInScopeSpecification/included_verify_authenticated.py", /*expectRefresh=*/true);
64+
await expireCookieAndTriggerRequest(`${location.protocol}//www1.${location.hostname}:${location.port}/device-bound-session-credentials/verify_authenticated.py`, /*expectRefresh=*/true);
65+
await expireCookieAndTriggerRequest(`${location.protocol}//www2.${location.hostname}:${location.port}/device-bound-session-credentials/verify_authenticated.py`, /*expectRefresh=*/false);
66+
}, "Scope specification configuration is respected");
67+
</script>
Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
1-
def main(request, response):
2-
expected_cookie_name_and_value = request.body
3-
if expected_cookie_name_and_value == b"":
4-
expected_cookie_name_and_value = b"auth_cookie=abcdef0123"
5-
(expected_name, expected_value) = expected_cookie_name_and_value.split(b"=")
6-
7-
headers = []
8-
# Only CORS requests need the CORS headers
9-
if request.headers.get(b"origin") != None:
10-
headers = [(b"Access-Control-Allow-Origin",request.headers.get(b"origin")),
11-
(b"Access-Control-Allow-Credentials", b"true")]
1+
import importlib
2+
util = importlib.import_module('device-bound-session-credentials.verify_authenticated_util')
123

13-
cookie = request.cookies.get(expected_name)
14-
if cookie == None or cookie.value != expected_value:
15-
return (401, headers, "")
16-
return (200, headers, "")
4+
def main(request, response):
5+
return util.verify_authenticated(request, response)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import importlib
2+
util = importlib.import_module('device-bound-session-credentials.verify_authenticated_util')
3+
4+
def main(request, response):
5+
return util.verify_authenticated(request, response)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
def verify_authenticated(request, response):
2+
expected_cookie_name_and_value = request.body
3+
if expected_cookie_name_and_value == b"":
4+
expected_cookie_name_and_value = b"auth_cookie=abcdef0123"
5+
(expected_name, expected_value) = expected_cookie_name_and_value.split(b"=")
6+
7+
headers = []
8+
# Only CORS requests need the CORS headers
9+
if request.headers.get(b"origin") != None:
10+
headers = [(b"Access-Control-Allow-Origin",request.headers.get(b"origin")),
11+
(b"Access-Control-Allow-Credentials", b"true")]
12+
13+
cookie = request.cookies.get(expected_name)
14+
if cookie == None or cookie.value != expected_value:
15+
return (401, headers, "")
16+
return (200, headers, "")

0 commit comments

Comments
 (0)