1313use OCP \IRequest ;
1414use OCP \IUser ;
1515use 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 ;
1620use Test \TestCase ;
1721
1822class 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