diff --git a/tests/Unit/Util/CryptoTest.php b/tests/Unit/Util/CryptoTest.php new file mode 100644 index 0000000000..7f6f0fb656 --- /dev/null +++ b/tests/Unit/Util/CryptoTest.php @@ -0,0 +1,45 @@ +getFunctionMock('Friendica\Util', 'random_int'); + $random_int->expects($this->any())->willReturnCallback(function($min, $max) { + return 12345678; + }); + + self::assertSame(12345678, Crypto::randomDigits(8)); + } + + public function testDiasporaPubRsaToMe() + { + $key = 'LS0tLS1CRUdJTiBSU0EgUFVCTElDIEtFWS0tLS0tDQpNSUdKQW9HQkFORjVLTmJzN2k3aTByNVFZckNpRExEZ09pU1BWbmgvdlFnMXpnSk9VZVRheWVETk5yZTR6T1RVDQpSVDcyZGlLQ294OGpYOE5paElJTFJtcUtTOWxVYVNzd21QcVNFenVpdE5xeEhnQy8xS2ZuaXM1Qm96NnRwUUxjDQpsZDMwQjJSMWZIVWdFTHZWd0JkV29pRDhSRUt1dFNuRVBGd1RwVmV6aVlWYWtNY25pclRWQWdNQkFBRT0NCi0tLS0tRU5EIFJTQSBQVUJMSUMgS0VZLS0tLS0'; + + // TODO PHPUnit 10: Replace with assertStringEqualsStringIgnoringLineEndings() + self::assertSame( + str_replace("\n", "\r\n", <<< TXT + -----BEGIN PUBLIC KEY----- + MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDReSjW7O4u4tK+UGKwogyw4Dok + j1Z4f70INc4CTlHk2sngzTa3uMzk1EU+9nYigqMfI1/DYoSCC0ZqikvZVGkrMJj6 + khM7orTasR4Av9Sn54rOQaM+raUC3JXd9AdkdXx1IBC71cAXVqIg/ERCrrUpxDxc + E6VXs4mFWpDHJ4q01QIDAQAB + -----END PUBLIC KEY----- + TXT), + Crypto::rsaToPem(base64_decode($key)) + ); + } +} diff --git a/tests/datasets/crypto/rsa/diaspora-public-pem b/tests/datasets/crypto/rsa/diaspora-public-pem deleted file mode 100644 index 09dd1640d3..0000000000 --- a/tests/datasets/crypto/rsa/diaspora-public-pem +++ /dev/null @@ -1,6 +0,0 @@ ------BEGIN PUBLIC KEY----- -MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDReSjW7O4u4tK+UGKwogyw4Dok -j1Z4f70INc4CTlHk2sngzTa3uMzk1EU+9nYigqMfI1/DYoSCC0ZqikvZVGkrMJj6 -khM7orTasR4Av9Sn54rOQaM+raUC3JXd9AdkdXx1IBC71cAXVqIg/ERCrrUpxDxc -E6VXs4mFWpDHJ4q01QIDAQAB ------END PUBLIC KEY----- \ No newline at end of file diff --git a/tests/datasets/crypto/rsa/diaspora-public-rsa-base64 b/tests/datasets/crypto/rsa/diaspora-public-rsa-base64 deleted file mode 100644 index ba835a4711..0000000000 --- a/tests/datasets/crypto/rsa/diaspora-public-rsa-base64 +++ /dev/null @@ -1 +0,0 @@ -LS0tLS1CRUdJTiBSU0EgUFVCTElDIEtFWS0tLS0tDQpNSUdKQW9HQkFORjVLTmJzN2k3aTByNVFZckNpRExEZ09pU1BWbmgvdlFnMXpnSk9VZVRheWVETk5yZTR6T1RVDQpSVDcyZGlLQ294OGpYOE5paElJTFJtcUtTOWxVYVNzd21QcVNFenVpdE5xeEhnQy8xS2ZuaXM1Qm96NnRwUUxjDQpsZDMwQjJSMWZIVWdFTHZWd0JkV29pRDhSRUt1dFNuRVBGd1RwVmV6aVlWYWtNY25pclRWQWdNQkFBRT0NCi0tLS0tRU5EIFJTQSBQVUJMSUMgS0VZLS0tLS0 \ No newline at end of file diff --git a/tests/src/Util/CryptoTest.php b/tests/src/Util/CryptoTest.php deleted file mode 100644 index dae87865b9..0000000000 --- a/tests/src/Util/CryptoTest.php +++ /dev/null @@ -1,64 +0,0 @@ -getFunctionMock('Friendica\Util', 'random_int'); - $random_int->expects($this->any())->willReturnCallback(function($min, $max) { - return 12345678; - }); - - self::assertSame(12345678, Crypto::randomDigits(8)); - } - - 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::assertSame($expected, Crypto::rsaToPem(base64_decode($key))); - } - - - public function dataPEM() - { - return [ - 'diaspora' => [ - 'key' => file_get_contents(__DIR__ . '/../../datasets/crypto/rsa/diaspora-public-pem'), - ], - ]; - } -}