3 process
.env
.DISABLE_MATRIX_BRIDGE
= '1';
4 process
.env
.DISABLE_API_LISTEN
= '1';
5 process
.env
.DISABLE_API_WEB_LISTEN
= '1';
7 const env
= require('gitter-web-env');
8 const config
= env
.config
;
10 const assert
= require('assert');
11 const request
= require('supertest');
12 const fixtureUtils
= require('gitter-web-test-utils/lib/fixture-utils');
13 const fixtureLoader
= require('gitter-web-test-utils/lib/test-fixtures');
14 const ensureMatrixFixtures
= require('./utils/ensure-matrix-fixtures');
15 const registerTestSynapseUser
= require('./utils/register-test-synapse-user');
16 const util
= require('util');
17 const requestLib
= util
.promisify(require('request'));
18 const urlJoin
= require('url-join');
20 const installBridge
= require('gitter-web-matrix-bridge');
21 const matrixStore
= require('gitter-web-matrix-bridge/lib/store');
23 const app
= require('../../server/web');
25 const homeserverUrl
= config
.get('matrix:bridge:homeserverUrl');
26 const bridgePortFromConfig
= config
.get('matrix:bridge:applicationServicePort');
28 describe('Gitter <-> Matrix bridging e2e', () => {
29 const fixture
= fixtureLoader
.setupEach({
31 accessToken
: 'web-internal'
34 accessToken
: 'web-internal'
51 users
: ['user1', 'user2']
55 //let someMatrixUserId;
56 let someMatrixUserAccessToken
;
59 await
ensureMatrixFixtures();
61 stopBridge
= await
installBridge(bridgePortFromConfig
+ 1);
63 const localPart
= fixtureUtils
.generateUsername().slice(1);
64 //someMatrixUserId = `@${localPart}:${serverName}`;
65 const res
= await
registerTestSynapseUser(localPart
);
66 someMatrixUserAccessToken
= res
.access_token
;
67 assert(someMatrixUserAccessToken
);
76 it('bridges message to Matrix in public Gitter room', async () => {
77 const messageText
= 'foo 123 baz';
78 // Send a message in a public room which should trigger the bridged Matrix
79 // room creation and send the message in the room.
80 const messageSendRes
= await
request(app
)
81 .post(`/api/v1/rooms/${fixture.troupe1.id}/chatMessages`)
82 .send({ text
: messageText
})
83 .set('Authorization', `Bearer ${fixture.user1.accessToken}`)
86 // Since we're using the async out-of-loop Gitter event-listeners to listen
87 // for the new chat message to come through and bridge we just have to wait
88 // until we see that the Matrix room is created and stored
91 matrixRoomId
= await matrixStore
.getMatrixRoomIdByGitterRoomId(fixture
.troupe1
.id
);
92 } while (!matrixRoomId
);
93 // And wait for the initial message to be bridged which triggered this whole process
94 assert(messageSendRes
.body
.id
);
97 matrixEventId
= await matrixStore
.getBridgedMessageEntryByGitterMessageId(
98 messageSendRes
.body
.id
100 } while (!matrixEventId
);
102 // Try to join the room from some Matrix user's perspective. We should be able to get in!
103 const joinRes
= await
requestLib({
105 uri
: urlJoin(homeserverUrl
, `/_matrix/client/r0/rooms/${matrixRoomId}/join`),
108 Authorization
: `Bearer ${someMatrixUserAccessToken}`,
109 'Content-Type': 'application/json'
116 `Expected to be able to join Matrix room (which should be public) for bridged public Gitter room, joinRes.body=${JSON.stringify(
121 // Make sure we can see the Gitter message in the matrix room as well
122 const messageRes
= await
requestLib({
124 uri
: urlJoin(homeserverUrl
, `/_matrix/client/r0/rooms/${matrixRoomId}/messages?dir=b`),
127 Authorization
: `Bearer ${someMatrixUserAccessToken}`,
128 'Content-Type': 'application/json'
132 messageRes
.statusCode
,
134 `Expected to be able to read messages in public Matrix room, messageRes.body=${JSON.stringify(
139 messageRes
.body
.chunk
.filter(event
=> event
.type
=== 'm.room.message')[0].content
.body
,
141 `Expected the latest message in the room to match our Gitter message we sent initially, messageRes.body=${JSON.stringify(
147 it('bridges message to Matrix in private Gitter room', async () => {
148 const messageText
= 'foo 123 baz';
149 // Send a message in a public room which should trigger the bridged Matrix
150 // room creation and send the message in the room.
151 const messageSendRes
= await
request(app
)
152 .post(`/api/v1/rooms/${fixture.troupePrivate1.id}/chatMessages`)
153 .send({ text
: messageText
})
154 .set('Authorization', `Bearer ${fixture.user1.accessToken}`)
157 // Since we're using the async out-of-loop Gitter event-listeners to listen
158 // for the new chat message to come through and bridge we just have to wait
159 // until we see that the Matrix room is created and stored
162 matrixRoomId
= await matrixStore
.getMatrixRoomIdByGitterRoomId(fixture
.troupePrivate1
.id
);
163 } while (!matrixRoomId
);
164 // And wait for the initial message to be bridged which triggered this whole process
165 assert(messageSendRes
.body
.id
);
168 matrixEventId
= await matrixStore
.getBridgedMessageEntryByGitterMessageId(
169 messageSendRes
.body
.id
171 } while (!matrixEventId
);
173 // Try to join the room from some Matrix user's perspective. We shouldn't be able to get in!
174 const joinRes
= await
requestLib({
176 uri
: urlJoin(homeserverUrl
, `/_matrix/client/r0/rooms/${matrixRoomId}/join`),
179 Authorization
: `Bearer ${someMatrixUserAccessToken}`,
180 'Content-Type': 'application/json'
187 `Expected not to be able to join Matrix room (which should be private) for bridged private Gitter room, joinRes.body=${JSON.stringify(
193 it('bridges message to Matrix in ONE_TO_ONE Gitter room', async () => {
194 const messageText
= 'foo 123 baz';
195 // Send a message in a public room which should trigger the bridged Matrix
196 // room creation and send the message in the room.
197 const messageSendRes
= await
request(app
)
198 .post(`/api/v1/rooms/${fixture.troupeOneToOne.id}/chatMessages`)
199 .send({ text
: messageText
})
200 .set('Authorization', `Bearer ${fixture.user1.accessToken}`)
203 // Since we're using the async out-of-loop Gitter event-listeners to listen
204 // for the new chat message to come through and bridge we just have to wait
205 // until we see that the Matrix room is created and stored
208 matrixRoomId
= await matrixStore
.getMatrixRoomIdByGitterRoomId(fixture
.troupeOneToOne
.id
);
209 } while (!matrixRoomId
);
210 // And wait for the initial message to be bridged which triggered this whole process
211 assert(messageSendRes
.body
.id
);
214 matrixEventId
= await matrixStore
.getBridgedMessageEntryByGitterMessageId(
215 messageSendRes
.body
.id
217 } while (!matrixEventId
);
219 // Try to join the room from some Matrix user's perspective. We shouldn't be able to get in!
220 const joinRes
= await
requestLib({
222 uri
: urlJoin(homeserverUrl
, `/_matrix/client/r0/rooms/${matrixRoomId}/join`),
225 Authorization
: `Bearer ${someMatrixUserAccessToken}`,
226 'Content-Type': 'application/json'
233 `Expected not to be able to join Matrix room (which should be private) for bridged ONE_TO_ONE Gitter room, joinRes.body=${JSON.stringify(