-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FedCM] Refactor the wpt tests request params check
This patch moves the request params check to one place to avoid the unnecessary duplication. Bug: None Change-Id: I8d2e525b09718ab6ea2ba1483356de6a6ef0732c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4851310 Reviewed-by: Nicolás Peña <npm@chromium.org> Commit-Queue: Yi Gu <yigu@chromium.org> Cr-Commit-Position: refs/heads/main@{#1197107}
- Loading branch information
1 parent
e0c0429
commit 64f8ed3
Showing
10 changed files
with
128 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
credential-management/support/fedcm/request-params-check.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
def commonCheck(request): | ||
if request.headers.get(b"Accept") != b"application/json": | ||
return (531, [], "Wrong Accept") | ||
if request.headers.get(b"Sec-Fetch-Dest") != b"webidentity": | ||
return (532, [], "Wrong Sec-Fetch-Dest header") | ||
if request.headers.get(b"Referer"): | ||
return (533, [], "Should not have Referer") | ||
if request.headers.get(b"Sec-Fetch-Mode") != b"no-cors": | ||
return (534, [], "Wrong Sec-Fetch-Mode header") | ||
|
||
def commonUncredentialedRequestCheck(request): | ||
if len(request.cookies) > 0: | ||
return (535, [], "Cookie should not be sent to this endpoint") | ||
if request.headers.get(b"Sec-Fetch-Site") != b"cross-site": | ||
return (536, [], "Wrong Sec-Fetch-Site header") | ||
|
||
def commonCredentialedRequestCheck(request): | ||
if request.cookies.get(b"cookie") != b"1": | ||
return (537, [], "Missing cookie") | ||
if request.headers.get(b"Sec-Fetch-Site") != b"none": | ||
return (538, [], "Wrong Sec-Fetch-Site header") | ||
|
||
def manifestCheck(request): | ||
common_error = commonCheck(request) | ||
if (common_error): | ||
return common_error | ||
common_uncredentialed_error = commonUncredentialedRequestCheck(request) | ||
if (common_uncredentialed_error): | ||
return common_uncredentialed_error | ||
|
||
if request.headers.get(b"Origin"): | ||
return (539, [], "Should not have Origin") | ||
|
||
def clientMetadataCheck(request): | ||
if (request.GET.get(b'skip_checks', b'0') != b'1'): | ||
common_error = commonCheck(request) | ||
if (common_error): | ||
return common_error | ||
common_uncredentialed_error = commonUncredentialedRequestCheck(request) | ||
if (common_uncredentialed_error): | ||
return common_uncredentialed_error | ||
|
||
if not request.headers.get(b"Origin"): | ||
return (540, [], "Missing Origin") | ||
|
||
def accountsCheck(request): | ||
common_error = commonCheck(request) | ||
if (common_error): | ||
return common_error | ||
common_credentialed_error = commonCredentialedRequestCheck(request) | ||
if (common_credentialed_error): | ||
return common_credentialed_error | ||
|
||
if request.headers.get(b"Origin"): | ||
return (539, [], "Should not have Origin") | ||
|
||
def tokenCheck(request): | ||
common_error = commonCheck(request) | ||
if (common_error): | ||
return common_error | ||
common_credentialed_error = commonCredentialedRequestCheck(request) | ||
if (common_credentialed_error): | ||
return common_credentialed_error | ||
|
||
if not request.headers.get(b"Origin"): | ||
return (540, [], "Missing Origin") | ||
if request.method != "POST": | ||
return (541, [], "Method is not POST") | ||
if request.headers.get(b"Content-Type") != b"application/x-www-form-urlencoded": | ||
return (542, [], "Wrong Content-Type") | ||
if not request.POST.get(b"client_id"): | ||
return (543, [], "Missing 'client_id' POST parameter") | ||
if not request.POST.get(b"account_id"): | ||
return (544, [], "Missing 'account_id' POST parameter") | ||
if not request.POST.get(b"disclosure_text_shown"): | ||
return (545, [], "Missing 'disclosure_text_shown' POST parameter") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 6 additions & 27 deletions
33
credential-management/support/fedcm/token_with_account_auto_selected_flag.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 6 additions & 27 deletions
33
credential-management/support/fedcm/token_with_account_id.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters