Skip to content

Commit

Permalink
TOTP: Ignore controller/UI code when calculating coverage
Browse files Browse the repository at this point in the history
These functions are either untestable in a pure unit test, or aren't worth testing. They're better suited to manual testing and e2e tests.
  • Loading branch information
iandunn committed Oct 12, 2022
1 parent 9f2bfd4 commit c6a6c41
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion providers/class-two-factor-totp.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ class Two_Factor_Totp extends Two_Factor_Provider {
const DEFAULT_TIME_STEP_ALLOWANCE = 4;

/**
* Chracters used in base32 encoding.
* Characters used in base32 encoding.
*
* @var string
*/
private static $base_32_chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';

/**
* Class constructor. Sets up hooks, etc.
*
* @codeCoverageIgnore
*/
protected function __construct() {
add_action( 'two_factor_user_options_' . __CLASS__, array( $this, 'user_two_factor_options' ) );
Expand All @@ -58,6 +60,8 @@ protected function __construct() {

/**
* Ensures only one instance of this class exists in memory at any one time.
*
* @codeCoverageIgnore
*/
public static function get_instance() {
static $instance;
Expand All @@ -81,6 +85,8 @@ public function get_label() {
* @param string $action Action ID.
*
* @return void
*
* @codeCoverageIgnore
*/
public function user_settings_action( $user_id, $action ) {
if ( self::ACTION_SECRET_DELETE === $action ) {
Expand All @@ -94,6 +100,8 @@ public function user_settings_action( $user_id, $action ) {
* @param integer $user_id User ID.
*
* @return string
*
* @codeCoverageIgnore
*/
protected function get_token_delete_url_for_user( $user_id ) {
return Two_Factor_Core::get_user_update_action_url( $user_id, self::ACTION_SECRET_DELETE );
Expand All @@ -104,6 +112,8 @@ protected function get_token_delete_url_for_user( $user_id ) {
*
* @param WP_User $user The current user being edited.
* @return false
*
* @codeCoverageIgnore
*/
public function user_two_factor_options( $user ) {
if ( ! isset( $user->ID ) ) {
Expand Down Expand Up @@ -161,6 +171,8 @@ public function user_two_factor_options( $user ) {
* @param integer $user_id The user ID whose options are being updated.
*
* @return void
*
* @codeCoverageIgnore
*/
public function user_two_factor_options_update( $user_id ) {
$notices = array();
Expand Down Expand Up @@ -255,6 +267,8 @@ public function is_valid_key( $key ) {
* @param integer $user_id User ID.
*
* @return void
*
* @codeCoverageIgnore
*/
public function admin_notices( $user_id ) {
$notices = get_user_meta( $user_id, self::NOTICES_META_KEY, true );
Expand Down Expand Up @@ -286,6 +300,8 @@ public function admin_notices( $user_id ) {
* @param WP_User $user WP_User object of the logged-in user.
*
* @return bool Whether the user gave a valid code
*
* @codeCoverageIgnore
*/
public function validate_authentication( $user ) {
if ( ! empty( $_REQUEST['authcode'] ) ) {
Expand Down Expand Up @@ -421,6 +437,8 @@ public static function calc_totp( $key, $step_count = false, $digits = self::DEF
* @param string $title The title to display in the Authentication app.
*
* @return string A URL to use as an img src to display the QR code
*
* @codeCoverageIgnore
*/
public static function get_google_qr_code( $name, $key, $title = null ) {
// Encode to support spaces, question marks and other characters.
Expand Down Expand Up @@ -450,6 +468,8 @@ public function is_available_for_user( $user ) {
* Prints the form that prompts the user to authenticate.
*
* @param WP_User $user WP_User object of the logged-in user.
*
* @codeCoverageIgnore
*/
public function authentication_page( $user ) {
require_once ABSPATH . '/wp-admin/includes/template.php';
Expand Down

0 comments on commit c6a6c41

Please sign in to comment.