Closed Bug 2090252 Opened 10 days ago Closed 7 days ago

2_test_login_totp.t reads the page before the TOTP enrollment and verification API calls return

Categories

(bugzilla.mozilla.org :: Continous Integration, defect)

defect

Tracking

()

RESOLVED FIXED

People

(Reporter: xavier.lhour, Assigned: xavier.lhour)

Details

Attachments

(1 external file)

qa/t/2_test_login_totp.t (test_selenium_2) fails intermittently, at a different step each time:

  • line 91, Correctly received secret32 from the form: the secret is empty, so enrollment then fails (title Error instead of User Preferences) and the rest of the file cascades
  • line 164 (test 42): after a valid code, the title is still Account Verification instead of Bugzilla Main Page

Both steps wait on an asynchronous API call that the test doesn't wait for:

  • Enrollment: js/account.js (line 106) writes the secret into the mfa-enable-totp-frame iframe only after await Bugzilla.API.get('user/mfa/totp/enroll') returns. The test reads #secret right after typing the password.
  • Verification: js/mfa_totp.js cancels the form submit, posts the code to user/mfa/verify_totp_code, and only submits the form (the navigation to the main page) once that returns. WebDriver's click returns before that navigation starts, and title_is checks once without waiting.

The same applies to every Submit on the verification page: lines 159 and 203 read #verify-totp-error, which is filled in when the API call fails, and lines 184 and 210 check the title after a recovery code.

The server side is not involved: Bugzilla::MFA::TOTP::check accepts the previous 30-second window too (verify($code, 1)), and the test and the web server run in the same container.

Seen recently on test_selenium_2: mozilla/bmo runs 41681665590, 41552084371 and 40949670595 (first attempts), and in bmo-private (run 40899070301 on 29/10, run 42253741795 twice on 06/11).

Possible fix: wait for each of these conditions before checking it, like 2_test_login_duo.t (line 81) already does for its title, e.g. a small helper in the test:

sub wait_until {
  my ($check) = @_;
  foreach (1 .. WAIT_TIME / 1000) {
    return 1 if $check->();
    sleep 1;
  }
  return 0;
}

used for the secret (non-empty #secret in the iframe), the title after each Submit, and the error text.

Assignee: nobody → xavier.lhour
Status: UNCONFIRMED → RESOLVED
Closed: 7 days ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: