Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(federation): Add test for avatar federation #11784

Merged
merged 2 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/Controller/FederationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,10 @@ public function acceptShare(int $id): DataResponse {
*
* @param int $id ID of the share
* @psalm-param non-negative-int $id
* @return DataResponse<Http::STATUS_OK, array<empty>, array{}>|DataResponse<Http::STATUS_NOT_FOUND, array{error?: string}, array{}>
* @return DataResponse<Http::STATUS_OK, array<empty>, array{}>|DataResponse<Http::STATUS_NOT_FOUND|Http::STATUS_BAD_REQUEST, array{error?: string}, array{}>
*
* 200: Invite declined successfully
* 400: Invite was already accepted, use the "Remove the current user from a room" endpoint instead
* 404: Invite can not be found
*/
#[NoAdminRequired]
Expand All @@ -146,7 +147,7 @@ public function rejectShare(int $id): DataResponse {
} catch (UnauthorizedException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
} catch (\InvalidArgumentException $e) {
return new DataResponse(['error' => $e->getMessage()], Http::STATUS_NOT_FOUND);
return new DataResponse(['error' => $e->getMessage()], $e->getMessage() === 'invitation' ? Http::STATUS_NOT_FOUND : Http::STATUS_BAD_REQUEST);
}
return new DataResponse();
}
Expand Down
5 changes: 5 additions & 0 deletions lib/Federation/FederationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ public function rejectRemoteRoomShare(IUser $user, int $shareId): void {
} catch (DoesNotExistException $e) {
throw new \InvalidArgumentException('invitation');
}

if ($invitation->getState() !== Invitation::STATE_PENDING) {
throw new \InvalidArgumentException('state');
}

if ($invitation->getUserId() !== $user->getUID()) {
throw new UnauthorizedException('user');
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Middleware/InjectionMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,13 @@ protected function getRoomByInvite(AEnvironmentAwareController $controller): voi
if (!$room instanceof Room) {
$token = $this->request->getParam('token');
$room = $this->manager->getRoomByToken($token);
$controller->setRoom($room);
}

$participant = $controller->getParticipant();
if (!$participant instanceof Participant) {
try {
$invitation = $this->invitationMapper->getInvitationsForUserByLocalRoom($room, $this->userId);
$controller->setRoom($room);
$controller->setInvitation($invitation);
} catch (DoesNotExistException $e) {
throw new ParticipantNotFoundException('No invite available', $e->getCode(), $e);
Expand Down
35 changes: 35 additions & 0 deletions openapi-federation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,41 @@
}
}
}
},
"400": {
"description": "Invite was already accepted, use the \"Remove the current user from a room\" endpoint instead",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"ocs"
],
"properties": {
"ocs": {
"type": "object",
"required": [
"meta",
"data"
],
"properties": {
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {
"type": "object",
"properties": {
"error": {
"type": "string"
}
}
}
}
}
}
}
}
}
}
}
}
Expand Down
35 changes: 35 additions & 0 deletions openapi-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -16631,6 +16631,41 @@
}
}
}
},
"400": {
"description": "Invite was already accepted, use the \"Remove the current user from a room\" endpoint instead",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"ocs"
],
"properties": {
"ocs": {
"type": "object",
"required": [
"meta",
"data"
],
"properties": {
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {
"type": "object",
"properties": {
"error": {
"type": "string"
}
}
}
}
}
}
}
}
}
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/types/openapi/openapi-federation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,19 @@ export type operations = {
};
};
};
/** @description Invite was already accepted, use the "Remove the current user from a room" endpoint instead */
400: {
content: {
"application/json": {
ocs: {
meta: components["schemas"]["OCSMeta"];
data: {
error?: string;
};
};
};
};
};
/** @description Invite can not be found */
404: {
content: {
Expand Down
13 changes: 13 additions & 0 deletions src/types/openapi/openapi-full.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5665,6 +5665,19 @@ export type operations = {
};
};
};
/** @description Invite was already accepted, use the "Remove the current user from a room" endpoint instead */
400: {
content: {
"application/json": {
ocs: {
meta: components["schemas"]["OCSMeta"];
data: {
error?: string;
};
};
};
};
};
/** @description Invite can not be found */
404: {
content: {
Expand Down
1 change: 1 addition & 0 deletions tests/integration/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ public function userHasInvites(string $user, string $apiVersion, TableNode $form
foreach ($invites as $data) {
self::$remoteToInviteId[$this->translateRemoteServer($data['remoteServerUrl']) . '::' . self::$tokenToIdentifier[$data['remoteToken']]] = $data['id'];
self::$inviteIdToRemote[$data['id']] = $this->translateRemoteServer($data['remoteServerUrl']) . '::' . self::$tokenToIdentifier[$data['remoteToken']];
self::$identifierToToken['LOCAL::' . $data['roomName']] = $data['localToken'];
}
}

Expand Down
25 changes: 25 additions & 0 deletions tests/integration/features/federation/invite.feature
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ Feature: federation/invite
| room | room | 3 | LOCAL | room |
And user "participant2" accepts invite to room "room" of server "LOCAL" with 400 (v1)
| error | state |
And user "participant2" declines invite to room "room" of server "LOCAL" with 400 (v1)
| error | state |
And user "participant2" has the following invitations (v1)
| remoteServerUrl | remoteToken | state | inviterCloudId | inviterDisplayName |
| LOCAL | room | 1 | participant1@http://localhost:8080 | participant1-displayname |
Expand Down Expand Up @@ -227,3 +229,26 @@ Feature: federation/invite
Then user "participant2" is participant of the following rooms (v4)
| id | name | type |
| room | Federated room | 2 |

Scenario: Allow accessing conversation and room avatars for invited users
Given the following "spreed" app config is set
| federation_enabled | yes |
Given user "participant1" creates room "room" (v4)
| roomType | 2 |
| roomName | room |
And user "participant1" adds federated_user "participant2" to room "room" with 200 (v4)
And user "participant2" has the following invitations (v1)
| remoteServerUrl | remoteToken | state | inviterCloudId | inviterDisplayName |
| LOCAL | room | 0 | participant1@http://localhost:8080 | participant1-displayname |
When as user "participant2"
Then the room "LOCAL::room" has an avatar with 200
And user "participant2" accepts invite to room "room" of server "LOCAL" with 200 (v1)
| id | name | type | remoteServer | remoteToken |
| room | room | 2 | LOCAL | room |
When as user "participant2"
Then the room "LOCAL::room" has an avatar with 200
And user "participant2" removes themselves from room "LOCAL::room" with 200 (v4)
And user "participant2" has the following invitations (v1)
| remoteServerUrl | remoteToken | state | inviterCloudId | inviterDisplayName |
When as user "participant2"
Then the room "LOCAL::room" has an avatar with 404
Loading