-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] Add dedicated TOTP encryption salt
- Loading branch information
Showing
6 changed files
with
320 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* remove this if don't end up adding the warning */ | ||
|
||
.two-factor-methods-table .notice { | ||
//width: auto; | ||
/*max-width: 100%;*/ | ||
/* overflow-x: scroll;*/ | ||
/*width: clamp( 300px, 60%, 400px ); | ||
max-width: clamp( 300px, 60%, 400px );*/ | ||
overflow: hidden; | ||
} | ||
|
||
.two-factor-methods-table .notice pre { | ||
/*width: 100%; | ||
max-width: 100%; | ||
overflow-x: scroll;*/ | ||
|
||
background-color: #d7d7d7; | ||
overflow: hidden; | ||
} | ||
|
||
.two-factor-methods-table .notice pre code { | ||
/* todo get this to not overflow page */ | ||
|
||
/*display: block;*/ | ||
padding: 10px; | ||
overflow: scroll; | ||
/* | ||
width: clamp( 300px, 60%, 400px ); | ||
max-width: 400px;*/ | ||
|
||
background-color: transparent; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
/** | ||
* Test Two Factor Provider. | ||
* | ||
* @package Two_Factor | ||
*/ | ||
|
||
/** | ||
* Class Tests_Two_Factor_Provider | ||
* | ||
* @package Two_Factor | ||
* @group providers | ||
*/ | ||
class Tests_Two_Factor_Provider extends WP_UnitTestCase { | ||
private static $config_path; | ||
private static $original_config; | ||
//private static $original_config_permissions; | ||
|
||
/** | ||
* Setup shared fixtures before any tests run. | ||
* | ||
* @param WP_UnitTest_Factory $factory | ||
*/ | ||
public static function wpSetUpBeforeClass( $factory ) { | ||
//ini_set( 'realpath_cache_size', 0 ); didn't help | ||
|
||
self::$config_path = Two_Factor_Provider::get_config_path(); | ||
self::$original_config = file_get_contents( self::$config_path ); | ||
//self::$original_config_permissions = substr( sprintf( '%o', fileperms( self::$config_path ) ), -4 ); | ||
|
||
if ( empty( self::$original_config ) ) { | ||
self::fail( 'Config file is empty.' ); | ||
} | ||
} | ||
|
||
/** | ||
* Restore global state between tests. | ||
*/ | ||
public function tear_down() { | ||
//chmod( self::$config_path, octdec( self::$original_config_permissions ) ); | ||
//clearstatcache here too, same as whatever below | ||
|
||
$restored = file_put_contents( self::$config_path, self::$original_config ); | ||
|
||
if ( false === $restored ) { | ||
self::fail( 'Failed to restore original config.' ); | ||
} | ||
|
||
parent::tear_down(); | ||
} | ||
|
||
/** | ||
* Test that new constants can be created. | ||
* | ||
* @covers Two_Factor_Provider::maybe_create_config_salt() | ||
*/ | ||
public function test_create_new_constant() { | ||
$constant_name = 'FOO_NEW'; | ||
|
||
// It doesn't exist yet | ||
$this->assertFalse( defined( $constant_name ) ); | ||
$this->assertFalse( stripos( self::$original_config, $constant_name ) ); | ||
|
||
$result = Two_Factor_Provider::maybe_create_config_salt( $constant_name ); | ||
$new_config = file_get_contents( self::$config_path ); | ||
|
||
// It does exist now | ||
$this->assertTrue( $result ); | ||
$this->assertTrue( defined( $constant_name ) ); | ||
$this->assertTrue( 64 === strlen( constant( $constant_name ) ) ); | ||
$this->assertNotEmpty( $new_config ); | ||
$this->assertGreaterThan( 0, stripos( $new_config, $constant_name ) ); | ||
} | ||
|
||
/** | ||
* Test that existing constants aren't redefined. | ||
* | ||
* @covers Two_Factor_Provider::maybe_create_config_salt() | ||
*/ | ||
public function test_create_existing_constant() { | ||
$this->assertTrue( defined( 'DB_NAME' ) ); | ||
$result = Two_Factor_Provider::maybe_create_config_salt( 'DB_NAME' ); | ||
$this->assertTrue( $result ); | ||
$this->assertSame( self::$original_config, file_get_contents( self::$config_path ) ); | ||
} | ||
|
||
/** | ||
* Test that unwritable files return false | ||
* | ||
* @covers Two_Factor_Provider::maybe_create_config_salt() | ||
*/ | ||
//public function test_unwritable_config() { | ||
// // todo ugh don't waste more time on this, just test it manually once to make sure works and can leave this test out | ||
// | ||
// chmod( self::$config_path, 0444 ); | ||
// clearstatcache( true, self::$config_path ); // doesn't work, neither does any other variation of params | ||
// $this->assertFalse( is_writable( self::$config_path ) ); | ||
// // todo ^ says can write even though perms are 444 | ||
// | ||
// $this->assertFalse( defined( 'FOO_UNWRITABLE' ) ); | ||
// $result = Two_Factor_Provider::maybe_create_config_salt( 'FOO_UNWRITABLE' ); | ||
// $this->assertFalse( $result ); | ||
//} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,20 @@ | |
|
||
$table_prefix = getenv( 'WORDPRESS_TABLE_PREFIX' ) ?: 'wpphpunittests_'; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited | ||
|
||
|
||
/* | ||
* Warning: Changing this value will break decryption for existing users, and prevent | ||
* them from logging in with this factor. If you change this you must create a constant | ||
* to facilitate migration: | ||
* | ||
* define( 'TWO_FACTOR_TOTP_ENCRYPTION_SALT_MIGRATE', 'place the old value here' ); | ||
* | ||
* See {@TODO support article URL} for more information. | ||
*/ | ||
define( 'TWO_FACTOR_TOTP_ENCRYPTION_SALT', '4N:v{FDL,s?:UM[[1>?.:Dq?=Iwh5%z]!f,2-6rDyv0/-za<03;q`J-YV:QOu;&3' ); | ||
define( 'SECURE_AUTH_SALT', '389lrsuytneiarsm39p80talurynetim32ta790stjuynareitm3298pluynatri' ); | ||
|
||
|
||
define( 'WP_TESTS_DOMAIN', 'example.org' ); | ||
define( 'WP_TESTS_EMAIL', '[email protected]' ); | ||
define( 'WP_TESTS_TITLE', 'Test Blog' ); | ||
|