Skip to content

Commit

Permalink
Tests: Only validate that it's encrypted if the encryption methods ar…
Browse files Browse the repository at this point in the history
…e available.
  • Loading branch information
dd32 committed Apr 13, 2023
1 parent 852d818 commit 3d89b20
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions tests/test-wporg-two-factor.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,14 @@ public function test_set_primary_provider_for_user() {
$enabled = Two_Factor_Core::enable_provider_for_user( self::$regular_user->ID, 'Two_Factor_Totp' );
$this->assertTrue( $enabled );

// Validate that the TOTP key was stored in an encrypted form.
$totp_key = $totp_provider->get_user_totp_key( self::$regular_user->ID );
$totp_user_meta = get_user_meta( self::$regular_user->ID, $totp_provider::SECRET_META_KEY, true );
$this->assertNotSame( $totp_key, $totp_user_meta );
// Validate that the TOTP key was stored in an encrypted form, if encryption methods are available.
// Pending https://github.com/WordPress/wporg-mu-plugins/pull/390 merge.
if ( function_exists( 'wporg_is_encrypted' ) ) {
$totp_key = $totp_provider->get_user_totp_key( self::$regular_user->ID );
$totp_user_meta = get_user_meta( self::$regular_user->ID, $totp_provider::SECRET_META_KEY, true );
$this->assertNotSame( $totp_key, $totp_user_meta );
$this->assertTrue( wporg_is_encrypted( $totp_user_meta ) );
}

// Validate that TOTP is now the primary provider.
$provider = Two_Factor_Core::get_primary_provider_for_user( self::$regular_user->ID );
Expand Down

0 comments on commit 3d89b20

Please sign in to comment.