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 c66f090
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 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

0 comments on commit c66f090

Please sign in to comment.