diff --git a/composer.json b/composer.json
index 706ee3f0e4..12df630ccf 100644
--- a/composer.json
+++ b/composer.json
@@ -157,6 +157,7 @@
},
"scripts": {
"test": "phpunit",
+ "test:unit": "phpunit -c tests/phpunit.xml --testsuite unit",
"phpstan": "phpstan analyze --memory-limit 1024M --configuration .phpstan.neon",
"lint": "find . -name \\*.php -not -path './vendor/*' -not -path './view/asset/*' -print0 | xargs -0 -n1 php -l",
"docker:translate": "docker run --rm -v $PWD:/data -w /data friendicaci/transifex bin/run_xgettext.sh",
diff --git a/src/Util/Crypto.php b/src/Util/Crypto.php
index ba3c46bbc3..8113697639 100644
--- a/src/Util/Crypto.php
+++ b/src/Util/Crypto.php
@@ -306,13 +306,6 @@ class Crypto
*/
public static function randomDigits($digits)
{
- $rn = '';
-
- // generating cryptographically secure pseudo-random integers
- for ($i = 0; $i < $digits; $i++) {
- $rn .= random_int(0, 9);
- }
-
- return (int) $rn;
+ return random_int(0, 10 ** $digits - 1);
}
}
diff --git a/tests/Unit/Util/CryptoTest.php b/tests/Unit/Util/CryptoTest.php
new file mode 100644
index 0000000000..1e728746f2
--- /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/phpunit.xml b/tests/phpunit.xml
index 6f16c7a73e..0e323813f8 100644
--- a/tests/phpunit.xml
+++ b/tests/phpunit.xml
@@ -7,10 +7,16 @@
timeoutForMediumTests="900"
timeoutForLargeTests="900"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
-
- functional/
- src/
-
+
+
+ functional/
+ src/
+ Unit/
+
+
+ Unit/
+
+
diff --git a/tests/src/Util/CryptoTest.php b/tests/src/Util/CryptoTest.php
deleted file mode 100644
index 544561bc3b..0000000000
--- a/tests/src/Util/CryptoTest.php
+++ /dev/null
@@ -1,65 +0,0 @@
-getFunctionMock('Friendica\Util', 'random_int');
- $random_int->expects($this->any())->willReturnCallback(function($min, $max) {
- return 1;
- });
-
- self::assertSame(1, Crypto::randomDigits(1));
- self::assertSame(11111111, 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'),
- ],
- ];
- }
-}