summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Petry <vincent@nextcloud.com>2020-12-09 10:26:20 +0100
committerVincent Petry <vincent@nextcloud.com>2020-12-11 18:15:52 +0100
commit10840fd4c021f8b5fe750f3caf37afe4ebc19cf9 (patch)
treef3b86d6e833ab3a57b772508c855b7af5c238876
parentbcc9f8fdb5da031a36d76772d8000c8dee47bc58 (diff)
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 <vincent@nextcloud.com>
-rw-r--r--.drone.yml4
-rw-r--r--tests/integration/features/bootstrap/FeatureContext.php164
-rw-r--r--tests/integration/features/chat/system-messages.feature60
-rw-r--r--tests/integration/features/conversation/find-listed.feature126
-rw-r--r--tests/integration/features/conversation/join-listable.feature (renamed from tests/integration/features/callapi/joining-listable-rooms.feature)5
-rw-r--r--tests/integration/features/conversation/set-listable.feature57
-rw-r--r--tests/integration/spreedcheats/lib/Controller/ApiController.php15
-rw-r--r--tests/php/Controller/SignalingControllerTest.php2
-rw-r--r--tests/php/Signaling/BackendNotifierTest.php4
9 files changed, 424 insertions, 13 deletions
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;
}
/**
@@ -131,6 +139,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))\))?$/
*
* @param string $user
@@ -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');
}
@@ -1383,6 +1465,44 @@ class FeatureContext implements Context, SnippetAcceptingContext {
}
/**
+ * @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/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/callapi/joining-listable-rooms.feature b/tests/integration/features/conversation/join-listable.feature
index 0086ffbd4..ac6ac5331 100644
--- a/tests/integration/features/callapi/joining-listable-rooms.feature
+++ b/tests/integration/features/conversation/join-listable.feature
@@ -1,7 +1,8 @@
-Feature: callapi/listable-rooms
+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
@@ -78,7 +79,7 @@ Feature: callapi/listable-rooms
| actorId | participantType | actorType |
| creator | OWNER | users |
| regular-user | USER | users |
- | user-guest | USER_SELF_JOINED | users |
+ | user-guest | USER | users |
Scenario: Anyone can join an all-listed public room
Given user "creator" creates room "room"
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