|
1 | | -import type { ISubscription, IUser } from '@rocket.chat/core-typings'; |
| 1 | +import type { IUser } from '@rocket.chat/core-typings'; |
2 | 2 |
|
3 | 3 | import type {} from '../../../../../apps/meteor/app/api/server/v1/permissions.ts'; |
4 | 4 | import { api } from '../../../../../apps/meteor/tests/data/api-data'; |
@@ -101,7 +101,7 @@ import { SynapseClient } from '../helper/synapse-client'; |
101 | 101 | matrixRoomId = await hs1AdminApp.createRoom(channelName); |
102 | 102 | }); |
103 | 103 |
|
104 | | - it('should throw an error if a user without access-federation permission tries to invite a user to a room', async () => { |
| 104 | + it('should throw an error if a remote user tries to invite a user without access-federation permission to a room', async () => { |
105 | 105 | await expect(hs1AdminApp.matrixClient.invite(matrixRoomId, `@${user.username}:${federationConfig.rc1.url}`)).rejects.toThrow(); |
106 | 106 | const subscriptions = await getSubscriptions(rc1AdminRequestConfig); |
107 | 107 | const invitedSub = subscriptions.update.find((sub) => sub.fname?.includes(channelName)); |
@@ -139,33 +139,70 @@ import { SynapseClient } from '../helper/synapse-client'; |
139 | 139 | expect(createResponse.body).toHaveProperty('errorType', 'error-not-authorized-federation'); |
140 | 140 | }); |
141 | 141 |
|
142 | | - it('should not be able to add a user without access-federation permission to a room', async () => { |
143 | | - const createResponse = await createRoom({ |
144 | | - type: 'p', |
145 | | - name: `federated-room-${Date.now()}`, |
146 | | - members: [], |
147 | | - extraData: { |
148 | | - federated: true, |
149 | | - }, |
150 | | - config: rc1AdminRequestConfig, |
| 142 | + describe('Inviting from a local server', () => { |
| 143 | + let channelName: string; |
| 144 | + |
| 145 | + let createResponse; |
| 146 | + let addUserResponse; |
| 147 | + |
| 148 | + beforeAll(async () => { |
| 149 | + channelName = `federated-room-${Date.now()}`; |
| 150 | + createResponse = await createRoom({ |
| 151 | + type: 'p', |
| 152 | + name: channelName, |
| 153 | + members: [], |
| 154 | + extraData: { |
| 155 | + federated: true, |
| 156 | + }, |
| 157 | + config: rc1AdminRequestConfig, |
| 158 | + }); |
| 159 | + expect(createResponse.status).toBe(200); |
| 160 | + expect(createResponse.body).toHaveProperty('success', true); |
| 161 | + expect(createResponse.body).toHaveProperty('group'); |
| 162 | + expect(createResponse.body.group).toHaveProperty('_id'); |
| 163 | + expect(createResponse.body.group).toHaveProperty('t', 'p'); |
| 164 | + expect(createResponse.body.group).toHaveProperty('federated', true); |
151 | 165 | }); |
| 166 | + let user: TestUser<IUser>; |
152 | 167 |
|
153 | | - expect(createResponse.status).toBe(200); |
154 | | - expect(createResponse.body).toHaveProperty('success', true); |
155 | | - expect(createResponse.body).toHaveProperty('group'); |
156 | | - expect(createResponse.body.group).toHaveProperty('_id'); |
157 | | - expect(createResponse.body.group).toHaveProperty('t', 'p'); |
158 | | - expect(createResponse.body.group).toHaveProperty('federated', true); |
| 168 | + beforeAll(async () => { |
| 169 | + user = await createUser( |
| 170 | + { |
| 171 | + username: `g3-${Date.now()}`, |
| 172 | + password: '1', |
| 173 | + roles: ['user'], |
| 174 | + }, |
| 175 | + rc1AdminRequestConfig, |
| 176 | + ); |
| 177 | + }); |
159 | 178 |
|
160 | | - const addUserResponse = await addUserToRoom({ |
161 | | - usernames: [federationConfig.hs1.adminMatrixUserId], |
162 | | - rid: createResponse.body.group._id, |
163 | | - config: rc1User1RequestConfig, |
| 179 | + afterAll(async () => { |
| 180 | + await deleteUser(user, {}, rc1AdminRequestConfig); |
164 | 181 | }); |
| 182 | + it('should not be able to add a user without access-federation permission to a room', async () => { |
| 183 | + const addUserResponse = await addUserToRoom({ |
| 184 | + usernames: [user.username], |
| 185 | + rid: createResponse.body.group._id, |
| 186 | + config: rc1AdminRequestConfig, |
| 187 | + }); |
| 188 | + |
| 189 | + expect(addUserResponse.status).toBe(200); |
| 190 | + expect(addUserResponse.body).toHaveProperty('success', true); |
| 191 | + expect(addUserResponse.body.message).toMatch(/error-not-authorized-federation/); |
| 192 | + }); |
| 193 | + |
| 194 | + it("should be able to add a remote user to a room regardless of the user's access-federation permission defined locally", async () => { |
| 195 | + addUserResponse = await addUserToRoom({ |
| 196 | + usernames: [federationConfig.hs1.adminMatrixUserId], |
| 197 | + rid: createResponse.body.group._id, |
| 198 | + config: rc1AdminRequestConfig, |
| 199 | + }); |
165 | 200 |
|
166 | | - expect(addUserResponse.status).toBe(200); |
167 | | - expect(addUserResponse.body).toHaveProperty('success', true); |
168 | | - expect(addUserResponse.body.message).toMatch(/error-not-allowed/); |
| 201 | + expect(addUserResponse.status).toBe(200); |
| 202 | + expect(addUserResponse.body).toHaveProperty('success', true); |
| 203 | + expect(addUserResponse.body).toHaveProperty('message'); |
| 204 | + expect(addUserResponse.body.message).toMatch('{"msg":"result","id":"id","result":true}'); |
| 205 | + }); |
169 | 206 | }); |
170 | 207 | }); |
171 | 208 |
|
|
0 commit comments