Skip to content

Commit 965e56d

Browse files
thefrog-ghchromium-wpt-export-bot
authored andcommitted
Add WPT for query params for registration + refresh endpoints
This also fixes start_session.py to convert response.headers (type: ResponseHeaders) into a list before concatenating with another list. Change-Id: Ie759e2f24869ead60aa872e6989182ed98cc665c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7003076 Reviewed-by: Daniel Rubery <[email protected]> Commit-Queue: thefrog <[email protected]> Cr-Commit-Position: refs/heads/main@{#1524818}
1 parent 185978d commit 965e56d

File tree

4 files changed

+68
-4
lines changed

4 files changed

+68
-4
lines changed

device-bound-session-credentials/refresh_session.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import importlib
22
import json
3+
from urllib.parse import parse_qs
34
jwt_helper = importlib.import_module('device-bound-session-credentials.jwt_helper')
45
session_manager = importlib.import_module('device-bound-session-credentials.session_manager')
56

@@ -23,6 +24,9 @@ def main(request, response):
2324
}
2425
return (200, response.headers, json.dumps(response_body))
2526

27+
if test_session_manager.get_has_custom_query_param() and 'refreshQueryParam' not in parse_qs(request.url_parts.query):
28+
return (400, response.headers, "")
29+
2630
session_key = test_session_manager.get_session_key(session_id)
2731
if session_key == None:
2832
return (400, response.headers, "")
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!DOCTYPE html>
2+
<meta charset="utf-8">
3+
<script src="/resources/testharness.js"></script>
4+
<script src="/resources/testharnessreport.js"></script>
5+
<script src="helper.js" type="module"></script>
6+
7+
<script type="module">
8+
import { configureServer, expireCookie, documentHasCookie, waitForCookie, addCookieAndSessionCleanup, setupShardedServerState, postJson } from "./helper.js";
9+
10+
promise_test(async t => {
11+
await setupShardedServerState();
12+
const expectedCookieAndValue = "auth_cookie=abcdef0123";
13+
const expectedCookieAndAttributes = `${expectedCookieAndValue};Domain=${location.hostname};Path=/device-bound-session-credentials`;
14+
addCookieAndSessionCleanup(t);
15+
16+
// Configure server to:
17+
// 1. Check that registration has the query param specified below.
18+
// 2. Set a refresh endpoint query param in the session instructions and
19+
// verify that refresh has that query param.
20+
await configureServer({ hasCustomQueryParam: true });
21+
22+
// Prompt starting a session, and wait until registration completes. Pass
23+
// through the query param to registration.
24+
const registrationUrl = `start_session.py?registrationQueryParam=123`;
25+
const loginResponse = await postJson('login.py', { registrationUrl });
26+
assert_equals(loginResponse.status, 200);
27+
await waitForCookie(expectedCookieAndValue, /*expectCookie=*/true);
28+
29+
// Confirm that a request has the cookie set.
30+
const authResponse = await fetch('verify_authenticated.py');
31+
assert_equals(authResponse.status, 200);
32+
33+
// Trigger refresh by expiring the cookie.
34+
expireCookie(expectedCookieAndAttributes);
35+
assert_false(documentHasCookie(expectedCookieAndValue));
36+
// The server refresh will fail if the refresh endpoint query param is not
37+
// present during refresh.
38+
const authResponseAfterExpiry = await fetch('verify_authenticated.py');
39+
assert_equals(authResponseAfterExpiry.status, 200);
40+
assert_true(documentHasCookie(expectedCookieAndValue));
41+
}, "Registration and refresh endpoints can contain query params");
42+
</script>
43+

device-bound-session-credentials/session_manager.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def __init__(self):
5353
self.provider_key = None
5454
self.use_empty_response = False
5555
self.registration_extra_cookies = []
56+
self.has_custom_query_param = False
5657

5758
def next_session_id(self):
5859
return len(self.session_to_key_map)
@@ -164,6 +165,10 @@ def configure_state_for_test(self, configuration):
164165
for detail in registration_extra_cookies:
165166
self.registration_extra_cookies.append(CookieDetail(detail.get("nameAndValue"), detail.get("attributes")))
166167

168+
has_custom_query_param = configuration.get("hasCustomQueryParam")
169+
if has_custom_query_param is not None:
170+
self.has_custom_query_param = has_custom_query_param
171+
167172
def get_should_refresh_end_session(self):
168173
return self.should_refresh_end_session
169174

@@ -188,6 +193,9 @@ def get_refresh_sends_challenge(self):
188193
def set_has_called_refresh(self, has_called_refresh):
189194
self.has_called_refresh = has_called_refresh
190195

196+
def get_has_custom_query_param(self):
197+
return self.has_custom_query_param
198+
191199
def pull_server_state(self):
192200
return {
193201
"hasCalledRefresh": self.has_called_refresh
@@ -205,6 +213,11 @@ def get_cookie_details(self, session_id):
205213
def get_early_challenge(self, session_id):
206214
return self.session_to_early_challenge_map.get(session_id)
207215

216+
def get_refresh_url(self):
217+
if not self.has_custom_query_param:
218+
return self.refresh_url
219+
return self.refresh_url + "?refreshQueryParam=456"
220+
208221
def get_sessions_instructions_response_credentials(self, session_id, request):
209222
return list(map(lambda cookie_detail: {
210223
"type": "cookie",
@@ -230,7 +243,7 @@ def get_session_instructions_response(self, session_id, request):
230243

231244
response_body = {
232245
"session_identifier": str(response_session_id),
233-
"refresh_url": self.refresh_url,
246+
"refresh_url": self.get_refresh_url(),
234247
"scope": {
235248
"origin": scope_origin,
236249
"include_site": self.include_site,

device-bound-session-credentials/start_session.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import importlib
2+
from urllib.parse import parse_qs
23
jwt_helper = importlib.import_module('device-bound-session-credentials.jwt_helper')
34
session_manager = importlib.import_module('device-bound-session-credentials.session_manager')
45

@@ -15,13 +16,16 @@ def main(request, response):
1516
test_session_manager.set_session_key(session_id, jwt_header.get('jwk'))
1617

1718
if not verified or jwt_payload.get("jti") != "login_challenge_value":
18-
return (400, response.headers + extra_cookie_headers, "")
19+
return (400, list(response.headers) + extra_cookie_headers, "")
1920

2021
if jwt_payload.get("authorization") != test_session_manager.get_authorization_value():
21-
return (400, response.headers + extra_cookie_headers, "")
22+
return (400, list(response.headers) + extra_cookie_headers, "")
2223

2324
if jwt_payload.get("sub") is not None:
24-
return (400, response.headers + extra_cookie_headers, "")
25+
return (400, list(response.headers) + extra_cookie_headers, "")
26+
27+
if test_session_manager.get_has_custom_query_param() and 'registrationQueryParam' not in parse_qs(request.url_parts.query):
28+
return (400, list(response.headers) + extra_cookie_headers, "")
2529

2630
(code, headers, body) = test_session_manager.get_session_instructions_response(session_id, request)
2731
headers += extra_cookie_headers

0 commit comments

Comments
 (0)