aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFerdinand Thiessen <opensource@fthiessen.de>2024-11-05 17:40:29 +0100
committerFerdinand Thiessen <opensource@fthiessen.de>2024-11-05 19:01:26 +0100
commit9ca9c899b70a66994a395bb3928f928d3cefeb3c (patch)
treeff7bb6adb91337cd604682e6387191a30b3db7f8
parent25d13a4afe9c5902f289b9f27ae18440f9f4088a (diff)
downloadnextcloud-server-fix/deps/php-seclin.tar.gz
nextcloud-server-fix/deps/php-seclin.zip
fixup: Fix files_external testsfix/deps/php-seclin
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
-rw-r--r--apps/files_external/lib/Lib/Auth/PublicKey/RSA.php3
-rw-r--r--apps/files_external/tests/Controller/AjaxControllerTest.php48
-rw-r--r--lib/private/IntegrityCheck/Checker.php2
-rw-r--r--tests/lib/IntegrityCheck/CheckerTest.php10
4 files changed, 44 insertions, 19 deletions
diff --git a/apps/files_external/lib/Lib/Auth/PublicKey/RSA.php b/apps/files_external/lib/Lib/Auth/PublicKey/RSA.php
index 7a0e724652e..3b88fa91375 100644
--- a/apps/files_external/lib/Lib/Auth/PublicKey/RSA.php
+++ b/apps/files_external/lib/Lib/Auth/PublicKey/RSA.php
@@ -66,7 +66,8 @@ class RSA extends AuthMechanism {
$keyLength = 1024;
}
+ $secret = $this->config->getSystemValue('secret', '');
return $rsa->createKey($keyLength)
- ->withPassword($this->config->getSystemValue('secret', ''));
+ ->withPassword($secret);
}
}
diff --git a/apps/files_external/tests/Controller/AjaxControllerTest.php b/apps/files_external/tests/Controller/AjaxControllerTest.php
index dc9661732cc..9755cdda19e 100644
--- a/apps/files_external/tests/Controller/AjaxControllerTest.php
+++ b/apps/files_external/tests/Controller/AjaxControllerTest.php
@@ -13,28 +13,27 @@ use OCP\IGroupManager;
use OCP\IRequest;
use OCP\IUser;
use OCP\IUserSession;
+use phpseclib3\Crypt\RSA as CryptRSA;
+use phpseclib3\Crypt\RSA\PrivateKey;
+use phpseclib3\Crypt\RSA\PublicKey;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class AjaxControllerTest extends TestCase {
- /** @var IRequest */
- private $request;
- /** @var RSA */
- private $rsa;
- /** @var GlobalAuth */
- private $globalAuth;
- /** @var IUserSession */
- private $userSession;
- /** @var IGroupManager */
- private $groupManager;
- /** @var AjaxController */
- private $ajaxController;
+ private IRequest&MockObject $request;
+ private RSA&MockObject $rsa;
+ private GlobalAuth&MockObject $globalAuth;
+ private IUserSession&MockObject $userSession;
+ private IGroupManager&MockObject $groupManager;
+
+ private AjaxController $ajaxController;
protected function setUp(): void {
$this->request = $this->createMock(IRequest::class);
- $this->rsa = $this->getMockBuilder('\\OCA\\Files_External\\Lib\\Auth\\PublicKey\\RSA')
+ $this->rsa = $this->getMockBuilder(RSA::class)
->disableOriginalConstructor()
->getMock();
- $this->globalAuth = $this->getMockBuilder('\\OCA\\Files_External\\Lib\\Auth\\Password\GlobalAuth')
+ $this->globalAuth = $this->getMockBuilder(GlobalAuth::class)
->disableOriginalConstructor()
->getMock();
$this->userSession = $this->createMock(IUserSession::class);
@@ -53,12 +52,29 @@ class AjaxControllerTest extends TestCase {
}
public function testGetSshKeys(): void {
+ $keyImpl = $this->createMock(CryptRSA::class);
+ $keyImpl->expects(self::once())
+ ->method('toString')
+ ->with('OpenSSH')
+ ->willReturn('MyPublicKey');
+
+ $publicKey = $this->createMock(PublicKey::class);
+ $publicKey->expects(self::once())
+ ->method('getPublicKey')
+ ->willReturn($keyImpl);
+
+ $privateKey = $this->createMock(PrivateKey::class);
+ $privateKey->expects(self::once())
+ ->method('toString')
+ ->with('PKCS1')
+ ->willReturn('MyPrivatekey');
+
$this->rsa
->expects($this->once())
->method('createKey')
->willReturn([
- 'privatekey' => 'MyPrivateKey',
- 'publickey' => 'MyPublicKey',
+ 'privatekey' => $privateKey,
+ 'publickey' => $publicKey,
]);
$expected = new JSONResponse(
diff --git a/lib/private/IntegrityCheck/Checker.php b/lib/private/IntegrityCheck/Checker.php
index 9d9e5c4467d..c8ef7a40bc2 100644
--- a/lib/private/IntegrityCheck/Checker.php
+++ b/lib/private/IntegrityCheck/Checker.php
@@ -213,7 +213,7 @@ class Checker {
json_encode($signature, JSON_PRETTY_PRINT)
);
} catch (\Exception $e) {
- if (!$this->fileAccessHelper->is_writable($appInfoDir)) {
+ if ($this->fileAccessHelper->is_writable($appInfoDir) === false) {
throw new \Exception($appInfoDir . ' is not writable');
}
throw $e;
diff --git a/tests/lib/IntegrityCheck/CheckerTest.php b/tests/lib/IntegrityCheck/CheckerTest.php
index c87ff68d303..cc8f2980d97 100644
--- a/tests/lib/IntegrityCheck/CheckerTest.php
+++ b/tests/lib/IntegrityCheck/CheckerTest.php
@@ -131,6 +131,14 @@ class CheckerTest extends TestCase {
"certificate": "-----BEGIN CERTIFICATE-----\r\nMIIEwTCCAqmgAwIBAgIUWv0iujufs5lUr0svCf\/qTQvoyKAwDQYJKoZIhvcNAQEF\r\nBQAwIzEhMB8GA1UECgwYb3duQ2xvdWQgQ29kZSBTaWduaW5nIENBMB4XDTE1MTEw\r\nMzIyNDk1M1oXDTE2MTEwMzIyNDk1M1owEjEQMA4GA1UEAwwHU29tZUFwcDCCAiIw\r\nDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK8q0x62agGSRBqeWsaeEwFfepMk\r\nF8cAobMMi50qHCv9IrOn\/ZH9l52xBrbIkErVmRjmly0d4JhD8Ymhidsh9ONKYl\/j\r\n+ishsZDM8eNNdp3Ew+fEYVvY1W7mR1qU24NWj0bzVsClI7hvPVIuw7AjfBDq1C5+\r\nA+ZSLSXYvOK2cEWjdxQfuNZwEZSjmA63DUllBIrm35IaTvfuyhU6BW9yHZxmb8+M\r\nw0xDv30D5UkE\/2N7Pa\/HQJLxCR+3zKibRK3nUyRDLSXxMkU9PnFNaPNX59VPgyj4\r\nGB1CFSToldJVPF4pzh7p36uGXZVxs8m3LFD4Ol8mhi7jkxDZjqFN46gzR0r23Py6\r\ndol9vf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wuzr7DumiAULexnP\/Y7xwxLv7\r\n4B+pXTAcRK0zECDEaX3npS8xWzrB\r\n-----END CERTIFICATE-----"
}';
$this->fileAccessHelper
+ ->expects(self::any())
+ ->method('is_writable')
+ ->with(
+ $this->equalTo(\OC::$SERVERROOT . '/tests/data/integritycheck/app//appinfo'),
+ )
+ ->willReturn(true);
+
+ $this->fileAccessHelper
->expects($this->once())
->method('file_put_contents')
->with(
@@ -145,7 +153,7 @@ class CheckerTest extends TestCase {
$keyBundle = file_get_contents(__DIR__ . '/../../data/integritycheck/SomeApp.crt');
$rsaPrivateKey = file_get_contents(__DIR__ . '/../../data/integritycheck/SomeApp.key');
- $rsa = RSA::loadPrivateKey($rsaPrivateKey);
+ $rsa = RSA::load($rsaPrivateKey);
$x509 = new X509();
$x509->loadX509($keyBundle);
$this->checker->writeAppSignature(\OC::$SERVERROOT . '/tests/data/integritycheck/app/', $x509, $rsa);