1313use OCP \Share \IAttributes ;
1414use OCP \Share \IShare ;
1515use PHPUnit \Framework \MockObject \MockObject ;
16+ use Sabre \DAV \Exception \BadRequest ;
1617use Sabre \DAV \Server ;
1718use Sabre \HTTP \RequestInterface ;
1819use Sabre \HTTP \ResponseInterface ;
@@ -23,6 +24,7 @@ class FilesDropPluginTest extends TestCase {
2324 private FilesDropPlugin $ plugin ;
2425
2526 private Folder &MockObject $ node ;
27+ private IAttributes &MockObject $ attributes ;
2628 private IShare &MockObject $ share ;
2729 private Server &MockObject $ server ;
2830 private RequestInterface &MockObject $ request ;
@@ -45,10 +47,10 @@ protected function setUp(): void {
4547 $ this ->request = $ this ->createMock (RequestInterface::class);
4648 $ this ->response = $ this ->createMock (ResponseInterface::class);
4749
48- $ attributes = $ this ->createMock (IAttributes::class);
50+ $ this -> attributes = $ this ->createMock (IAttributes::class);
4951 $ this ->share ->expects ($ this ->any ())
5052 ->method ('getAttributes ' )
51- ->willReturn ($ attributes );
53+ ->willReturn ($ this -> attributes );
5254
5355 $ this ->share
5456 ->method ('getToken ' )
@@ -104,7 +106,7 @@ public function testFileAlreadyExistsValid(): void {
104106 $ this ->plugin ->beforeMethod ($ this ->request , $ this ->response );
105107 }
106108
107- public function testMKCOL (): void {
109+ public function testFileDropMKCOLWithoutNickname (): void {
108110 $ this ->plugin ->enable ();
109111 $ this ->plugin ->setShare ($ this ->share );
110112
@@ -116,6 +118,45 @@ public function testMKCOL(): void {
116118 $ this ->plugin ->beforeMethod ($ this ->request , $ this ->response );
117119 }
118120
121+ public function testFileRequestNoMKCOLWithoutNickname (): void {
122+ $ this ->plugin ->enable ();
123+ $ this ->plugin ->setShare ($ this ->share );
124+
125+ $ this ->request ->method ('getMethod ' )
126+ ->willReturn ('MKCOL ' );
127+
128+ $ this ->attributes
129+ ->method ('getAttribute ' )
130+ ->with ('fileRequest ' , 'enabled ' )
131+ ->willReturn (true );
132+
133+ $ this ->expectException (BadRequest::class);
134+
135+ $ this ->plugin ->beforeMethod ($ this ->request , $ this ->response );
136+ }
137+
138+ public function testFileRequestMKCOLWithNickname (): void {
139+ $ this ->plugin ->enable ();
140+ $ this ->plugin ->setShare ($ this ->share );
141+
142+ $ this ->request ->method ('getMethod ' )
143+ ->willReturn ('MKCOL ' );
144+
145+ $ this ->attributes
146+ ->method ('getAttribute ' )
147+ ->with ('fileRequest ' , 'enabled ' )
148+ ->willReturn (true );
149+
150+ $ this ->request ->method ('hasHeader ' )
151+ ->with ('X-NC-Nickname ' )
152+ ->willReturn (true );
153+ $ this ->request ->method ('getHeader ' )
154+ ->with ('X-NC-Nickname ' )
155+ ->willReturn ('nickname ' );
156+
157+ $ this ->plugin ->beforeMethod ($ this ->request , $ this ->response );
158+ }
159+
119160 public function testSubdirPut (): void {
120161 $ this ->plugin ->enable ();
121162 $ this ->plugin ->setShare ($ this ->share );
0 commit comments