Skip to content

Commit bc421c8

Browse files
committed
Start with integration tests for invites
Signed-off-by: Joas Schilling <[email protected]>
1 parent 51a5b85 commit bc421c8

File tree

4 files changed

+44
-5
lines changed

4 files changed

+44
-5
lines changed

Diff for: lib/Controller/RoomController.php

+14-3
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
use OCP\User\Events\UserLiveStatusEvent;
6868
use OCP\UserStatus\IManager as IUserStatusManager;
6969
use OCP\UserStatus\IUserStatus;
70+
use Psr\Log\LoggerInterface;
7071

7172
class RoomController extends AEnvironmentAwareController {
7273
public const EVENT_BEFORE_ROOMS_GET = self::class . '::preGetRooms';
@@ -111,6 +112,8 @@ class RoomController extends AEnvironmentAwareController {
111112
protected $talkConfig;
112113
/** @var FederationManager */
113114
protected $federationManager;
115+
/** @var LoggerInterface */
116+
protected $logger;
114117

115118
/** @var array */
116119
protected $commonReadMessages = [];
@@ -135,7 +138,9 @@ public function __construct(string $appName,
135138
IL10N $l10n,
136139
IConfig $config,
137140
Config $talkConfig,
138-
ICloudIdManager $cloudIdManager) {
141+
ICloudIdManager $cloudIdManager,
142+
FederationManager $federationManager,
143+
LoggerInterface $logger) {
139144
parent::__construct($appName, $request);
140145
$this->session = $session;
141146
$this->appManager = $appManager;
@@ -156,6 +161,8 @@ public function __construct(string $appName,
156161
$this->config = $config;
157162
$this->talkConfig = $talkConfig;
158163
$this->cloudIdManager = $cloudIdManager;
164+
$this->federationManager = $federationManager;
165+
$this->logger = $logger;
159166
}
160167

161168
protected function getTalkHashHeader(): array {
@@ -1129,13 +1136,16 @@ public function addParticipantToRoom(string $newParticipant, string $source = 'u
11291136
$this->guestManager->sendEmailInvitation($this->room, $participant);
11301137

11311138
return new DataResponse($data);
1132-
} elseif ($source === 'remote') {
1139+
} elseif ($source === 'remotes') {
11331140
if (!$this->federationManager->isEnabled()) {
1134-
return new DataResponse([], Http::STATUS_BAD_REQUEST);
1141+
return new DataResponse([], Http::STATUS_NOT_IMPLEMENTED);
11351142
}
11361143
try {
11371144
$newUser = $this->cloudIdManager->resolveCloudId($newParticipant);
11381145
} catch (\InvalidArgumentException $e) {
1146+
$this->logger->error($e->getMessage(), [
1147+
'exception' => $e,
1148+
]);
11391149
return new DataResponse([], Http::STATUS_BAD_REQUEST);
11401150
}
11411151

@@ -1145,6 +1155,7 @@ public function addParticipantToRoom(string $newParticipant, string $source = 'u
11451155
'displayName' => $newUser->getDisplayId(),
11461156
];
11471157
} else {
1158+
$this->logger->error('Trying to add participant from unsupported source ' . $source);
11481159
return new DataResponse([], Http::STATUS_BAD_REQUEST);
11491160
}
11501161

Diff for: lib/Federation/FederationManager.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function __construct(
8888
*/
8989
public function isEnabled(): bool {
9090
// TODO: Set to default true once implementation is complete
91-
return $this->config->getAppValue(Application::APP_ID, 'federation_enabled', 'false') === 'true';
91+
return $this->config->getAppValue(Application::APP_ID, 'federation_enabled', 'no') === 'yes';
9292
}
9393

9494
/**

Diff for: tests/integration/features/bootstrap/FeatureContext.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,7 @@ public function userChangesListableScopeOfTheRoom(string $user, string $identifi
10691069
}
10701070

10711071
/**
1072-
* @Then /^user "([^"]*)" adds (user|group|email|circle) "([^"]*)" to room "([^"]*)" with (\d+) \((v4)\)$/
1072+
* @Then /^user "([^"]*)" adds (user|group|email|circle|remote) "([^"]*)" to room "([^"]*)" with (\d+) \((v4)\)$/
10731073
*
10741074
* @param string $user
10751075
* @param string $newType
@@ -1080,6 +1080,11 @@ public function userChangesListableScopeOfTheRoom(string $user, string $identifi
10801080
*/
10811081
public function userAddAttendeeToRoom(string $user, string $newType, string $newId, string $identifier, int $statusCode, string $apiVersion): void {
10821082
$this->setCurrentUser($user);
1083+
1084+
if ($newType === 'remote') {
1085+
$newId .= '@' . $this->baseUrl;
1086+
}
1087+
10831088
$this->sendRequest(
10841089
'POST', '/apps/spreed/api/' . $apiVersion . '/room/' . self::$identifierToToken[$identifier] . '/participants',
10851090
new TableNode([
@@ -2108,6 +2113,8 @@ public function sendRequest($verb, $url, $body = null, array $headers = []) {
21082113
$this->response = $client->{$verb}($fullUrl, $options);
21092114
} catch (ClientException $ex) {
21102115
$this->response = $ex->getResponse();
2116+
} catch (\GuzzleHttp\Exception\ServerException $ex) {
2117+
$this->response = $ex->getResponse();
21112118
}
21122119
}
21132120

Diff for: tests/integration/features/federation/invite.feature

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Feature: federation/invite
2+
Background:
3+
Given user "participant1" exists
4+
Given user "participant2" exists
5+
6+
Scenario: federation is disabled
7+
Given the following app config is set
8+
| federation_enabled | no |
9+
Given user "participant1" creates room "room" (v4)
10+
| roomType | 3 |
11+
| roomName | room |
12+
And user "participant1" adds remote "participant2" to room "room" with 501 (v4)
13+
14+
15+
Scenario: federation is enabled
16+
Given the following app config is set
17+
| federation_enabled | yes |
18+
Given user "participant1" creates room "room" (v4)
19+
| roomType | 3 |
20+
| roomName | room |
21+
And user "participant1" adds remote "participant2" to room "room" with 200 (v4)

0 commit comments

Comments
 (0)