diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/integration/features/bootstrap/FeatureContext.php | 74 | ||||
-rw-r--r-- | tests/integration/features/federation/invite.feature | 54 | ||||
-rwxr-xr-x | tests/integration/run.sh | 21 | ||||
-rw-r--r-- | tests/php/Chat/Parser/SystemMessageTest.php | 6 | ||||
-rw-r--r-- | tests/php/Federation/FederationTest.php | 10 | ||||
-rw-r--r-- | tests/php/Notification/NotifierTest.php | 17 |
6 files changed, 154 insertions, 28 deletions
diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php index 6e741187f..ca7e67874 100644 --- a/tests/integration/features/bootstrap/FeatureContext.php +++ b/tests/integration/features/bootstrap/FeatureContext.php @@ -52,6 +52,10 @@ class FeatureContext implements Context, SnippetAcceptingContext { protected static $textToMessageId; /** @var array[] */ protected static $messageIdToText; + /** @var int[] */ + protected static $remoteToInviteId; + /** @var string[] */ + protected static $inviteIdToRemote; protected static $permissionsMap = [ @@ -360,6 +364,32 @@ class FeatureContext implements Context, SnippetAcceptingContext { } $this->assertInvites($invites, $formData); + + foreach ($invites as $data) { + self::$remoteToInviteId[$this->translateRemoteServer($data['remote_server']) . '::' . self::$tokenToIdentifier[$data['remote_token']]] = $data['id']; + self::$inviteIdToRemote[$data['id']] = $this->translateRemoteServer($data['remote_server']) . '::' . self::$tokenToIdentifier[$data['remote_token']]; + } + } + + /** + * @Then /^user "([^"]*)" (accepts|declines) invite to room "([^"]*)" of server "([^"]*)" \((v1)\)$/ + * + * @param string $user + * @param string $roomName + * @param string $server + * @param string $apiVersion + * @param TableNode|null $formData + */ + public function userAcceptsDeclinesRemoteInvite(string $user, string $acceptsDeclines, string $roomName, string $server, string $apiVersion, TableNode $formData = null): void { + $inviteId = self::$remoteToInviteId[$server . '::' . $roomName]; + + $verb = $acceptsDeclines === 'accepts' ? 'POST' : 'DELETE'; + + $this->setCurrentUser($user); + if ($server === 'LOCAL') { + $this->sendRemoteRequest($verb, '/apps/spreed/api/' . $apiVersion . '/federation/invitation/' . $inviteId); + } + $this->assertStatusCode($this->response, 200); } /** @@ -380,19 +410,24 @@ class FeatureContext implements Context, SnippetAcceptingContext { $data['remote_token'] = self::$tokenToIdentifier[$invite['remote_token']] ?? 'unknown-token'; } if (isset($expectedInvite['remote_server'])) { - if ($invite['remote_server'] === 'localhost:8080') { - $data['remote_server'] = 'LOCAL'; - } elseif ($invite['remote_server'] === 'localhost:8180') { - $data['remote_server'] = 'REMOTE'; - } else { - $data['remote_server'] = 'unknown-server'; - } + $data['remote_server'] = $this->translateRemoteServer($invite['remote_server']); } return $data; }, $invites, $formData->getHash())); } + protected function translateRemoteServer(string $server): string { + $server = str_replace('http://', '', $server); + if ($server === 'localhost:8080') { + return 'LOCAL'; + } + if ($server === 'localhost:8180') { + return 'REMOTE'; + } + return 'unknown-server'; + } + /** * @Then /^user "([^"]*)" (is|is not) participant of room "([^"]*)" \((v4)\)$/ * @@ -1783,7 +1818,7 @@ class FeatureContext implements Context, SnippetAcceptingContext { $data = [ 'room' => self::$tokenToIdentifier[$message['token']], 'actorType' => (string) $message['actorType'], - 'actorId' => ($message['actorType'] === 'guests') ? self::$sessionIdToUser[$message['actorId']]: (string) $message['actorId'], + 'actorId' => ($message['actorType'] === 'guests') ? self::$sessionIdToUser[$message['actorId']] : (string) $message['actorId'], 'systemMessage' => (string) $message['systemMessage'], ]; @@ -2006,6 +2041,8 @@ class FeatureContext implements Context, SnippetAcceptingContext { if (strpos($notification['object_id'], '/') !== false) { [$roomToken, $message] = explode('/', $notification['object_id']); $data['object_id'] = self::$tokenToIdentifier[$roomToken] . '/' . self::$messageIdToText[$message] ?? 'UNKNOWN_MESSAGE'; + } elseif (strpos($expectedNotification['object_id'], 'INVITE_ID') !== false) { + $data['object_id'] = 'INVITE_ID(' . self::$inviteIdToRemote[$notification['object_id']] . ')'; } else { [$roomToken,] = explode('/', $notification['object_id']); $data['object_id'] = self::$tokenToIdentifier[$roomToken]; @@ -2414,6 +2451,27 @@ class FeatureContext implements Context, SnippetAcceptingContext { */ public function sendRequest($verb, $url, $body = null, array $headers = []) { $fullUrl = $this->baseUrl . 'ocs/v2.php' . $url; + $this->sendRequestFullUrl($verb, $fullUrl, $body, $headers); + } + + /** + * @param string $verb + * @param string $url + * @param TableNode|array|null $body + * @param array $headers + */ + public function sendRemoteRequest($verb, $url, $body = null, array $headers = []) { + $fullUrl = $this->baseRemoteUrl . 'ocs/v2.php' . $url; + $this->sendRequestFullUrl($verb, $fullUrl, $body, $headers); + } + + /** + * @param string $verb + * @param string $fullUrl + * @param TableNode|array|null $body + * @param array $headers + */ + public function sendRequestFullUrl($verb, $fullUrl, $body = null, array $headers = []) { $client = new Client(); $options = ['cookies' => $this->getUserCookieJar($this->currentUser)]; if ($this->currentUser === 'admin') { diff --git a/tests/integration/features/federation/invite.feature b/tests/integration/features/federation/invite.feature index 26f93e6bb..1ea48f739 100644 --- a/tests/integration/features/federation/invite.feature +++ b/tests/integration/features/federation/invite.feature @@ -3,7 +3,7 @@ Feature: federation/invite Given user "participant1" exists Given user "participant2" exists - Scenario: federation is disabled + Scenario: Federation is disabled Given the following "spreed" app config is set | federation_enabled | no | Given user "participant1" creates room "room" (v4) @@ -14,7 +14,7 @@ Feature: federation/invite | actorType | actorId | participantType | | users | participant1 | 1 | - Scenario: federation is enabled + Scenario: Accepting an invite Given the following "spreed" app config is set | federation_enabled | yes | Given user "participant1" creates room "room" (v4) @@ -25,6 +25,56 @@ Feature: federation/invite | actorType | actorId | participantType | | users | participant1 | 1 | | federated_users | participant2 | 3 | + Then user "participant1" sees the following system messages in room "room" with 200 + | room | actorType | actorId | systemMessage | message | messageParameters | + | room | users | participant1 | federated_user_added | You invited {user} | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"},"federated_user":{"type":"user","id":"participant2","name":"participant2@localhost:8180","server":"http:\/\/localhost:8180"}} | + | room | users | participant1 | conversation_created | You created the conversation | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"}} | And user "participant2" has the following invitations (v1) | remote_server | remote_token | | LOCAL | room | + Then user "participant2" has the following notifications + | app | object_type | object_id | subject | + | spreed | remote_talk_share | INVITE_ID(LOCAL::room) | @participant1-displayname shared room room on http://localhost:8080 with you | + And user "participant2" accepts invite to room "room" of server "LOCAL" (v1) + And user "participant2" has the following invitations (v1) + When user "participant1" sees the following attendees in room "room" with 200 (v4) + | actorType | actorId | participantType | + | users | participant1 | 1 | + | federated_users | participant2 | 3 | + Then user "participant1" sees the following system messages in room "room" with 200 + | room | actorType | actorId | systemMessage | message | messageParameters | + | room | federated_users | participant2@http://localhost:8180 | federated_user_added | {federated_user} accepted the invitation | {"actor":{"type":"user","id":"participant2","name":"participant2@localhost:8180","server":"http:\/\/localhost:8180"},"federated_user":{"type":"user","id":"participant2","name":"participant2@localhost:8180","server":"http:\/\/localhost:8180"}} | + | room | users | participant1 | federated_user_added | You invited {user} | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"},"federated_user":{"type":"user","id":"participant2","name":"participant2@localhost:8180","server":"http:\/\/localhost:8180"}} | + | room | users | participant1 | conversation_created | You created the conversation | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"}} | + + Scenario: Declining an invite + Given the following "spreed" app config is set + | federation_enabled | yes | + Given user "participant1" creates room "room" (v4) + | roomType | 3 | + | roomName | room | + And user "participant1" adds remote "participant2" to room "room" with 200 (v4) + When user "participant1" sees the following attendees in room "room" with 200 (v4) + | actorType | actorId | participantType | + | users | participant1 | 1 | + | federated_users | participant2 | 3 | + Then user "participant1" sees the following system messages in room "room" with 200 + | room | actorType | actorId | systemMessage | message | messageParameters | + | room | users | participant1 | federated_user_added | You invited {user} | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"},"federated_user":{"type":"user","id":"participant2","name":"participant2@localhost:8180","server":"http:\/\/localhost:8180"}} | + | room | users | participant1 | conversation_created | You created the conversation | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"}} | + And user "participant2" has the following invitations (v1) + | remote_server | remote_token | + | LOCAL | room | + Then user "participant2" has the following notifications + | app | object_type | object_id | subject | + | spreed | remote_talk_share | INVITE_ID(LOCAL::room) | @participant1-displayname shared room room on http://localhost:8080 with you | + And user "participant2" declines invite to room "room" of server "LOCAL" (v1) + And user "participant2" has the following invitations (v1) + When user "participant1" sees the following attendees in room "room" with 200 (v4) + | actorType | actorId | participantType | + | users | participant1 | 1 | + Then user "participant1" sees the following system messages in room "room" with 200 + | room | actorType | actorId | systemMessage | message | messageParameters | + | room | federated_users | participant2@http://localhost:8180 | federated_user_removed | {federated_user} declined the invitation | {"actor":{"type":"user","id":"participant2","name":"participant2@localhost:8180","server":"http:\/\/localhost:8180"},"federated_user":{"type":"user","id":"participant2","name":"participant2@localhost:8180","server":"http:\/\/localhost:8180"}} | + | room | users | participant1 | federated_user_added | You invited {user} | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"},"federated_user":{"type":"user","id":"participant2","name":"participant2@localhost:8180","server":"http:\/\/localhost:8180"}} | + | room | users | participant1 | conversation_created | You created the conversation | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"}} | diff --git a/tests/integration/run.sh b/tests/integration/run.sh index ce3ebd25e..832032ba3 100755 --- a/tests/integration/run.sh +++ b/tests/integration/run.sh @@ -17,16 +17,25 @@ echo '#' echo '# Starting PHP webserver' echo '#' php -S localhost:8080 -t ${ROOT_DIR} & -PHPPID=$! +PHPPID1=$! echo 'Running on process ID:' -echo $PHPPID +echo $PHPPID1 # also kill php process in case of ctrl+c -trap 'kill -TERM $PHPPID; wait $PHPPID' TERM +trap 'kill -TERM $PHPPID1; wait $PHPPID1' TERM # The federated server is started and stopped by the tests themselves PORT_FED=8180 export PORT_FED + +php -S localhost:${PORT_FED} -t ${ROOT_DIR} & +PHPPID2=$! +echo 'Running on process ID:' +echo $PHPPID2 + +# also kill php process in case of ctrl+c +trap 'kill -TERM $PHPPID2; wait $PHPPID2' TERM + NEXTCLOUD_ROOT_DIR=${ROOT_DIR} export NEXTCLOUD_ROOT_DIR export TEST_SERVER_URL="http://localhost:8080/" @@ -74,11 +83,13 @@ echo '' echo '#' echo '# Stopping PHP webserver and disabling spreedcheats' echo '#' -kill $PHPPID +kill $PHPPID1 +kill $PHPPID2 ${ROOT_DIR}/occ app:disable spreedcheats rm -rf ../../../spreedcheats -wait $PHPPID +wait $PHPPID1 +wait $PHPPID2 exit $RESULT diff --git a/tests/php/Chat/Parser/SystemMessageTest.php b/tests/php/Chat/Parser/SystemMessageTest.php index 1fcf409e0..ad9daae63 100644 --- a/tests/php/Chat/Parser/SystemMessageTest.php +++ b/tests/php/Chat/Parser/SystemMessageTest.php @@ -33,6 +33,7 @@ use OCA\Talk\Participant; use OCA\Talk\Room; use OCA\Talk\Share\RoomShareProvider; use OCP\Comments\IComment; +use OCP\Federation\ICloudIdManager; use OCP\Files\Folder; use OCP\Files\InvalidPathException; use OCP\Files\IRootFolder; @@ -71,6 +72,8 @@ class SystemMessageTest extends TestCase { protected $rootFolder; /** @var IURLGenerator|MockObject */ protected $url; + /** @var ICloudIdManager|MockObject */ + protected $cloudIdManager; /** @var IL10N|MockObject */ protected $l; @@ -85,6 +88,7 @@ class SystemMessageTest extends TestCase { $this->photoCache = $this->createMock(PhotoCache::class); $this->rootFolder = $this->createMock(IRootFolder::class); $this->url = $this->createMock(IURLGenerator::class); + $this->cloudIdManager = $this->createMock(ICloudIdManager::class); $this->l = $this->createMock(IL10N::class); $this->l->expects($this->any()) ->method('t') @@ -114,6 +118,7 @@ class SystemMessageTest extends TestCase { $this->shareProvider, $this->photoCache, $this->rootFolder, + $this->cloudIdManager, $this->url, ]) ->onlyMethods($methods) @@ -129,6 +134,7 @@ class SystemMessageTest extends TestCase { $this->shareProvider, $this->photoCache, $this->rootFolder, + $this->cloudIdManager, $this->url ); } diff --git a/tests/php/Federation/FederationTest.php b/tests/php/Federation/FederationTest.php index 8bb7bd13d..0b6b6d147 100644 --- a/tests/php/Federation/FederationTest.php +++ b/tests/php/Federation/FederationTest.php @@ -34,10 +34,12 @@ use OCA\Talk\Model\AttendeeMapper; use OCA\Talk\Room; use OCA\Talk\Service\ParticipantService; use OCP\BackgroundJob\IJobList; +use OCP\EventDispatcher\IEventDispatcher; use OCP\Federation\ICloudFederationFactory; use OCP\Federation\ICloudFederationNotification; use OCP\Federation\ICloudFederationProviderManager; use OCP\Federation\ICloudFederationShare; +use OCP\ISession; use OCP\IURLGenerator; use OCP\IUser; use OCP\IUserManager; @@ -84,11 +86,12 @@ class FederationTest extends TestCase { $this->userManager = $this->createMock(IUserManager::class); $this->attendeeMapper = $this->createMock(AttendeeMapper::class); $this->config = $this->createMock(Config::class); + $this->logger = $this->createMock(LoggerInterface::class); $this->notifications = new Notifications( $this->cloudFederationFactory, $this->addressHandler, - $this->createMock(LoggerInterface::class), + $this->logger, $this->cloudFederationProviderManager, $this->createMock(IJobList::class), $this->userManager, @@ -106,7 +109,10 @@ class FederationTest extends TestCase { $this->createMock(IURLGenerator::class), $this->createMock(ParticipantService::class), $this->attendeeMapper, - $this->createMock(Manager::class) + $this->createMock(Manager::class), + $this->createMock(ISession::class), + $this->createMock(IEventDispatcher::class), + $this->logger ); } diff --git a/tests/php/Notification/NotifierTest.php b/tests/php/Notification/NotifierTest.php index 7148f6e6f..2192b3de9 100644 --- a/tests/php/Notification/NotifierTest.php +++ b/tests/php/Notification/NotifierTest.php @@ -212,8 +212,7 @@ class NotifierTest extends TestCase { $n->expects($this->once()) ->method('getSubjectParameters') ->willReturn([$uid]); - $n->expects($this->exactly(2)) - ->method('getObjectType') + $n->method('getObjectType') ->willReturn('room'); $n->method('getObjectId') ->willReturn('roomToken'); @@ -329,8 +328,7 @@ class NotifierTest extends TestCase { $n->expects($this->once()) ->method('getSubjectParameters') ->willReturn([$uid]); - $n->expects($this->exactly(2)) - ->method('getObjectType') + $n->method('getObjectType') ->willReturn('room'); $n->method('getObjectId') ->willReturn('roomToken'); @@ -461,8 +459,7 @@ class NotifierTest extends TestCase { $n->expects($this->once()) ->method('getSubjectParameters') ->willReturn([$uid]); - $n->expects($this->exactly(2)) - ->method('getObjectType') + $n->method('getObjectType') ->willReturn('room'); $n->method('getObjectId') ->willReturn('roomToken'); @@ -1022,8 +1019,7 @@ class NotifierTest extends TestCase { $notification->expects($this->once()) ->method('getSubjectParameters') ->willReturn($subjectParameters); - $notification->expects($this->exactly(2)) - ->method('getObjectType') + $notification->method('getObjectType') ->willReturn('chat'); $notification->method('getObjectId') ->willReturn('roomToken'); @@ -1144,11 +1140,10 @@ class NotifierTest extends TestCase { $n->expects($this->never()) ->method('getObjectType'); } elseif ($objectType === null && $app === 'spreed') { - $n->expects($this->once()) - ->method('getObjectType') + $n->method('getObjectType') ->willReturn(''); } else { - $n->expects($this->exactly(2)) + $n->expects($this->any()) ->method('getObjectType') ->willReturn($objectType); } |