1010use  OCA \Files_External \Lib \Auth \PublicKey \RSA ;
1111use  OCP \AppFramework \Http \JSONResponse ;
1212use  OCP \IGroupManager ;
13+ use  OCP \IL10N ;
1314use  OCP \IRequest ;
1415use  OCP \IUser ;
1516use  OCP \IUserSession ;
@@ -28,6 +29,8 @@ class AjaxControllerTest extends TestCase {
2829	private  $ groupManager
2930	/** @var AjaxController */ 
3031	private  $ ajaxController
32+ 	/** @var IL10N */ 
33+ 	private  $ l10n
3134
3235	protected  function  setUp (): void  {
3336		$ this request  = $ this createMock (IRequest::class);
@@ -39,16 +42,27 @@ protected function setUp(): void {
3942			->getMock ();
4043		$ this userSession  = $ this createMock (IUserSession::class);
4144		$ this groupManager  = $ this createMock (IGroupManager::class);
45+ 		$ this l10n  = $ this createMock (IL10N ::class);
4246
4347		$ this ajaxController  = new  AjaxController (
4448			'files_external ' ,
4549			$ this request ,
4650			$ this rsa ,
4751			$ this globalAuth ,
4852			$ this userSession ,
49- 			$ this groupManager 
53+ 			$ this groupManager ,
54+ 			$ this l10n ,
5055		);
5156
57+ 		$ this l10n ->expects ($ this any ())
58+ 			->method ('t ' )
59+ 			->willReturnCallback (function  ($ string$ args
60+ 				if  (!is_array ($ args
61+ 					$ args$ args
62+ 				}
63+ 				return  vsprintf ($ string$ args
64+ 			});
65+ 
5266		parent ::setUp ();
5367	}
5468
@@ -87,7 +101,9 @@ public function testSaveGlobalCredentialsAsAdminForAnotherUser(): void {
87101			->expects ($ this never ())
88102			->method ('saveAuth ' );
89103
90- 		$ this assertSame (false , $ this ajaxController ->saveGlobalCredentials ('UidOfTestUser ' , 'test ' , 'password ' ));
104+ 		$ response$ this ajaxController ->saveGlobalCredentials ('UidOfTestUser ' , 'test ' , 'password ' );
105+ 		$ this assertSame ($ responsegetStatus (), 403 );
106+ 		$ this assertSame ('Permission denied ' , $ responsegetData ()['message ' ]);
91107	}
92108
93109	public  function  testSaveGlobalCredentialsAsAdminForSelf (): void  {
@@ -105,7 +121,8 @@ public function testSaveGlobalCredentialsAsAdminForSelf(): void {
105121			->method ('saveAuth ' )
106122			->with ('MyAdminUid ' , 'test ' , 'password ' );
107123
108- 		$ this assertSame (true , $ this ajaxController ->saveGlobalCredentials ('MyAdminUid ' , 'test ' , 'password ' ));
124+ 		$ response$ this ajaxController ->saveGlobalCredentials ('MyAdminUid ' , 'test ' , 'password ' );
125+ 		$ this assertSame ($ responsegetStatus (), 200 );
109126	}
110127
111128	public  function  testSaveGlobalCredentialsAsNormalUserForSelf (): void  {
@@ -120,7 +137,8 @@ public function testSaveGlobalCredentialsAsNormalUserForSelf(): void {
120137			->method ('saveAuth ' )
121138			->with ('MyUserUid ' , 'test ' , 'password ' );
122139
123- 		$ this assertSame (true , $ this ajaxController ->saveGlobalCredentials ('MyUserUid ' , 'test ' , 'password ' ));
140+ 		$ response$ this ajaxController ->saveGlobalCredentials ('MyUserUid ' , 'test ' , 'password ' );
141+ 		$ this assertSame ($ responsegetStatus (), 200 );
124142	}
125143
126144	public  function  testSaveGlobalCredentialsAsNormalUserForAnotherUser (): void  {
@@ -135,6 +153,8 @@ public function testSaveGlobalCredentialsAsNormalUserForAnotherUser(): void {
135153			->expects ($ this never ())
136154			->method ('saveAuth ' );
137155
138- 		$ this assertSame (false , $ this ajaxController ->saveGlobalCredentials ('AnotherUserUid ' , 'test ' , 'password ' ));
156+ 		$ response$ this ajaxController ->saveGlobalCredentials ('AnotherUserUid ' , 'test ' , 'password ' );
157+ 		$ this assertSame ($ responsegetStatus (), 403 );
158+ 		$ this assertSame ('Permission denied ' , $ responsegetData ()['message ' ]);
139159	}
140160}
0 commit comments