Browse Source

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>
pull/4706/head
Vincent Petry 5 years ago
parent
commit
6d75ad2b62
No known key found for this signature in database GPG Key ID: E055D6A4D513575C
  1. 2
      .drone.yml
  2. 2
      lib/Service/ParticipantService.php
  3. 36
      tests/integration/features/bootstrap/FeatureContext.php
  4. 97
      tests/integration/features/callapi/joining-listable-rooms.feature

2
.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

2
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())
)
)
) {

36
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);
}

97
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 |
Loading…
Cancel
Save