diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php index e2cb45ae081..42bd5fee2c3 100644 --- a/tests/integration/features/bootstrap/FeatureContext.php +++ b/tests/integration/features/bootstrap/FeatureContext.php @@ -210,6 +210,92 @@ public function userTriesToCreateRoom($user, $statusCode, TableNode $formData = $this->assertStatusCode($this->response, $statusCode); } + /** + * @Then /^user "([^"]*)" gets the room for path "([^"]*)" with (\d+)$/ + * + * @param string $user + * @param string $path + * @param int $statusCode + */ + public function userGetsTheRoomForPath($user, $path, $statusCode) { + $fileId = $this->getFileIdForPath($user, $path); + + $this->setCurrentUser($user); + $this->sendRequest('GET', '/apps/spreed/api/v1/file/' . $fileId); + $this->assertStatusCode($this->response, $statusCode); + + if ($statusCode !== '200') { + return; + } + + $response = $this->getDataFromResponse($this->response); + + $identifier = 'file ' . $path . ' room'; + self::$identifierToToken[$identifier] = $response['token']; + self::$tokenToIdentifier[$response['token']] = $identifier; + } + + /** + * @param string $user + * @param string $path + * @return int + */ + private function getFileIdForPath($user, $path) { + $this->currentUser = $user; + + $url = "/$user/$path"; + + $headers = []; + $headers['Depth'] = 0; + + $body = '' . + ' ' . + ' ' . + ' ' . + ''; + + $this->sendingToDav('PROPFIND', $url, $headers, $body); + + $this->assertStatusCode($this->response, 207); + + $xmlResponse = simplexml_load_string($this->response->getBody()); + $xmlResponse->registerXPathNamespace('oc', 'http://owncloud.org/ns'); + + return (int)$xmlResponse->xpath('//oc:fileid')[0]; + } + + /** + * @param string $verb + * @param string $url + * @param array $headers + * @param string $body + */ + private function sendingToDav(string $verb, string $url, array $headers = null, string $body = null) { + $fullUrl = $this->baseUrl . "remote.php/dav/files" . $url; + $client = new Client(); + $options = []; + if ($this->currentUser === 'admin') { + $options['auth'] = 'admin'; + } else { + $options['auth'] = [$this->currentUser, '123456']; + } + $options['headers'] = [ + 'OCS_APIREQUEST' => 'true' + ]; + if ($headers !== null) { + $options['headers'] = array_merge($options['headers'], $headers); + } + if ($body !== null) { + $options['body'] = $body; + } + + try { + $this->response = $client->send($client->createRequest($verb, $fullUrl, $options)); + } catch (GuzzleHttp\Exception\ClientException $ex) { + $this->response = $ex->getResponse(); + } + } + /** * @Then /^user "([^"]*)" joins room "([^"]*)" with (\d+)$/ * diff --git a/tests/integration/features/bootstrap/SharingContext.php b/tests/integration/features/bootstrap/SharingContext.php index 9c2e1d1ec77..0d377ec91c5 100644 --- a/tests/integration/features/bootstrap/SharingContext.php +++ b/tests/integration/features/bootstrap/SharingContext.php @@ -144,6 +144,31 @@ public function userSharesWithUserWithOcs(string $user, string $path, string $sh $this->theOCSStatusCodeShouldBe($statusCode); } + /** + * @When user :user shares :path with group :sharee + * + * @param string $user + * @param string $path + * @param string $sharee + * @param TableNode|null $body + */ + public function userSharesWithGroup(string $user, string $path, string $sharee, TableNode $body = null) { + $this->userSharesWith($user, $path, 1 /*Share::SHARE_TYPE_GROUP*/, $sharee, $body); + } + + /** + * @When user :user shares :path with group :sharee with OCS :statusCode + * + * @param string $user + * @param string $path + * @param string $sharee + * @param int $statusCode + */ + public function userSharesWithGroupWithOcs(string $user, string $path, string $sharee, int $statusCode) { + $this->userSharesWithGroup($user, $path, $sharee); + $this->theOCSStatusCodeShouldBe($statusCode); + } + /** * @When user :user shares :path with room :room * @@ -169,6 +194,29 @@ public function userSharesWithRoomWithOcs(string $user, string $path, string $ro $this->theOCSStatusCodeShouldBe($statusCode); } + /** + * @When user :user shares :path by link + * + * @param string $user + * @param string $path + * @param TableNode|null $body + */ + public function userSharesByLink(string $user, string $path, TableNode $body = null) { + $this->userSharesWith($user, $path, 3 /*Share::SHARE_TYPE_LINK*/, '', $body); + } + + /** + * @When user :user shares :path by link with OCS :statusCode + * + * @param string $user + * @param string $path + * @param int $statusCode + */ + public function userSharesByLinkWithOcs(string $user, string $path, int $statusCode) { + $this->userSharesByLink($user, $path); + $this->theOCSStatusCodeShouldBe($statusCode); + } + /** * @When user :user updates last share with * diff --git a/tests/integration/features/conversation/files.feature b/tests/integration/features/conversation/files.feature new file mode 100644 index 00000000000..d79b9024f1d --- /dev/null +++ b/tests/integration/features/conversation/files.feature @@ -0,0 +1,189 @@ +Feature: conversation/files + + Background: + Given user "participant1" exists + Given user "participant2" exists + Given user "participant3" exists + And group "group1" exists + And user "participant2" is member of group "group1" + + # When "user XXX gets the room for path YYY with 200" succeeds the room token + # can later be used by any participant using the "file YYY room" identifier. + + Scenario: get room for file not shared + When user "participant1" gets the room for path "welcome.txt" with 404 + + + + Scenario: get room for file shared with user + Given user "participant1" shares "welcome.txt" with user "participant2" with OCS 100 + When user "participant1" gets the room for path "welcome.txt" with 200 + And user "participant2" gets the room for path "welcome (2).txt" with 200 + Then user "participant1" is participant of room "file welcome (2).txt room" + And user "participant2" is participant of room "file welcome (2).txt room" + + Scenario: get room for folder shared with user + Given user "participant1" creates folder "/test" + And user "participant1" shares "test" with user "participant2" with OCS 100 + When user "participant1" gets the room for path "test" with 404 + And user "participant2" gets the room for path "test" with 404 + + Scenario: get room for file in folder shared with user + Given user "participant1" creates folder "/test" + And user "participant1" moves file "/welcome.txt" to "/test/renamed.txt" with 201 + And user "participant1" shares "test" with user "participant2" with OCS 100 + When user "participant1" gets the room for path "test/renamed.txt" with 200 + And user "participant2" gets the room for path "test/renamed.txt" with 200 + Then user "participant1" is participant of room "file test/renamed.txt room" + And user "participant2" is participant of room "file test/renamed.txt room" + + Scenario: get room for file in folder reshared with user + Given user "participant1" creates folder "/test" + And user "participant1" moves file "/welcome.txt" to "/test/renamed.txt" with 201 + And user "participant1" shares "test" with user "participant2" with OCS 100 + And user "participant2" shares "test" with user "participant3" with OCS 100 + When user "participant1" gets the room for path "test/renamed.txt" with 200 + And user "participant2" gets the room for path "test/renamed.txt" with 200 + And user "participant3" gets the room for path "test/renamed.txt" with 200 + Then user "participant1" is participant of room "file test/renamed.txt room" + And user "participant2" is participant of room "file test/renamed.txt room" + And user "participant3" is participant of room "file test/renamed.txt room" + + Scenario: get room for file no longer shared + Given user "participant1" shares "welcome.txt" with user "participant2" with OCS 100 + And user "participant1" deletes last share + When user "participant1" gets the room for path "welcome.txt" with 404 + + + + Scenario: get room for file shared with group + Given user "participant1" shares "welcome.txt" with group "group1" with OCS 100 + When user "participant1" gets the room for path "welcome.txt" with 200 + And user "participant2" gets the room for path "welcome (2).txt" with 200 + Then user "participant1" is participant of room "file welcome (2).txt room" + And user "participant2" is participant of room "file welcome (2).txt room" + + Scenario: get room for file shared with user and group + Given user "participant1" shares "welcome.txt" with group "group1" with OCS 100 + And user "participant1" shares "welcome.txt" with user "participant3" with OCS 100 + When user "participant1" gets the room for path "welcome.txt" with 200 + And user "participant2" gets the room for path "welcome (2).txt" with 200 + And user "participant3" gets the room for path "welcome (2).txt" with 200 + Then user "participant1" is participant of room "file welcome (2).txt room" + And user "participant2" is participant of room "file welcome (2).txt room" + And user "participant3" is participant of room "file welcome (2).txt room" + + + + Scenario: get room for file shared by link + Given user "participant1" shares "welcome.txt" by link with OCS 100 + When user "participant1" gets the room for path "welcome.txt" with 404 + + Scenario: get room for file shared with user and by link + Given user "participant1" shares "welcome.txt" by link with OCS 100 + And user "participant1" shares "welcome.txt" with user "participant2" with OCS 100 + When user "participant1" gets the room for path "welcome.txt" with 200 + And user "participant2" gets the room for path "welcome (2).txt" with 200 + Then user "participant1" is participant of room "file welcome (2).txt room" + And user "participant2" is participant of room "file welcome (2).txt room" + + + + Scenario: owner of a shared file can join its room + Given user "participant1" shares "welcome.txt" with user "participant2" with OCS 100 + And user "participant2" gets the room for path "welcome (2).txt" with 200 + When user "participant1" joins room "file welcome (2).txt room" with 200 + Then user "participant1" is participant of room "file welcome (2).txt room" + + Scenario: user with access to a file can join its room + Given user "participant1" shares "welcome.txt" with user "participant2" with OCS 100 + And user "participant1" gets the room for path "welcome.txt" with 200 + When user "participant2" joins room "file welcome.txt room" with 200 + Then user "participant2" is participant of room "file welcome.txt room" + + Scenario: owner of a file in a shared folder can join its room + Given user "participant1" creates folder "/test" + And user "participant1" moves file "/welcome.txt" to "/test/renamed.txt" with 201 + And user "participant1" shares "test" with user "participant2" with OCS 100 + And user "participant2" gets the room for path "test/renamed.txt" with 200 + When user "participant1" joins room "file test/renamed.txt room" with 200 + Then user "participant1" is participant of room "file test/renamed.txt room" + + Scenario: user with access to a file in a shared folder can join its room + Given user "participant1" creates folder "/test" + And user "participant1" moves file "/welcome.txt" to "/test/renamed.txt" with 201 + And user "participant1" shares "test" with user "participant2" with OCS 100 + And user "participant1" gets the room for path "test/renamed.txt" with 200 + When user "participant2" joins room "file test/renamed.txt room" with 200 + Then user "participant2" is participant of room "file test/renamed.txt room" + + Scenario: owner of a no longer shared file can not join its room + Given user "participant1" shares "welcome.txt" with user "participant2" with OCS 100 + And user "participant2" gets the room for path "welcome (2).txt" with 200 + And user "participant1" deletes last share + When user "participant1" joins room "file welcome (2).txt room" with 404 + Then user "participant1" is not participant of room "file welcome (2).txt room" + + Scenario: user no longer with access to a file can not join its room + Given user "participant1" shares "welcome.txt" with user "participant3" with OCS 100 + And user "participant1" shares "welcome.txt" with user "participant2" with OCS 100 + And user "participant1" gets the room for path "welcome.txt" with 200 + And user "participant1" deletes last share + When user "participant2" joins room "file welcome.txt room" with 404 + Then user "participant2" is not participant of room "file welcome.txt room" + + Scenario: user without access to a file can not join its room + Given user "participant1" shares "welcome.txt" with user "participant2" with OCS 100 + And user "participant1" gets the room for path "welcome.txt" with 200 + When user "participant3" joins room "file welcome.txt room" with 404 + Then user "participant3" is not participant of room "file welcome.txt room" + + Scenario: guest can not join a file room + Given user "participant1" shares "welcome.txt" with user "participant2" with OCS 100 + And user "participant1" gets the room for path "welcome.txt" with 200 + When user "guest" joins room "file welcome.txt room" with 404 + + + + Scenario: owner of a shared file can join its room again after leaving it + Given user "participant1" shares "welcome.txt" with user "participant2" with OCS 100 + And user "participant2" gets the room for path "welcome (2).txt" with 200 + And user "participant1" joins room "file welcome (2).txt room" with 200 + And user "participant1" is participant of room "file welcome (2).txt room" + When user "participant1" leaves room "file welcome (2).txt room" with 200 + And user "participant1" is not participant of room "file welcome (2).txt room" + And user "participant1" joins room "file welcome (2).txt room" with 200 + Then user "participant1" is participant of room "file welcome (2).txt room" + + Scenario: user with access to a file can join its room again after leaving it + Given user "participant1" shares "welcome.txt" with user "participant2" with OCS 100 + And user "participant1" gets the room for path "welcome.txt" with 200 + And user "participant2" joins room "file welcome.txt room" with 200 + And user "participant2" is participant of room "file welcome.txt room" + When user "participant2" leaves room "file welcome.txt room" with 200 + And user "participant2" is not participant of room "file welcome.txt room" + And user "participant2" joins room "file welcome.txt room" with 200 + Then user "participant2" is participant of room "file welcome.txt room" + + + + # Participants are removed from the room for a no longer shared file once they + # try to join the room again, but not when the file is unshared. + + Scenario: owner is not participant of room for file no longer shared + Given user "participant1" shares "welcome.txt" with user "participant2" with OCS 100 + And user "participant1" gets the room for path "welcome.txt" with 200 + And user "participant1" is participant of room "file welcome.txt room" + When user "participant1" deletes last share + Then user "participant1" is participant of room "file welcome.txt room" + And user "participant1" joins room "file welcome.txt room" with 404 + And user "participant1" is not participant of room "file welcome.txt room" + + Scenario: user is not participant of room for file no longer with access to it + Given user "participant1" shares "welcome.txt" with user "participant2" with OCS 100 + And user "participant2" gets the room for path "welcome (2).txt" with 200 + And user "participant2" is participant of room "file welcome (2).txt room" + When user "participant1" deletes last share + Then user "participant2" is participant of room "file welcome (2).txt room" + And user "participant2" joins room "file welcome (2).txt room" with 404 + And user "participant2" is not participant of room "file welcome (2).txt room"