summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Petry <vincent@nextcloud.com>2020-12-07 18:10:39 +0100
committerVincent Petry <vincent@nextcloud.com>2020-12-11 18:15:51 +0100
commit6d75ad2b62a9f99b845596544c022b45e199a3fe (patch)
tree0ca0841cbf3b849442b9b19d0f472ac11e42ab6a
parent52b88a9c16b66131e8e87721bcceacd7395a99d5 (diff)
Added integration tests for joining listable rooms
Added guest app to CI for callapi tests. Added test scenarios for joining listable rooms. Signed-off-by: Vincent Petry <vincent@nextcloud.com>
-rw-r--r--.drone.yml2
-rw-r--r--lib/Service/ParticipantService.php2
-rw-r--r--tests/integration/features/bootstrap/FeatureContext.php36
-rw-r--r--tests/integration/features/callapi/joining-listable-rooms.feature97
4 files changed, 129 insertions, 8 deletions
diff --git a/.drone.yml b/.drone.yml
index f2535429e..371d7a0db 100644
--- a/.drone.yml
+++ b/.drone.yml
@@ -273,12 +273,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/lib/Service/ParticipantService.php b/lib/Service/ParticipantService.php
index 76ad96b08..042f98795 100644
--- a/lib/Service/ParticipantService.php
+++ b/lib/Service/ParticipantService.php
@@ -178,7 +178,7 @@ class ParticipantService {
$room->getListable() === Room::LISTABLE_ALL || (
$room->getListable() === Room::LISTABLE_USERS &&
// queried here to avoid loop deps
- !\OC::$server->query(\OC\Talk\Manager::class)->isGuestUser($user->getUID())
+ !\OC::$server->query(\OCA\Talk\Manager::class)->isGuestUser($user->getUID())
)
)
) {
diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php
index 03c6cc171..bf1e22965 100644
--- a/tests/integration/features/bootstrap/FeatureContext.php
+++ b/tests/integration/features/bootstrap/FeatureContext.php
@@ -30,7 +30,6 @@ use GuzzleHttp\Cookie\CookieJar;
use GuzzleHttp\Exception\ClientException;
use PHPUnit\Framework\Assert;
use Psr\Http\Message\ResponseInterface;
-use OCA\Talk\Room;
/**
* Defines application features from the specific context.
@@ -316,13 +315,16 @@ class FeatureContext implements Context, SnippetAcceptingContext {
if (isset($attendee['actorId']) && substr($attendee['actorId'], 0, strlen('"guest')) === '"guest') {
$attendee['actorId'] = sha1(self::$userToSessionId[trim($attendee['actorId'], '"')]);
}
+ if (isset($attendee['participantType'])) {
+ $attendee['participantType'] = (string)$this->mapParticipantTypeTestInput($attendee['participantType']);
+ }
return $attendee;
}, $formData->getHash());
usort($expected, [$this, 'sortAttendees']);
usort($result, [$this, 'sortAttendees']);
- Assert::assertEquals($result, $expected);
+ Assert::assertEquals($expected, $result);
} else {
Assert::assertNull($formData);
}
@@ -338,6 +340,23 @@ class FeatureContext implements Context, SnippetAcceptingContext {
return $a1['actorId'] <=> $a2['actorId'];
}
+ private function mapParticipantTypeTestInput($participantType) {
+ if (is_int($participantType)) {
+ return $participantType;
+ }
+
+ switch ($participantType) {
+ case 'OWNER': return 1;
+ case 'MODERATOR': return 2;
+ case 'USER': return 3;
+ case 'GUEST': return 4;
+ case 'USER_SELF_JOINED': return 5;
+ case 'GUEST_MODERATOR': return 6;
+ }
+
+ Assert::fail('Invalid test input value for participant type');
+ }
+
/**
* @param string $guest
* @param string $isOrNotParticipant
@@ -809,16 +828,18 @@ class FeatureContext implements Context, SnippetAcceptingContext {
public function userChangesListableScopeOfTheRoom($user, $identifier, $newState, $statusCode, $apiVersion = 'v3') {
$this->setCurrentUser($user);
if ($newState === 'none') {
- $newStateValue = Room::LISTABLE_NONE;
+ $newStateValue = 0; // Room::LISTABLE_NONE
} elseif ($newState === 'users') {
- $newStateValue = Room::LISTABLE_USERS;
+ $newStateValue = 1; // Room::LISTABLE_USERS
+ } elseif ($newState === 'all') {
+ $newStateValue = 2; // Room::LISTABLE_ALL
} else {
- $newStateValue = Room::LISTABLE_ALL;
+ Assert::fail('Invalid listable scope value');
}
$this->sendRequest(
'PUT', '/apps/spreed/api/' . $apiVersion . '/room/' . self::$identifierToToken[$identifier] . '/listable',
- new TableNode([['state', $newStateValue]])
+ new TableNode([['scope', $newStateValue]])
);
$this->assertStatusCode($this->response, $statusCode);
}
@@ -1511,9 +1532,10 @@ class FeatureContext implements Context, SnippetAcceptingContext {
public function addingUserToGroup($user, $group) {
$currentUser = $this->currentUser;
$this->setCurrentUser('admin');
- $this->response = $this->sendRequest('POST', "/cloud/users/$user/groups", [
+ $this->sendRequest('POST', "/cloud/users/$user/groups", [
'groupid' => $group,
]);
+ $this->assertStatusCode($this->response, 200);
$this->setCurrentUser($currentUser);
}
diff --git a/tests/integration/features/callapi/joining-listable-rooms.feature b/tests/integration/features/callapi/joining-listable-rooms.feature
new file mode 100644
index 000000000..de890b929
--- /dev/null
+++ b/tests/integration/features/callapi/joining-listable-rooms.feature
@@ -0,0 +1,97 @@
+Feature: callapi/listable-rooms
+ Background:
+ Given user "creator" exists
+ And user "regular-user" exists
+ And user "user-guest" exists
+ And user "user-guest" is member of group "guest_app"
+ # 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 |