Skip to content

Commit c66f090

Browse files
committed
fixup: Fix files_external tests
Signed-off-by: Ferdinand Thiessen <[email protected]>
1 parent 25d13a4 commit c66f090

File tree

2 files changed

+34
-17
lines changed

2 files changed

+34
-17
lines changed

apps/files_external/lib/Lib/Auth/PublicKey/RSA.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ public function createKey($keyLength): RSACrypt\PrivateKey {
6666
$keyLength = 1024;
6767
}
6868

69+
$secret = $this->config->getSystemValue('secret', '');
6970
return $rsa->createKey($keyLength)
70-
->withPassword($this->config->getSystemValue('secret', ''));
71+
->withPassword($secret);
7172
}
7273
}

apps/files_external/tests/Controller/AjaxControllerTest.php

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,27 @@
1313
use OCP\IRequest;
1414
use OCP\IUser;
1515
use OCP\IUserSession;
16+
use phpseclib3\Crypt\RSA as CryptRSA;
17+
use phpseclib3\Crypt\RSA\PrivateKey;
18+
use phpseclib3\Crypt\RSA\PublicKey;
19+
use PHPUnit\Framework\MockObject\MockObject;
1620
use Test\TestCase;
1721

1822
class AjaxControllerTest extends TestCase {
19-
/** @var IRequest */
20-
private $request;
21-
/** @var RSA */
22-
private $rsa;
23-
/** @var GlobalAuth */
24-
private $globalAuth;
25-
/** @var IUserSession */
26-
private $userSession;
27-
/** @var IGroupManager */
28-
private $groupManager;
29-
/** @var AjaxController */
30-
private $ajaxController;
23+
private IRequest&MockObject $request;
24+
private RSA&MockObject $rsa;
25+
private GlobalAuth&MockObject $globalAuth;
26+
private IUserSession&MockObject $userSession;
27+
private IGroupManager&MockObject $groupManager;
28+
29+
private AjaxController $ajaxController;
3130

3231
protected function setUp(): void {
3332
$this->request = $this->createMock(IRequest::class);
34-
$this->rsa = $this->getMockBuilder('\\OCA\\Files_External\\Lib\\Auth\\PublicKey\\RSA')
33+
$this->rsa = $this->getMockBuilder(RSA::class)
3534
->disableOriginalConstructor()
3635
->getMock();
37-
$this->globalAuth = $this->getMockBuilder('\\OCA\\Files_External\\Lib\\Auth\\Password\GlobalAuth')
36+
$this->globalAuth = $this->getMockBuilder(GlobalAuth::class)
3837
->disableOriginalConstructor()
3938
->getMock();
4039
$this->userSession = $this->createMock(IUserSession::class);
@@ -53,12 +52,29 @@ protected function setUp(): void {
5352
}
5453

5554
public function testGetSshKeys(): void {
55+
$keyImpl = $this->createMock(CryptRSA::class);
56+
$keyImpl->expects(self::once())
57+
->method('toString')
58+
->with('OpenSSH')
59+
->willReturn('MyPublicKey');
60+
61+
$publicKey = $this->createMock(PublicKey::class);
62+
$publicKey->expects(self::once())
63+
->method('getPublicKey')
64+
->willReturn($keyImpl);
65+
66+
$privateKey = $this->createMock(PrivateKey::class);
67+
$privateKey->expects(self::once())
68+
->method('toString')
69+
->with('PKCS1')
70+
->willReturn('MyPrivatekey');
71+
5672
$this->rsa
5773
->expects($this->once())
5874
->method('createKey')
5975
->willReturn([
60-
'privatekey' => 'MyPrivateKey',
61-
'publickey' => 'MyPublicKey',
76+
'privatekey' => $privateKey,
77+
'publickey' => $publicKey,
6278
]);
6379

6480
$expected = new JSONResponse(

0 commit comments

Comments
 (0)