forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Security: Enhance the
wp_hash()
function to support custom hashing …
…algorithms. The default algorithm remains as md5, but this change allows any algorithm that's supported by `hash_hmac()` to be used instead. Props pushpenderindia, ayeshrajans, debarghyabanerjee, johnbillion Fixes #62005 git-svn-id: https://develop.svn.wordpress.org/trunk@59578 602fd350-edb4-49c9-b593-d223f7449a82
- Loading branch information
1 parent
d6aa043
commit 3a07176
Showing
3 changed files
with
63 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
/** | ||
* Tests for the behavior of `wp_hash()` | ||
* | ||
* @group functions | ||
* | ||
* @covers ::wp_hash | ||
*/ | ||
class Tests_Functions_wpHash extends WP_UnitTestCase { | ||
|
||
/** | ||
* @dataProvider data_wp_hash_uses_specified_algorithm | ||
* | ||
* @ticket 62005 | ||
*/ | ||
public function test_wp_hash_uses_specified_algorithm( string $algo, int $expected_length ) { | ||
$hash = wp_hash( 'data', 'auth', $algo ); | ||
|
||
$this->assertSame( $expected_length, strlen( $hash ) ); | ||
} | ||
|
||
public function data_wp_hash_uses_specified_algorithm() { | ||
return array( | ||
array( 'md5', 32 ), | ||
array( 'sha1', 40 ), | ||
array( 'sha256', 64 ), | ||
); | ||
} | ||
|
||
/** | ||
* @ticket 62005 | ||
*/ | ||
public function test_wp_hash_throws_exception_on_invalid_algorithm() { | ||
$this->expectException( 'InvalidArgumentException' ); | ||
|
||
wp_hash( 'data', 'auth', 'invalid' ); | ||
} | ||
} |
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