From ff2804804f220e05383707287848339b22da1326 Mon Sep 17 00:00:00 2001 From: Max Semenik Date: Wed, 17 Oct 2018 19:19:41 -0700 Subject: [PATCH] Hard deprecate functionality replaced with random_bytes() Deprecated in 1.32, no callers. Change-Id: Id2d59c303fd60fab2b323af6cab137fdf74b5377 --- includes/MediaWikiServices.php | 1 + includes/libs/CryptRand.php | 6 ++++++ includes/utils/MWCryptRand.php | 3 +++ tests/phpunit/includes/MediaWikiServicesTest.php | 8 +++++++- 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/includes/MediaWikiServices.php b/includes/MediaWikiServices.php index 0acd55a822..f3ca7d469e 100644 --- a/includes/MediaWikiServices.php +++ b/includes/MediaWikiServices.php @@ -518,6 +518,7 @@ class MediaWikiServices extends ServiceContainer { * @return CryptRand */ public function getCryptRand() { + wfDeprecated( __METHOD__, '1.32' ); return $this->getService( 'CryptRand' ); } diff --git a/includes/libs/CryptRand.php b/includes/libs/CryptRand.php index a1bbd099c4..da0cae250d 100644 --- a/includes/libs/CryptRand.php +++ b/includes/libs/CryptRand.php @@ -46,6 +46,7 @@ class CryptRand { * @return string */ protected function initialRandomState() { + wfDeprecated( __METHOD__, '1.32' ); return ''; } @@ -59,6 +60,7 @@ class CryptRand { * @author Tim Starling */ protected function driftHash( $data ) { + wfDeprecated( __METHOD__, '1.32' ); return ''; } @@ -70,6 +72,7 @@ class CryptRand { * @return string A new weak random state */ protected function randomState() { + wfDeprecated( __METHOD__, '1.32' ); return ''; } @@ -83,6 +86,7 @@ class CryptRand { * @return bool Always true */ public function wasStrong() { + wfDeprecated( __METHOD__, '1.32' ); return true; } @@ -96,6 +100,7 @@ class CryptRand { * @return string Raw binary random data */ public function generate( $bytes ) { + wfDeprecated( __METHOD__, '1.32' ); $bytes = floor( $bytes ); return random_bytes( $bytes ); } @@ -108,6 +113,7 @@ class CryptRand { * @return string Hexadecimal random data */ public function generateHex( $chars ) { + wfDeprecated( __METHOD__, '1.32' ); return MWCryptRand::generateHex( $chars ); } } diff --git a/includes/utils/MWCryptRand.php b/includes/utils/MWCryptRand.php index 0fc45f7e11..ec8bf5cf21 100644 --- a/includes/utils/MWCryptRand.php +++ b/includes/utils/MWCryptRand.php @@ -32,6 +32,7 @@ class MWCryptRand { * @return CryptRand */ protected static function singleton() { + wfDeprecated( __METHOD__, '1.32' ); return MediaWikiServices::getInstance()->getCryptRand(); } @@ -45,6 +46,7 @@ class MWCryptRand { * @return bool Always true */ public static function wasStrong() { + wfDeprecated( __METHOD__, '1.32' ); return true; } @@ -58,6 +60,7 @@ class MWCryptRand { * @return string Raw binary random data */ public static function generate( $bytes ) { + wfDeprecated( __METHOD__, '1.32' ); return random_bytes( floor( $bytes ) ); } diff --git a/tests/phpunit/includes/MediaWikiServicesTest.php b/tests/phpunit/includes/MediaWikiServicesTest.php index c838fc3165..ab9a47210e 100644 --- a/tests/phpunit/includes/MediaWikiServicesTest.php +++ b/tests/phpunit/includes/MediaWikiServicesTest.php @@ -11,6 +11,7 @@ use MediaWiki\Services\ServiceDisabledException; * @group MediaWiki */ class MediaWikiServicesTest extends MediaWikiTestCase { + private $deprecatedServices = [ 'CryptRand' ]; /** * @return Config @@ -276,6 +277,7 @@ class MediaWikiServicesTest extends MediaWikiTestCase { $getterCases[$name] = [ 'get' . $service, $class, + in_array( $service, $this->deprecatedServices ) ]; } @@ -285,7 +287,11 @@ class MediaWikiServicesTest extends MediaWikiTestCase { /** * @dataProvider provideGetters */ - public function testGetters( $getter, $type ) { + public function testGetters( $getter, $type, $isDeprecated = false ) { + if ( $isDeprecated ) { + $this->hideDeprecated( MediaWikiServices::class . "::$getter" ); + } + // Test against the default instance, since the dummy will not know the default services. $services = MediaWikiServices::getInstance(); $service = $services->$getter(); -- 2.20.1