Skip to content

Commit

Permalink
fixup: Fix files_external tests
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux committed Nov 5, 2024
1 parent 25d13a4 commit 9ca9c89
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 19 deletions.
3 changes: 2 additions & 1 deletion apps/files_external/lib/Lib/Auth/PublicKey/RSA.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public function createKey($keyLength): RSACrypt\PrivateKey {
$keyLength = 1024;
}

$secret = $this->config->getSystemValue('secret', '');
return $rsa->createKey($keyLength)
->withPassword($this->config->getSystemValue('secret', ''));
->withPassword($secret);
}
}
48 changes: 32 additions & 16 deletions apps/files_external/tests/Controller/AjaxControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,27 @@
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);
Expand All @@ -53,12 +52,29 @@ protected function setUp(): void {
}

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(
Expand Down
2 changes: 1 addition & 1 deletion lib/private/IntegrityCheck/Checker.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public function writeAppSignature($path,
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;
Expand Down
10 changes: 9 additions & 1 deletion tests/lib/IntegrityCheck/CheckerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ public function testWriteAppSignature(): void {
"signature": "Y5yvXvcGHVPuRRatKVDUONWq1FpLXugZd6Km\/+aEHsQj7coVl9FeMj9OsWamBf7yRIw3dtNLguTLlAA9QAv\/b0uHN3JnbNZN+dwFOve4NMtqXfSDlWftqKN00VS+RJXpG1S2IIx9Poyp2NoghL\/5AuTv4GHiNb7zU\/DT\/kt71pUGPgPR6IIFaE+zHOD96vjYkrH+GfWZzKR0FCdLib9yyNvk+EGrcjKM6qjs2GKfS\/XFjj\/\/neDnh\/0kcPuKE3ZbofnI4TIDTv0CGqvOp7PtqVNc3Vy\/UKa7uF1PT0MAUKMww6Ei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TAcRK0zECDEaX3npS8xWzrB\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')
Expand All @@ -145,7 +153,7 @@ public function testWriteAppSignature(): void {

$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);
Expand Down

0 comments on commit 9ca9c89

Please sign in to comment.