Skip to content

Commit 326810a

Browse files
kalutesV8 LUCI CQ
authored andcommitted
Dismiss google account suspicious activity
Test accounts sometimes are flagged for suspicious activity which adds a popup on most workspace pages when the account is logged in. Dismiss this flag during login if present. Change-Id: I266bd2d7c2fa2a0f29c49919d9ca29aeac69b533 Reviewed-on: https://chromium-review.googlesource.com/c/crossbench/+/6650142 Commit-Queue: Kameron Lutes <[email protected]> Reviewed-by: Charles Dick <[email protected]>
1 parent 6acc0ec commit 326810a

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

crossbench/benchmarks/loading/config/login/google.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,27 @@
6262
"source": "js",
6363
})
6464

65+
SUSPICIOUS_ACTIVITY_URL: str = "https://myaccount.google.com/notifications"
66+
CHCEK_SUSPICIOUS_ACTIVITY: ClickAction = ClickAction.parse({
67+
"action": "click",
68+
"pos": {
69+
"selector": "[aria-label='Check activity']",
70+
"required": True,
71+
},
72+
"source": "js",
73+
})
74+
75+
CLICK_YES_IT_WAS_ME: ClickAction = ClickAction.parse({
76+
"action": "click",
77+
"pos": {
78+
"selector": "xpath///button[./span[text()='Yes, it was me']]",
79+
"required": True,
80+
"wait": True,
81+
},
82+
"source": "js",
83+
"verify": "xpath///body[not(./button[./span[text()='Yes, it was me']])]",
84+
})
85+
6586

6687
class GoogleLogin(PresetLoginBlock):
6788
"""Google-specific login steps."""
@@ -131,10 +152,25 @@ def run_with(self, runner: ActionRunner, run: Run,
131152
self._dismiss_login_page(action, runner, run, SKIP_HOME_ADDRESS,
132153
ADD_HOME_ADDRESS_REDIRECT, time_left)
133154

155+
self._clear_suspicious_activity(action, runner, run)
156+
157+
134158
def _dismiss_login_page(self, action: Actions, runner: ActionRunner, run: Run,
135159
click_action: ClickAction, current_url: str,
136160
timeout: dt.timedelta) -> None:
137161
runner.click(run, click_action)
138162
action.wait_js_condition(
139163
f"return !document.URL.startsWith('{current_url}');", 0.2, timeout)
140164
action.wait_for_ready_state(ReadyState.COMPLETE, timeout)
165+
166+
def _clear_suspicious_activity(self, action: Actions, runner: ActionRunner,
167+
run: Run):
168+
has_suspicious_activity = action.js(
169+
"return document.querySelector("
170+
"\"[aria-label='Check activity']\") != null;")
171+
172+
if not has_suspicious_activity:
173+
return
174+
175+
runner.click(run, CHCEK_SUSPICIOUS_ACTIVITY)
176+
runner.click(run, CLICK_YES_IT_WAS_ME)

tests/crossbench/benchmarks/loading/config/test_login.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ def expect_successful_google_login(self):
8181
self.browser.expect_js(result=True)
8282
# Return successful login URL
8383
self.browser.expect_js(result="https://myaccount.google.com")
84+
# Check for suspicious activity
85+
self.browser.expect_js(result=False)
8486

8587
def test_google_account(self):
8688
config = PagesConfig.parse(self._CONFIG_DATA)
@@ -111,7 +113,7 @@ def test_logged_in_non_google_account(self):
111113
self.run.story_secrets = page[0].secrets
112114
config.pages[0].login.run_with(self.action_runner, self.run, page[0])
113115

114-
def test_account_maintenance_redirects_dismissed(self):
116+
def test_full_account_maintenance_flow(self):
115117
config = PagesConfig.parse(self._CONFIG_DATA)
116118
page = LoadingPageFilter.stories_from_config(self.mock_args(), config)
117119

@@ -168,6 +170,18 @@ def test_account_maintenance_redirects_dismissed(self):
168170
# Return successful login URL
169171
self.browser.expect_js(result="https://myaccount.google.com")
170172

173+
# Return suspicious activity is present
174+
self.browser.expect_js(result=True)
175+
# Click suspicious activity button
176+
self.browser.expect_js(result=1)
177+
# Wait for 'yes' button
178+
self.browser.expect_js(result=1)
179+
# Click 'yes' button
180+
self.browser.expect_js(result=1)
181+
# Wait 'yes' button not present.
182+
self.browser.expect_js(result=1)
183+
184+
171185
self.run.story_secrets = page[0].secrets
172186
config.pages[0].login.run_with(self.action_runner, self.run, page[0])
173187

tests/crossbench/benchmarks/loading/test_loading.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,8 @@ def setup_expected_google_login_js(self):
511511
JsInvocation(True),
512512
# Return successful login URL
513513
JsInvocation("https://myaccount.google.com", re.compile(r".*URL.*")),
514+
# No suspicious activity
515+
JsInvocation(False),
514516
]
515517
for browser in self.browsers:
516518
for script in expected_scripts:

0 commit comments

Comments
 (0)