2020use OCP \IUser ;
2121use OCP \IUserManager ;
2222use OCP \IUserSession ;
23+ use OCP \Lockdown \ILockdownManager ;
2324use OCP \User \Events \BeforePasswordUpdatedEvent ;
2425use OCP \User \Events \PasswordUpdatedEvent ;
2526use OCP \User \Events \UserCreatedEvent ;
@@ -41,6 +42,7 @@ class UserEventsListenersTest extends TestCase {
4142 protected IUserManager &MockObject $ userManager ;
4243 protected IUserSession &MockObject $ userSession ;
4344 protected SetupManager &MockObject $ setupManager ;
45+ protected ILockdownManager &MockObject $ lockdownManager ;
4446 protected PassphraseService &MockObject $ passphraseService ;
4547
4648 protected UserEventsListener $ instance ;
@@ -55,6 +57,7 @@ public function setUp(): void {
5557 $ this ->userManager = $ this ->createMock (IUserManager::class);
5658 $ this ->userSession = $ this ->createMock (IUserSession::class);
5759 $ this ->setupManager = $ this ->createMock (SetupManager::class);
60+ $ this ->lockdownManager = $ this ->createMock (ILockdownManager::class);
5861 $ this ->passphraseService = $ this ->createMock (PassphraseService::class);
5962
6063 $ this ->instance = new UserEventsListener (
@@ -66,10 +69,14 @@ public function setUp(): void {
6669 $ this ->userSession ,
6770 $ this ->setupManager ,
6871 $ this ->passphraseService ,
72+ $ this ->lockdownManager ,
6973 );
7074 }
7175
7276 public function testLogin (): void {
77+ $ this ->lockdownManager ->expects (self ::once ())
78+ ->method ('canAccessFilesystem ' )
79+ ->willReturn (true );
7380 $ this ->userSetup ->expects (self ::once ())
7481 ->method ('setupUser ' )
7582 ->willReturn (true );
@@ -96,6 +103,9 @@ public function testLogin(): void {
96103 }
97104
98105 public function testLoginMasterKey (): void {
106+ $ this ->lockdownManager ->expects (self ::once ())
107+ ->method ('canAccessFilesystem ' )
108+ ->willReturn (true );
99109 $ this ->util ->method ('isMasterKeyEnabled ' )->willReturn (true );
100110
101111 $ this ->userSetup ->expects (self ::never ())
@@ -121,6 +131,36 @@ public function testLoginMasterKey(): void {
121131 $ this ->instance ->handle ($ event );
122132 }
123133
134+ public function testLoginNoFilesystemAccess (): void {
135+ $ this ->lockdownManager ->expects (self ::once ())
136+ ->method ('canAccessFilesystem ' )
137+ ->willReturn (false );
138+
139+ $ this ->userSetup ->expects (self ::never ())
140+ ->method ('setupUser ' );
141+
142+ $ this ->setupManager ->expects (self ::never ())
143+ ->method ('setupForUser ' );
144+
145+ $ this ->keyManager ->expects (self ::never ())
146+ ->method ('init ' );
147+
148+ $ user = $ this ->createMock (IUser::class);
149+ $ user ->expects (self ::any ())
150+ ->method ('getUID ' )
151+ ->willReturn ('testUser ' );
152+
153+ $ event = $ this ->createMock (UserLoggedInEvent::class);
154+ $ event ->expects (self ::atLeastOnce ())
155+ ->method ('getUser ' )
156+ ->willReturn ($ user );
157+ $ event ->expects (self ::atLeastOnce ())
158+ ->method ('getPassword ' )
159+ ->willReturn ('password ' );
160+
161+ $ this ->instance ->handle ($ event );
162+ }
163+
124164 public function testLogout (): void {
125165 $ this ->session ->expects (self ::once ())
126166 ->method ('clear ' );
0 commit comments