Skip to content

Commit 7d1c21b

Browse files
authored
Set the assessment.event.expected_action when sending a CreateAssessment request. (GoogleCloudPlatform#11170)
1 parent f3cbb8e commit 7d1c21b

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

recaptcha_enterprise/demosite/app/backend/create_recaptcha_assessment.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717

1818

1919
def create_assessment(
20-
project_id: str, recaptcha_site_key: str, token: str
20+
project_id: str, recaptcha_site_key: str, token: str, expected_action: str
2121
) -> Assessment:
2222
"""Create an assessment to analyze the risk of a UI action.
2323
Args:
2424
project_id: Google Cloud Project ID
2525
recaptcha_site_key: Site key obtained by registering a domain/app to use recaptcha services.
2626
token: The token obtained from the client on passing the recaptchaSiteKey.
27+
expected_action: The expected action for this type of event.
2728
Returns: Assessment response.
2829
"""
2930

@@ -34,6 +35,7 @@ def create_assessment(
3435
event = recaptchaenterprise_v1.Event()
3536
event.site_key = recaptcha_site_key
3637
event.token = token
38+
event.expected_action = expected_action
3739

3840
assessment = recaptchaenterprise_v1.Assessment()
3941
assessment.event = event

recaptcha_enterprise/demosite/app/urls.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def on_homepage_load() -> Response:
6868
context.get("project_id"),
6969
context.get("site_key"),
7070
json_data["token"],
71+
recaptcha_action
7172
)
7273

7374
# Check if the token is valid, score is above threshold score and the action equals expected.
@@ -114,6 +115,7 @@ def on_signup() -> Response:
114115
context.get("project_id"),
115116
context.get("site_key"),
116117
json_data["token"],
118+
recaptcha_action
117119
)
118120

119121
# Check if the token is valid, score is above threshold score and the action equals expected.
@@ -162,6 +164,7 @@ def on_login() -> Response:
162164
context.get("project_id"),
163165
context.get("site_key"),
164166
json_data["token"],
167+
recaptcha_action
165168
)
166169

167170
# Check if the token is valid, score is above threshold score and the action equals expected.
@@ -210,6 +213,7 @@ def on_store_checkout() -> Response:
210213
context.get("project_id"),
211214
context.get("site_key"),
212215
json_data["token"],
216+
recaptcha_action
213217
)
214218

215219
# Check if the token is valid, score is above threshold score and the action equals expected.
@@ -257,6 +261,7 @@ def on_comment_submit() -> Response:
257261
context.get("project_id"),
258262
context.get("site_key"),
259263
json_data["token"],
264+
recaptcha_action
260265
)
261266

262267
# Check if the token is valid, score is above threshold score and the action equals expected.

0 commit comments

Comments
 (0)