From 10840fd4c021f8b5fe750f3caf37afe4ebc19cf9 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Wed, 9 Dec 2020 10:26:20 +0100 Subject: Fix tests for listable conversations Fix number detection in participantType tests The guests app is now enabled. The spreed app is whitelisted for guest account users. A password is now set for the guest account users to be able to log in properly. Added system message tests for listable and read-only attributes. Added tests scenarios for permission checks and room type checks before setting listable attribute. Added integration tests for /listed-rooms endpoint Covers permissions to search and also with and without search terms. Signed-off-by: Vincent Petry --- .drone.yml | 4 +- .../features/bootstrap/FeatureContext.php | 164 ++++++++++++++++++++- .../callapi/joining-listable-rooms.feature | 96 ------------ .../features/chat/system-messages.feature | 60 ++++++++ .../features/conversation/find-listed.feature | 126 ++++++++++++++++ .../features/conversation/join-listable.feature | 97 ++++++++++++ .../features/conversation/set-listable.feature | 57 +++++++ .../spreedcheats/lib/Controller/ApiController.php | 15 +- tests/php/Controller/SignalingControllerTest.php | 2 + tests/php/Signaling/BackendNotifierTest.php | 4 + 10 files changed, 518 insertions(+), 107 deletions(-) delete mode 100644 tests/integration/features/callapi/joining-listable-rooms.feature create mode 100644 tests/integration/features/conversation/find-listed.feature create mode 100644 tests/integration/features/conversation/join-listable.feature create mode 100644 tests/integration/features/conversation/set-listable.feature diff --git a/.drone.yml b/.drone.yml index 371d7a0db..c4b91b773 100644 --- a/.drone.yml +++ b/.drone.yml @@ -273,14 +273,12 @@ steps: environment: APP_NAME: spreed CORE_BRANCH: master - GUESTS_BRANCH: master DATABASEHOST: sqlite commands: - bash tests/drone-run-integration-tests.sh || exit 0 - wget https://raw.githubusercontent.com/nextcloud/travis_ci/master/before_install.sh - bash ./before_install.sh $APP_NAME $CORE_BRANCH $DATABASEHOST - cd ../server - - git clone --depth 1 -b "$GUESTS_BRANCH" https://github.com/nextcloud/guests apps/guests - ./occ app:enable $APP_NAME - cd apps/$APP_NAME @@ -380,12 +378,14 @@ steps: environment: APP_NAME: spreed CORE_BRANCH: master + GUESTS_BRANCH: master DATABASEHOST: sqlite commands: - bash tests/drone-run-integration-tests.sh || exit 0 - wget https://raw.githubusercontent.com/nextcloud/travis_ci/master/before_install.sh - bash ./before_install.sh $APP_NAME $CORE_BRANCH $DATABASEHOST - cd ../server + - git clone --depth 1 -b "$GUESTS_BRANCH" https://github.com/nextcloud/guests apps/guests - ./occ app:enable $APP_NAME - cd apps/$APP_NAME diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php index d938360b1..d062de2de 100644 --- a/tests/integration/features/bootstrap/FeatureContext.php +++ b/tests/integration/features/bootstrap/FeatureContext.php @@ -35,6 +35,7 @@ use Psr\Http\Message\ResponseInterface; * Defines application features from the specific context. */ class FeatureContext implements Context, SnippetAcceptingContext { + public const TEST_PASSWORD = '123456'; /** @var array[] */ protected static $identifierToToken; @@ -77,6 +78,12 @@ class FeatureContext implements Context, SnippetAcceptingContext { /** @var SharingContext */ private $sharingContext; + /** @var null|bool */ + private $guestsAppWasEnabled = null; + + /** @var string */ + private $guestsOldWhitelist; + use CommandLineTrait; public static function getTokenForIdentifier(string $identifier) { @@ -89,6 +96,7 @@ class FeatureContext implements Context, SnippetAcceptingContext { public function __construct() { $this->cookieJars = []; $this->baseUrl = getenv('TEST_SERVER_URL'); + $this->guestsAppWasEnabled = null; } /** @@ -130,6 +138,78 @@ class FeatureContext implements Context, SnippetAcceptingContext { } } + /** + * @Then /^user "([^"]*)" cannot find any listed rooms(?: \((v(1|2|3))\))?$/ + * + * @param string $user + * @param string $apiVersion + */ + public function userCannotFindAnyListedRooms($user, $apiVersion = 'v1') { + $this->userCanFindListedRoomsWithTerm($user, '', $apiVersion, null); + } + + /** + * @Then /^user "([^"]*)" cannot find any listed rooms with (\d+)(?: \((v(1|2|3))\))?$/ + * + * @param string $user + * @param int $statusCode + * @param string $apiVersion + */ + public function userCannotFindAnyListedRoomsWithStatus($user, $statusCode, $apiVersion = 'v1') { + $this->setCurrentUser($user); + $this->sendRequest('GET', '/apps/spreed/api/' . $apiVersion . '/room'); + $this->assertStatusCode($this->response, $statusCode); + } + + /** + * @Then /^user "([^"]*)" cannot find any listed rooms with term "([^"]*)"(?: \((v(1|2|3))\))?$/ + * + * @param string $user + * @param string $term + * @param string $apiVersion + */ + public function userCannotFindAnyListedRoomsWithTerm($user, $term, $apiVersion = 'v1') { + $this->userCanFindListedRoomsWithTerm($user, $term, $apiVersion, null); + } + + /** + * @Then /^user "([^"]*)" can find listed rooms(?: \((v(1|2|3))\))?$/ + * + * @param string $user + * @param string $apiVersion + * @param TableNode|null $formData + */ + public function userCanFindListedRooms($user, $apiVersion = 'v1', TableNode $formData = null) { + $this->userCanFindListedRoomsWithTerm($user, '', $apiVersion, $formData); + } + + /** + * @Then /^user "([^"]*)" can find listed rooms with term "([^"]*)"(?: \((v(1|2|3))\))?$/ + * + * @param string $user + * @param string $term + * @param string $apiVersion + * @param TableNode|null $formData + */ + public function userCanFindListedRoomsWithTerm($user, $term, $apiVersion = 'v1', TableNode $formData = null) { + $this->setCurrentUser($user); + $suffix = ''; + if ($term !== '') { + $suffix = '?searchTerm=' . \rawurlencode($term); + } + $this->sendRequest('GET', '/apps/spreed/api/' . $apiVersion . '/listed-room' . $suffix); + $this->assertStatusCode($this->response, 200); + + $rooms = $this->getDataFromResponse($this->response); + + if ($formData === null) { + Assert::assertEmpty($rooms); + return; + } + + $this->assertRooms($rooms, $formData); + } + /** * @Then /^user "([^"]*)" is participant of the following rooms(?: \((v(1|2|3))\))?$/ * @@ -348,7 +428,7 @@ class FeatureContext implements Context, SnippetAcceptingContext { } private function mapParticipantTypeTestInput($participantType) { - if (is_int($participantType)) { + if (is_numeric($participantType)) { return $participantType; } @@ -519,7 +599,7 @@ class FeatureContext implements Context, SnippetAcceptingContext { if ($this->currentUser === 'admin') { $options['auth'] = 'admin'; } else { - $options['auth'] = [$this->currentUser, '123456']; + $options['auth'] = [$this->currentUser, self::TEST_PASSWORD]; } $options['headers'] = [ 'OCS_APIREQUEST' => 'true' @@ -824,7 +904,7 @@ class FeatureContext implements Context, SnippetAcceptingContext { } /** - * @Then /^user "([^"]*)" allows listing room "([^"]*)" for "(none|users|all)" with (\d+)(?: \((v(1|2|3))\))?$/ + * @Then /^user "([^"]*)" allows listing room "([^"]*)" for "(none|users|all|\d+)" with (\d+)(?: \((v(1|2|3))\))?$/ * * @param string $user * @param string $newState @@ -840,6 +920,8 @@ class FeatureContext implements Context, SnippetAcceptingContext { $newStateValue = 1; // Room::LISTABLE_USERS } elseif ($newState === 'all') { $newStateValue = 2; // Room::LISTABLE_ALL + } elseif (is_numeric($newState)) { + $newStateValue = (int)$newState; } else { Assert::fail('Invalid listable scope value'); } @@ -1382,6 +1464,44 @@ class FeatureContext implements Context, SnippetAcceptingContext { $this->setCurrentUser($currentUser); } + /** + * @Given /^guest accounts can be created$/ + * + * @param TableNode $formData + */ + public function allowGuestAccountsCreation(): void { + $currentUser = $this->currentUser; + $this->setCurrentUser('admin'); + + // save old state and restore at the end + $this->sendRequest('GET', '/cloud/apps?filter=enabled'); + $this->assertStatusCode($this->response, 200); + $data = $this->getDataFromResponse($this->response); + $this->guestsAppWasEnabled = in_array('guests', $data['apps'], true); + + if (!$this->guestsAppWasEnabled) { + // enable guests app + /* + $this->sendRequest('POST', '/cloud/apps/guests'); + $this->assertStatusCode($this->response, 200); + */ + // seems using provisioning API doesn't create tables... + $this->runOcc(['app:enable', 'guests']); + } + + // save previously set whitelist + $this->sendRequest('GET', '/apps/provisioning_api/api/v1/config/apps/guests/whitelist'); + $this->assertStatusCode($this->response, 200); + $this->guestsOldWhitelist = $this->getDataFromResponse($this->response)['data']; + + // set whitelist to allow spreed only + $this->sendRequest('POST', '/apps/provisioning_api/api/v1/config/apps/guests/whitelist', [ + 'value' => 'spreed', + ]); + + $this->setCurrentUser($currentUser); + } + /** * @BeforeScenario * @AfterScenario @@ -1397,6 +1517,35 @@ class FeatureContext implements Context, SnippetAcceptingContext { $this->setCurrentUser($currentUser); } + /** + * @AfterScenario + */ + public function resetGuestsAppState() { + if ($this->guestsAppWasEnabled === null) { + // guests app was not touched + return; + } + + $currentUser = $this->currentUser; + $this->setCurrentUser('admin'); + + if ($this->guestsOldWhitelist) { + // restore old whitelist + $this->sendRequest('POST', '/apps/provisioning_api/api/v1/config/apps/guests/whitelist', [ + 'value' => $this->guestsOldWhitelist, + ]); + } else { + // restore to default + $this->sendRequest('DELETE', '/apps/provisioning_api/api/v1/config/apps/guests/whitelist'); + } + + // restore app's enabled state + $this->sendRequest($this->guestsAppWasEnabled ? 'POST' : 'DELETE', '/cloud/apps/guests'); + + $this->setCurrentUser($currentUser); + $this->guestsAppWasEnabled = null; + } + /* * User management */ @@ -1432,8 +1581,11 @@ class FeatureContext implements Context, SnippetAcceptingContext { public function createGuestUser($user) { $currentUser = $this->currentUser; $this->setCurrentUser('admin'); + // in case it exists + $this->deleteUser($user); $this->sendRequest('POST', '/apps/spreedcheats/guest-users', [ 'userid' => $user, + 'password' => self::TEST_PASSWORD, ]); $this->assertStatusCode($this->response, 200); $this->createdGuestAccountUsers[] = $user; @@ -1453,7 +1605,7 @@ class FeatureContext implements Context, SnippetAcceptingContext { $this->setCurrentUser('admin'); $this->sendRequest('POST', '/cloud/users', [ 'userid' => $user, - 'password' => '123456' + 'password' => self::TEST_PASSWORD, ]); $this->assertStatusCode($this->response, 200, 'Failed to create user'); @@ -1586,7 +1738,7 @@ class FeatureContext implements Context, SnippetAcceptingContext { $requestToken = $this->extractRequestTokenFromResponse($this->response); // Login and extract new token - $password = ($user === 'admin') ? 'admin' : '123456'; + $password = ($user === 'admin') ? 'admin' : self::TEST_PASSWORD; $client = new Client(); $this->response = $client->post( $loginUrl, @@ -1625,7 +1777,7 @@ class FeatureContext implements Context, SnippetAcceptingContext { if ($this->currentUser === 'admin') { $options['auth'] = ['admin', 'admin']; } elseif (strpos($this->currentUser, 'guest') !== 0) { - $options['auth'] = [$this->currentUser, '123456']; + $options['auth'] = [$this->currentUser, self::TEST_PASSWORD]; } if ($body instanceof TableNode) { $fd = $body->getRowsHash(); diff --git a/tests/integration/features/callapi/joining-listable-rooms.feature b/tests/integration/features/callapi/joining-listable-rooms.feature deleted file mode 100644 index 0086ffbd4..000000000 --- a/tests/integration/features/callapi/joining-listable-rooms.feature +++ /dev/null @@ -1,96 +0,0 @@ -Feature: callapi/listable-rooms - Background: - Given user "creator" exists - And user "regular-user" exists - And user "user-guest" is a guest account user - # implicit: And user "guest" is a guest user with no account - - # ----------------------------------------------------------------------------- - # Non-listed rooms - # ----------------------------------------------------------------------------- - Scenario: Nobody can join a non-listed group room - Given user "creator" creates room "room" - | roomType | 2 | - | roomName | room | - When user "creator" allows listing room "room" for "none" with 200 - Then user "regular-user" joins room "room" with 404 - And user "user-guest" joins room "room" with 404 - And user "guest" joins room "room" with 404 - - Scenario: Anyone can join a non-listed public room - Given user "creator" creates room "room" - | roomType | 3 | - | roomName | room | - And user "creator" allows listing room "room" for "none" with 200 - When user "regular-user" joins room "room" with 200 - And user "user-guest" joins room "room" with 200 - And user "guest" joins room "room" with 200 - Then user "creator" sees the following attendees in room "room" with 200 (v3) - | actorId | participantType | actorType | - | creator | OWNER | users | - | regular-user | USER_SELF_JOINED | users | - | user-guest | USER_SELF_JOINED | users | - | "guest" | GUEST | guests | - - # ----------------------------------------------------------------------------- - # User-listed rooms - # ----------------------------------------------------------------------------- - Scenario: Only regular users can join a user-listed group room - Given user "creator" creates room "room" - | roomType | 2 | - | roomName | room | - And user "creator" allows listing room "room" for "users" with 200 - When user "regular-user" joins room "room" with 200 - And user "user-guest" joins room "room" with 404 - And user "guest" joins room "room" with 404 - Then user "creator" sees the following attendees in room "room" with 200 (v3) - | actorId | participantType | actorType | - | creator | OWNER | users | - | regular-user | USER | users | - - Scenario: Anyone can join a user-listed public room - Given user "creator" creates room "room" - | roomType | 3 | - | roomName | room | - And user "creator" allows listing room "room" for "users" with 200 - When user "regular-user" joins room "room" with 200 - And user "user-guest" joins room "room" with 200 - And user "guest" joins room "room" with 200 - Then user "creator" sees the following attendees in room "room" with 200 (v3) - | actorId | participantType | actorType | - | creator | OWNER | users | - | regular-user | USER | users | - | user-guest | USER_SELF_JOINED | users | - | "guest" | GUEST | guests | - - # ----------------------------------------------------------------------------- - # All-listed rooms - # ----------------------------------------------------------------------------- - Scenario: Only users with accounts can join an all-listed group room - Given user "creator" creates room "room" - | roomType | 2 | - | roomName | room | - And user "creator" allows listing room "room" for "all" with 200 - When user "regular-user" joins room "room" with 200 - And user "user-guest" joins room "room" with 200 - And user "guest" joins room "room" with 404 - Then user "creator" sees the following attendees in room "room" with 200 (v3) - | actorId | participantType | actorType | - | creator | OWNER | users | - | regular-user | USER | users | - | user-guest | USER_SELF_JOINED | users | - - Scenario: Anyone can join an all-listed public room - Given user "creator" creates room "room" - | roomType | 3 | - | roomName | room | - And user "creator" allows listing room "room" for "all" with 200 - When user "regular-user" joins room "room" with 200 - And user "user-guest" joins room "room" with 200 - And user "guest" joins room "room" with 200 - Then user "creator" sees the following attendees in room "room" with 200 (v3) - | actorId | participantType | actorType | - | creator | OWNER | users | - | regular-user | USER | users | - | user-guest | USER | users | - | "guest" | GUEST | guests | diff --git a/tests/integration/features/chat/system-messages.feature b/tests/integration/features/chat/system-messages.feature index 22166c62a..453b52c1e 100644 --- a/tests/integration/features/chat/system-messages.feature +++ b/tests/integration/features/chat/system-messages.feature @@ -160,6 +160,23 @@ Feature: System messages | file last share room | users | participant1 | participant1-displayname | user_added | | file last share room | users | participant1 | participant1-displayname | conversation_created | + Scenario: Joining listed room + Given user "participant1" creates room "room" + | roomType | 2 | + | roomName | room | + And user "participant1" allows listing room "room" for "all" with 200 + When user "participant2" joins room "room" with 200 + Then user "participant1" sees the following system messages in room "room" with 200 + | room | actorType | actorId | actorDisplayName | systemMessage | + | room | users | participant2 | participant2-displayname | user_added | + | room | users | participant1 | participant1-displayname | listable_all | + | room | users | participant1 | participant1-displayname | conversation_created | + And user "participant2" sees the following system messages in room "room" with 200 + | room | actorType | actorId | actorDisplayName | systemMessage | + | room | users | participant2 | participant2-displayname | user_added | + | room | users | participant1 | participant1-displayname | listable_all | + | room | users | participant1 | participant1-displayname | conversation_created | + Scenario: Participant escalation Given user "participant1" creates room "room" | roomType | 2 | @@ -193,3 +210,46 @@ Feature: System messages | room | users | participant1 | participant1-displayname | moderator_promoted | | room | users | participant1 | participant1-displayname | user_added | | room | users | participant1 | participant1-displayname | conversation_created | + + Scenario: Changing listable scope of room + Given user "participant1" creates room "room" + | roomType | 2 | + | roomName | room | + And user "participant1" adds "participant2" to room "room" with 200 + When user "participant1" allows listing room "room" for "all" with 200 + And user "participant1" allows listing room "room" for "users" with 200 + And user "participant1" allows listing room "room" for "none" with 200 + Then user "participant1" sees the following system messages in room "room" with 200 + | room | actorType | actorId | actorDisplayName | systemMessage | + | room | users | participant1 | participant1-displayname | listable_none | + | room | users | participant1 | participant1-displayname | listable_users | + | room | users | participant1 | participant1-displayname | listable_all | + | room | users | participant1 | participant1-displayname | user_added | + | room | users | participant1 | participant1-displayname | conversation_created | + And user "participant2" sees the following system messages in room "room" with 200 + | room | actorType | actorId | actorDisplayName | systemMessage | + | room | users | participant1 | participant1-displayname | listable_none | + | room | users | participant1 | participant1-displayname | listable_users | + | room | users | participant1 | participant1-displayname | listable_all | + | room | users | participant1 | participant1-displayname | user_added | + | room | users | participant1 | participant1-displayname | conversation_created | + + Scenario: Locking a room + Given user "participant1" creates room "room" + | roomType | 2 | + | roomName | room | + And user "participant1" adds "participant2" to room "room" with 200 + When user "participant1" locks room "room" with 200 + And user "participant1" unlocks room "room" with 200 + Then user "participant1" sees the following system messages in room "room" with 200 + | room | actorType | actorId | actorDisplayName | systemMessage | + | room | users | participant1 | participant1-displayname | read_only_off | + | room | users | participant1 | participant1-displayname | read_only | + | room | users | participant1 | participant1-displayname | user_added | + | room | users | participant1 | participant1-displayname | conversation_created | + And user "participant2" sees the following system messages in room "room" with 200 + | room | actorType | actorId | actorDisplayName | systemMessage | + | room | users | participant1 | participant1-displayname | read_only_off | + | room | users | participant1 | participant1-displayname | read_only | + | room | users | participant1 | participant1-displayname | user_added | + | room | users | participant1 | participant1-displayname | conversation_created | diff --git a/tests/integration/features/conversation/find-listed.feature b/tests/integration/features/conversation/find-listed.feature new file mode 100644 index 000000000..668a97ba0 --- /dev/null +++ b/tests/integration/features/conversation/find-listed.feature @@ -0,0 +1,126 @@ +Feature: conversation/find-listed + Background: + Given user "creator" exists + And user "regular-user" exists + And guest accounts can be created + And user "user-guest" is a guest account user + + Scenario Outline: Nobody can find non-listed rooms + Given user "creator" creates room "group-room" + | roomType | 2 | + | roomName | group-room | + And user "creator" creates room "public-room" + | roomType | 3 | + | roomName | public-room | + When user "creator" allows listing room "group-room" for "none" with 200 + And user "creator" allows listing room "public-room" for "none" with 200 + Then user "creator" cannot find any listed rooms (v3) + Examples: + | user | + | creator | + | regular-user | + | user-guest | + + Scenario: Regular users can find user-listed rooms + Given user "creator" creates room "group-room" + | roomType | 2 | + | roomName | group-room | + And user "creator" creates room "public-room" + | roomType | 3 | + | roomName | public-room | + When user "creator" allows listing room "group-room" for "users" with 200 + And user "creator" allows listing room "public-room" for "users" with 200 + Then user "regular-user" can find listed rooms (v3) + | name | listable | + | group-room | 1 | + | public-room | 1 | + And user "user-guest" cannot find any listed rooms (v3) + + Scenario: All users can find all-listed rooms + Given user "creator" creates room "group-room" + | roomType | 2 | + | roomName | group-room | + And user "creator" creates room "public-room" + | roomType | 3 | + | roomName | public-room | + When user "creator" allows listing room "group-room" for "all" with 200 + And user "creator" allows listing room "public-room" for "all" with 200 + Then user "regular-user" can find listed rooms (v3) + | name | listable | + | group-room | 2 | + | public-room | 2 | + And user "user-guest" can find listed rooms (v3) + | name | listable | + | group-room | 2 | + | public-room | 2 | + + Scenario: Participants cannot search for already joined listed rooms + Given user "creator" creates room "group-room" + | roomType | 2 | + | roomName | group-room | + And user "creator" creates room "public-room" + | roomType | 3 | + | roomName | public-room | + And user "creator" allows listing room "group-room" for "users" with 200 + And user "creator" allows listing room "public-room" for "users" with 200 + When user "regular-user" joins room "group-room" with 200 + And user "regular-user" joins room "public-room" with 200 + Then user "regular-user" cannot find any listed rooms (v3) + + Scenario: Participants cannot search for already joined listed rooms + Given user "creator" creates room "group-room" + | roomType | 2 | + | roomName | group-room | + And user "creator" creates room "public-room" + | roomType | 3 | + | roomName | public-room | + And user "creator" allows listing room "group-room" for "users" with 200 + And user "creator" allows listing room "public-room" for "users" with 200 + When user "regular-user" joins room "group-room" with 200 + And user "regular-user" joins room "public-room" with 200 + Then user "regular-user" cannot find any listed rooms (v3) + + Scenario: Users can use search terms to find listed rooms + Given user "creator" creates room "group-room" + | roomType | 2 | + | roomName | group-room | + And user "creator" creates room "group-the-cool-room" + | roomType | 2 | + | roomName | group-the-cool-room | + And user "creator" creates room "public-room" + | roomType | 3 | + | roomName | public-room | + And user "creator" creates room "public-the-cool-room" + | roomType | 3 | + | roomName | public-the-cool-room | + When user "creator" allows listing room "group-room" for "all" with 200 + And user "creator" allows listing room "public-room" for "all" with 200 + And user "creator" allows listing room "group-the-cool-room" for "all" with 200 + And user "creator" allows listing room "public-the-cool-room" for "all" with 200 + Then user "regular-user" can find listed rooms with term "cool" (v3) + | name | listable | + | group-the-cool-room | 2 | + | public-the-cool-room | 2 | + And user "user-guest" can find listed rooms with term "cool" (v3) + | name | listable | + | group-the-cool-room | 2 | + | public-the-cool-room | 2 | + + Scenario: Searching for a listable room by unknown term returns no results + Given user "creator" creates room "group-room" + | roomType | 2 | + | roomName | group-room | + When user "creator" allows listing room "group-room" for "all" with 200 + Then user "regular-user" cannot find any listed rooms with term "cool" (v3) + And user "user-guest" cannot find any listed rooms with term "cool" (v3) + + Scenario: Guest users without accounts cannot search for listed rooms + Given user "creator" creates room "public-room" + | roomType | 3 | + | roomName | public-room | + And user "creator" creates room "public-room-listed" + | roomType | 3 | + | roomName | public-room-listed | + And user "creator" allows listing room "public-room-listed" for "all" with 200 + When user "guest" joins room "public-room" with 200 + Then user "guest" cannot find any listed rooms with 401 (v3) diff --git a/tests/integration/features/conversation/join-listable.feature b/tests/integration/features/conversation/join-listable.feature new file mode 100644 index 000000000..ac6ac5331 --- /dev/null +++ b/tests/integration/features/conversation/join-listable.feature @@ -0,0 +1,97 @@ +Feature: conversation/join-listable + Background: + Given user "creator" exists + And user "regular-user" exists + And guest accounts can be created + And user "user-guest" is a guest account user + # implicit: And user "guest" is a guest user with no account + + # ----------------------------------------------------------------------------- + # Non-listed rooms + # ----------------------------------------------------------------------------- + Scenario: Nobody can join a non-listed group room + Given user "creator" creates room "room" + | roomType | 2 | + | roomName | room | + When user "creator" allows listing room "room" for "none" with 200 + Then user "regular-user" joins room "room" with 404 + And user "user-guest" joins room "room" with 404 + And user "guest" joins room "room" with 404 + + Scenario: Anyone can join a non-listed public room + Given user "creator" creates room "room" + | roomType | 3 | + | roomName | room | + And user "creator" allows listing room "room" for "none" with 200 + When user "regular-user" joins room "room" with 200 + And user "user-guest" joins room "room" with 200 + And user "guest" joins room "room" with 200 + Then user "creator" sees the following attendees in room "room" with 200 (v3) + | actorId | participantType | actorType | + | creator | OWNER | users | + | regular-user | USER_SELF_JOINED | users | + | user-guest | USER_SELF_JOINED | users | + | "guest" | GUEST | guests | + + # ----------------------------------------------------------------------------- + # User-listed rooms + # ----------------------------------------------------------------------------- + Scenario: Only regular users can join a user-listed group room + Given user "creator" creates room "room" + | roomType | 2 | + | roomName | room | + And user "creator" allows listing room "room" for "users" with 200 + When user "regular-user" joins room "room" with 200 + And user "user-guest" joins room "room" with 404 + And user "guest" joins room "room" with 404 + Then user "creator" sees the following attendees in room "room" with 200 (v3) + | actorId | participantType | actorType | + | creator | OWNER | users | + | regular-user | USER | users | + + Scenario: Anyone can join a user-listed public room + Given user "creator" creates room "room" + | roomType | 3 | + | roomName | room | + And user "creator" allows listing room "room" for "users" with 200 + When user "regular-user" joins room "room" with 200 + And user "user-guest" joins room "room" with 200 + And user "guest" joins room "room" with 200 + Then user "creator" sees the following attendees in room "room" with 200 (v3) + | actorId | participantType | actorType | + | creator | OWNER | users | + | regular-user | USER | users | + | user-guest | USER_SELF_JOINED | users | + | "guest" | GUEST | guests | + + # ----------------------------------------------------------------------------- + # All-listed rooms + # ----------------------------------------------------------------------------- + Scenario: Only users with accounts can join an all-listed group room + Given user "creator" creates room "room" + | roomType | 2 | + | roomName | room | + And user "creator" allows listing room "room" for "all" with 200 + When user "regular-user" joins room "room" with 200 + And user "user-guest" joins room "room" with 200 + And user "guest" joins room "room" with 404 + Then user "creator" sees the following attendees in room "room" with 200 (v3) + | actorId | participantType | actorType | + | creator | OWNER | users | + | regular-user | USER | users | + | user-guest | USER | users | + + Scenario: Anyone can join an all-listed public room + Given user "creator" creates room "room" + | roomType | 3 | + | roomName | room | + And user "creator" allows listing room "room" for "all" with 200 + When user "regular-user" joins room "room" with 200 + And user "user-guest" joins room "room" with 200 + And user "guest" joins room "room" with 200 + Then user "creator" sees the following attendees in room "room" with 200 (v3) + | actorId | participantType | actorType | + | creator | OWNER | users | + | regular-user | USER | users | + | user-guest | USER | users | + | "guest" | GUEST | guests | diff --git a/tests/integration/features/conversation/set-listable.feature b/tests/integration/features/conversation/set-listable.feature new file mode 100644 index 000000000..a0b034517 --- /dev/null +++ b/tests/integration/features/conversation/set-listable.feature @@ -0,0 +1,57 @@ +Feature: conversation/set-listable + Background: + Given user "creator" exists + Given user "regular-user" exists + + Scenario Outline: Setting listable attribute + Given user "creator" creates room "room" + | roomType | 2 | + | roomName | room | + When user "creator" allows listing room "room" for "" with 200 + Then user "creator" is participant of the following rooms (v3) + | id | type | listable | + | room | 2 | | + Examples: + | listable | + | 0 | + | 1 | + | 2 | + + Scenario: Cannot set invalid listable attribute value + Given user "creator" creates room "room" + | roomType | 2 | + | roomName | room | + Then user "creator" allows listing room "room" for "5" with 400 + + Scenario: Only moderators and owners can change listable attribute + Given user "creator" creates room "room" + | roomType | 3 | + | roomName | room | + And user "moderator" exists + And guest accounts can be created + And user "user-guest" is a guest account user + And user "creator" adds "regular-user" to room "room" with 200 + And user "creator" adds "moderator" to room "room" with 200 + And user "creator" allows listing room "room" for "all" with 200 + When user "creator" promotes "moderator" in room "room" with 200 + And user "user-guest" joins room "room" with 200 + And user "guest" joins room "room" with 200 + Then user "moderator" allows listing room "room" for "none" with 200 + And user "regular-user" allows listing room "room" for "users" with 403 + And user "user-guest" allows listing room "room" for "users" with 403 + And user "guest" allows listing room "room" for "users" with 401 + + Scenario: Cannot change listable attribute of one to one conversations + Given user "creator" creates room "room" + | roomType | 1 | + | invite | regular-user | + Then user "creator" allows listing room "room" for "all" with 400 + And user "regular-user" allows listing room "room" for "all" with 400 + + Scenario: Cannot change listable attribute on a file conversation + Given user "creator" logs in + And user "creator" shares "welcome.txt" with user "regular-user" with OCS 100 + And user "regular-user" accepts last share + When user "creator" gets the room for path "welcome.txt" with 200 + And user "creator" joins room "file welcome.txt room" with 200 + Then user "creator" allows listing room "file welcome.txt room" for "all" with 403 diff --git a/tests/integration/spreedcheats/lib/Controller/ApiController.php b/tests/integration/spreedcheats/lib/Controller/ApiController.php index 745ba8ce2..8a1556126 100644 --- a/tests/integration/spreedcheats/lib/Controller/ApiController.php +++ b/tests/integration/spreedcheats/lib/Controller/ApiController.php @@ -29,6 +29,7 @@ use OCP\AppFramework\OCSController; use OCP\AppFramework\Http\DataResponse; use OCP\IDBConnection; use OCP\IRequest; +use OCP\IUserManager; use OCP\Share\IShare; class ApiController extends OCSController { @@ -36,11 +37,17 @@ class ApiController extends OCSController { /** @var IDBConnection */ private $db; + /** @var IUserManager */ + private $userManager; + public function __construct(string $appName, IRequest $request, - IDBConnection $db) { + IDBConnection $db, + IUserManager $userManager + ) { parent::__construct($appName, $request); $this->db = $db; + $this->userManager = $userManager; } /** @@ -80,8 +87,8 @@ class ApiController extends OCSController { * * @return DataResponse */ - public function createGuestAppUser($userid): DataResponse { - $guestAppContainer =\OC::$server->getRegisteredAppContainer('guests'); + public function createGuestAppUser(string $userid, string $password): DataResponse { + $guestAppContainer = \OC::$server->getRegisteredAppContainer('guests'); $guestManager = $guestAppContainer->query('\OCA\Guests\GuestManager'); $guestManager->createGuest( \OC::$server->getUserSession()->getUser(), @@ -90,6 +97,8 @@ class ApiController extends OCSController { $userid . '-displayname' ); + $this->userManager->get($userid)->setPassword($password); + return new DataResponse(); } } diff --git a/tests/php/Controller/SignalingControllerTest.php b/tests/php/Controller/SignalingControllerTest.php index 4f3644e14..2dc9453db 100644 --- a/tests/php/Controller/SignalingControllerTest.php +++ b/tests/php/Controller/SignalingControllerTest.php @@ -37,6 +37,7 @@ use OCA\Talk\Service\ParticipantService; use OCA\Talk\Service\SessionService; use OCA\Talk\Signaling\Messages; use OCA\Talk\TalkSession; +use OCP\App\IAppManager; use OCP\AppFramework\Utility\ITimeFactory; use OCP\EventDispatcher\IEventDispatcher; use OCP\Http\Client\IClientService; @@ -889,6 +890,7 @@ class SignalingControllerTest extends \Test\TestCase { $dbConnection, \OC::$server->getConfig(), $this->createMock(Config::class), + \OC::$server->get(IAppManager::class), \OC::$server->get(AttendeeMapper::class), \OC::$server->get(SessionMapper::class), $participantService, diff --git a/tests/php/Signaling/BackendNotifierTest.php b/tests/php/Signaling/BackendNotifierTest.php index bfc6e3d6e..57226b743 100644 --- a/tests/php/Signaling/BackendNotifierTest.php +++ b/tests/php/Signaling/BackendNotifierTest.php @@ -35,6 +35,7 @@ use OCA\Talk\Service\ParticipantService; use OCA\Talk\Signaling\BackendNotifier; use OCA\Talk\TalkSession; use OCA\Talk\Webinary; +use OCP\App\IAppManager; use OCP\AppFramework\Utility\ITimeFactory; use OCP\EventDispatcher\IEventDispatcher; use OCP\Http\Client\IClientService; @@ -141,6 +142,7 @@ class BackendNotifierTest extends \Test\TestCase { $dbConnection, $config, $this->config, + \OC::$server->get(IAppManager::class), \OC::$server->get(AttendeeMapper::class), \OC::$server->get(SessionMapper::class), $this->participantService, @@ -313,6 +315,7 @@ class BackendNotifierTest extends \Test\TestCase { 'lobby-state' => Webinary::LOBBY_NONE, 'lobby-timer' => null, 'read-only' => Room::READ_WRITE, + 'listable' => Room::LISTABLE_NONE, 'active-since' => null, 'sip-enabled' => 0, ], @@ -434,6 +437,7 @@ class BackendNotifierTest extends \Test\TestCase { 'listable' => Room::LISTABLE_ALL, 'active-since' => null, 'sip-enabled' => 0, + 'description' => '', ], ], ]); -- cgit v1.2.3