X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=tests%2Fsrc%2FUtil%2FCryptoTest.php;h=82afc24832264f94a1f4c8e13cf3600749efc9a2;hb=360614d2cf3aceeb763ef1281ad5236878f5d735;hp=9f232210c9561fc259f49dc6b70fc4351c1cc329;hpb=8293d5ed0af78ae6cc5629bb1f982a7b29794d32;p=friendica.git diff --git a/tests/src/Util/CryptoTest.php b/tests/src/Util/CryptoTest.php index 9f232210c9..82afc24832 100644 --- a/tests/src/Util/CryptoTest.php +++ b/tests/src/Util/CryptoTest.php @@ -1,6 +1,6 @@ assertEquals($min, $mMin); - $this->assertEquals($max, $mMax); + $phpMock['random_int'] = function ($mMin, $mMax) use ($min, $max) { + self::assertEquals($min, $mMin); + self::assertEquals($max, $mMax); return 1; }; } public function testRandomDigitsRandomInt() { - $this->assertRandomInt(0, 9); + self::assertRandomInt(0, 9); $test = Crypto::randomDigits(1); - $this->assertEquals(1, strlen($test)); - $this->assertEquals(1, $test); + self::assertEquals(1, strlen($test)); + self::assertEquals(1, $test); $test = Crypto::randomDigits(8); - $this->assertEquals(8, strlen($test)); - $this->assertEquals(11111111, $test); + self::assertEquals(8, strlen($test)); + self::assertEquals(11111111, $test); + } + + public function dataRsa(): array + { + return [ + 'diaspora' => [ + 'key' => file_get_contents(__DIR__ . '/../../datasets/crypto/rsa/diaspora-public-rsa-base64'), + 'expected' => file_get_contents(__DIR__ . '/../../datasets/crypto/rsa/diaspora-public-pem'), + ], + ]; + } + + /** + * @dataProvider dataRsa + */ + public function testPubRsaToMe(string $key, string $expected) + { + self::assertEquals($expected, Crypto::rsaToPem(base64_decode($key))); + } + + + public function dataPEM() + { + return [ + 'diaspora' => [ + 'key' => file_get_contents(__DIR__ . '/../../datasets/crypto/rsa/diaspora-public-pem'), + ], + ]; } } @@ -62,7 +103,6 @@ function random_int($min, $max) { global $phpMock; if (isset($phpMock['random_int'])) { - $result = call_user_func_array($phpMock['random_int'], func_get_args()); - return $result; + return call_user_func_array($phpMock['random_int'], func_get_args()); } }