You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 7abc9ca
Browse filesBrowse the repository at this point in the historyBrowse files
Add WP-CLI command tests and address review feedback
Adds PHPUnit coverage for Two_Factor_CLI_Command (status, disable, enable,
list-providers, backup-codes generate, unlock) and for the new
Two_Factor_Core::clear_login_rate_limit() helper.
Because the WP-CLI runtime is not loaded during PHPUnit, lightweight test
doubles for WP_CLI, WP_CLI_Command, and the WP_CLI\Utils helpers are added
under tests/cli/ to capture output and simulate the error()/confirm() exit
behaviour.
Also fixes the issues raised in review on PR WordPress#905:
- backup-codes generate now enables the Two_Factor_Backup_Codes provider
(mirroring rest_generate_codes()) so the codes are usable at login instead
of being stored but never offered.
- enable, disable, and the full reset now destroy the user's sessions when
their enabled providers change, matching the profile-page behaviour.
- The full reset no longer clears _two_factor_password_was_reset, so a
rescued user still sees the notice explaining why their old password
stopped working.
- Removes the misleading reference to a non-existent "Phase 3" totp
subcommand from the TOTP enable error message.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
/* translators: 1: comma-separated provider names, 2: user login */
@@ -389,7 +423,7 @@ public function enable( $args, $assoc_args ) {
389
423
WP_CLI::error(
390
424
sprintf(
391
425
/* translators: %s: provider class name */
392
-
__( 'Provider %s requires a pre-shared secret and cannot be enabled from the CLI. Set it up via the user profile page or the totp subcommand (Phase 3).', 'two-factor' ),
426
+
__( 'Provider %s requires a pre-shared secret and cannot be enabled from the CLI. Set it up via the user profile page.', 'two-factor' ),
393
427
$provider
394
428
)
395
429
);
@@ -402,7 +436,11 @@ public function enable( $args, $assoc_args ) {
-`enable` — enabling secret-free providers; session destruction on change; refusing TOTP (no stale "Phase 3" pointer) and backup codes; unknown provider and missing-argument errors
170
+
-`disable` (single provider) — removal leaves others intact, session destruction on change, idempotent no-op, confirmation required without `--yes`
171
+
-`disable` (all) — full reset clears providers/throttle/nonce state and destroys sessions, preserves the compromised-password-reset flag, idempotent no-op, stale-meta cleanup guarding the fail-closed email fallback, confirmation required without `--yes`
172
+
-`backup-codes generate` — default and `--count` code counts, regeneration replaces the set, enables the provider so codes are usable at login, session destruction when first enabled, unknown-action and missing-argument errors
173
+
-`unlock` — clears the login throttle for a rate-limited user; no-op message otherwise
174
+
157
175
## Test Helpers
158
176
159
177
-**`tests/bootstrap.php`** — Locates the WordPress test library (via `WP_TESTS_DIR` env var, relative path, or `/tmp/wordpress-tests-lib`), loads the plugin via `muplugins_loaded`, then boots the WP test environment.
160
178
-**`tests/class-two-factor-dummy-secure.php`** — Defines `Two_Factor_Dummy_Secure`, a test-only provider class that spoofs the key of `Two_Factor_Dummy` but always fails `validate_authentication`. Used by `Tests_Two_Factor_Dummy_Secure` and some core tests.
179
+
-**`tests/cli/`** — WP-CLI test doubles loaded by `Tests_Two_Factor_CLI_Command`: `class-wp-cli-command.php` (empty base-class stub), `class-wp-cli.php` (captures output into `WP_CLI::$logger`, throws on `error()`/`confirm()`), `class-wp-cli-mock-exit-exception.php` (stands in for a process exit), and `wp-cli-utils.php` (`WP_CLI\Utils\get_flag_value()` and `format_items()`).
0 commit comments