@@ -61,17 +61,13 @@ describe('Create attachments for message URLs', () => {
6161 const message = await jumpToMessage . createAttachmentForMessageURLs ( {
6262 message : createMessage ( 'hey' ) ,
6363 user : createUser ( ) ,
64- config : {
65- chainLimit : 10 ,
66- siteUrl : 'https://open.rocket.chat' ,
67- useRealName : true ,
68- } ,
64+ config : { chainLimit : 10 , useRealName : true } ,
6965 } ) ;
7066
7167 return expect ( message ) . to . not . have . property ( 'urls' ) ;
7268 } ) ;
7369
74- it ( 'should do nothing if URL is not from SiteUrl ' , async ( ) => {
70+ it ( 'should do nothing if URL does not have a msg query parameter ' , async ( ) => {
7571 const jumpToMessage = new BeforeSaveJumpToMessage ( {
7672 getMessages : async ( ) => [ createMessage ( 'linked message' , { _id : 'linked' } ) ] ,
7773 getRooms : async ( ) => [ createRoom ( ) ] ,
@@ -89,18 +85,14 @@ describe('Create attachments for message URLs', () => {
8985 ] ,
9086 } ) ,
9187 user : createUser ( ) ,
92- config : {
93- chainLimit : 10 ,
94- siteUrl : 'https://open.rocket.chat' ,
95- useRealName : true ,
96- } ,
88+ config : { chainLimit : 10 , useRealName : true } ,
9789 } ) ;
9890
9991 expect ( message ) . to . have . property ( 'urls' ) . of . length ( 1 ) ;
10092 expect ( message ) . to . not . have . property ( 'attachments' ) ;
10193 } ) ;
10294
103- it ( 'should do nothing if URL is from SiteUrl but not have a query string ' , async ( ) => {
95+ it ( 'should do nothing if URL has a non-msg query parameter ' , async ( ) => {
10496 const jumpToMessage = new BeforeSaveJumpToMessage ( {
10597 getMessages : async ( ) => [ createMessage ( 'linked message' , { _id : 'linked' } ) ] ,
10698 getRooms : async ( ) => [ createRoom ( ) ] ,
@@ -112,24 +104,20 @@ describe('Create attachments for message URLs', () => {
112104 message : createMessage ( 'hey' , {
113105 urls : [
114106 {
115- url : 'https://open.rocket.chat' ,
107+ url : 'https://open.rocket.chat/?token=value ' ,
116108 meta : { } ,
117109 } ,
118110 ] ,
119111 } ) ,
120112 user : createUser ( ) ,
121- config : {
122- chainLimit : 10 ,
123- siteUrl : 'https://open.rocket.chat' ,
124- useRealName : true ,
125- } ,
113+ config : { chainLimit : 10 , useRealName : true } ,
126114 } ) ;
127115
128116 expect ( message ) . to . have . property ( 'urls' ) . of . length ( 1 ) ;
129117 expect ( message ) . to . not . have . property ( 'attachments' ) ;
130118 } ) ;
131119
132- it ( 'should do nothing if URL is from SiteUrl but not have a msgId query string ' , async ( ) => {
120+ it ( 'should reject query parameter pollution (msg[$gt]=) ' , async ( ) => {
133121 const jumpToMessage = new BeforeSaveJumpToMessage ( {
134122 getMessages : async ( ) => [ createMessage ( 'linked message' , { _id : 'linked' } ) ] ,
135123 getRooms : async ( ) => [ createRoom ( ) ] ,
@@ -141,24 +129,55 @@ describe('Create attachments for message URLs', () => {
141129 message : createMessage ( 'hey' , {
142130 urls : [
143131 {
144- url : 'https://open.rocket.chat/?token=value ' ,
132+ url : 'https://open.rocket.chat/?msg[$gt]= ' ,
145133 meta : { } ,
146134 } ,
147135 ] ,
148136 } ) ,
149137 user : createUser ( ) ,
150- config : {
151- chainLimit : 10 ,
152- siteUrl : 'https://open.rocket.chat' ,
153- useRealName : true ,
154- } ,
138+ config : { chainLimit : 10 , useRealName : true } ,
155139 } ) ;
156140
157141 expect ( message ) . to . have . property ( 'urls' ) . of . length ( 1 ) ;
158142 expect ( message ) . to . not . have . property ( 'attachments' ) ;
159143 } ) ;
160144
161- it ( 'should do nothing if it do not find a msg from the URL' , async ( ) => {
145+ it ( 'should create quote attachment even when client hostname differs from server (e.g. localhost vs 127.0.0.1)' , async ( ) => {
146+ const jumpToMessage = new BeforeSaveJumpToMessage ( {
147+ getMessages : async ( ) => [ createMessage ( 'linked message' , { _id : 'linked' } ) ] ,
148+ getRooms : async ( ) => [ createRoom ( ) ] ,
149+ canAccessRoom : async ( ) => true ,
150+ getUserAvatarURL : ( ) => 'url' ,
151+ } ) ;
152+
153+ const message = await jumpToMessage . createAttachmentForMessageURLs ( {
154+ message : createMessage ( 'hey' , {
155+ urls : [
156+ {
157+ url : 'http://localhost:3000/channel/general?msg=linked' ,
158+ meta : { } ,
159+ } ,
160+ ] ,
161+ } ) ,
162+ user : createUser ( ) ,
163+ config : { chainLimit : 10 , useRealName : true } ,
164+ } ) ;
165+
166+ expect ( message ) . to . have . property ( 'urls' ) . and . to . have . lengthOf ( 1 ) ;
167+
168+ const [ url ] = message . urls ?? [ ] ;
169+ expect ( url ) . to . include ( {
170+ url : 'http://localhost:3000/channel/general?msg=linked' ,
171+ ignoreParse : true ,
172+ } ) ;
173+
174+ expect ( message ) . to . have . property ( 'attachments' ) . and . to . have . lengthOf ( 1 ) ;
175+
176+ const [ attachment ] = message . attachments ?? [ ] ;
177+ expect ( attachment ) . to . have . property ( 'text' , 'linked message' ) ;
178+ } ) ;
179+
180+ it ( 'should do nothing if it does not find a message from the URL' , async ( ) => {
162181 const jumpToMessage = new BeforeSaveJumpToMessage ( {
163182 getMessages : async ( ) => [ ] ,
164183 getRooms : async ( ) => [ createRoom ( ) ] ,
@@ -176,11 +195,7 @@ describe('Create attachments for message URLs', () => {
176195 ] ,
177196 } ) ,
178197 user : createUser ( ) ,
179- config : {
180- chainLimit : 10 ,
181- siteUrl : 'https://open.rocket.chat' ,
182- useRealName : true ,
183- } ,
198+ config : { chainLimit : 10 , useRealName : true } ,
184199 } ) ;
185200
186201 expect ( message ) . to . have . property ( 'urls' ) . of . length ( 1 ) ;
@@ -205,18 +220,14 @@ describe('Create attachments for message URLs', () => {
205220 ] ,
206221 } ) ,
207222 user : createUser ( ) ,
208- config : {
209- chainLimit : 10 ,
210- siteUrl : 'https://open.rocket.chat' ,
211- useRealName : true ,
212- } ,
223+ config : { chainLimit : 10 , useRealName : true } ,
213224 } ) ;
214225
215226 expect ( message ) . to . have . property ( 'urls' ) . of . length ( 1 ) ;
216227 expect ( message ) . to . not . have . property ( 'attachments' ) ;
217228 } ) ;
218229
219- it ( 'should do nothing if user dont have access to the room of the message from the URL' , async ( ) => {
230+ it ( 'should do nothing if user does not have access to the room of the message from the URL' , async ( ) => {
220231 const jumpToMessage = new BeforeSaveJumpToMessage ( {
221232 getMessages : async ( ) => [ createMessage ( 'linked message' , { _id : 'linked' } ) ] ,
222233 getRooms : async ( ) => [ createRoom ( ) ] ,
@@ -234,11 +245,7 @@ describe('Create attachments for message URLs', () => {
234245 ] ,
235246 } ) ,
236247 user : createUser ( ) ,
237- config : {
238- chainLimit : 10 ,
239- siteUrl : 'https://open.rocket.chat' ,
240- useRealName : true ,
241- } ,
248+ config : { chainLimit : 10 , useRealName : true } ,
242249 } ) ;
243250
244251 expect ( message ) . to . have . property ( 'urls' ) . of . length ( 1 ) ;
@@ -272,11 +279,7 @@ describe('Create attachments for message URLs', () => {
272279 ] ,
273280 } ) ,
274281 user : createUser ( ) ,
275- config : {
276- chainLimit : 10 ,
277- siteUrl : 'https://open.rocket.chat' ,
278- useRealName : true ,
279- } ,
282+ config : { chainLimit : 10 , useRealName : true } ,
280283 } ) ;
281284
282285 expect ( message ) . to . have . property ( 'urls' ) . and . to . have . lengthOf ( 1 ) ;
@@ -317,11 +320,7 @@ describe('Create attachments for message URLs', () => {
317320 ] ,
318321 } ) ,
319322 user : createUser ( ) ,
320- config : {
321- chainLimit : 10 ,
322- siteUrl : 'https://open.rocket.chat' ,
323- useRealName : true ,
324- } ,
323+ config : { chainLimit : 10 , useRealName : true } ,
325324 } ) ;
326325
327326 expect ( message ) . to . have . property ( 'attachments' ) . and . to . have . lengthOf ( 0 ) ;
@@ -349,11 +348,7 @@ describe('Create attachments for message URLs', () => {
349348 ] ,
350349 } ) ,
351350 user : createUser ( ) ,
352- config : {
353- chainLimit : 10 ,
354- siteUrl : 'https://open.rocket.chat' ,
355- useRealName : true ,
356- } ,
351+ config : { chainLimit : 10 , useRealName : true } ,
357352 } ) ;
358353
359354 expect ( message ) . to . have . property ( 'attachments' ) . and . to . have . lengthOf ( 1 ) ;
@@ -379,11 +374,7 @@ describe('Create attachments for message URLs', () => {
379374 ] ,
380375 } ) ,
381376 user : createUser ( ) ,
382- config : {
383- chainLimit : 10 ,
384- siteUrl : 'https://open.rocket.chat' ,
385- useRealName : true ,
386- } ,
377+ config : { chainLimit : 10 , useRealName : true } ,
387378 } ) ;
388379
389380 expect ( message ) . to . have . property ( 'urls' ) . and . to . have . lengthOf ( 1 ) ;
@@ -453,7 +444,6 @@ describe('Create attachments for message URLs', () => {
453444 user : createUser ( ) ,
454445 config : {
455446 chainLimit : 3 ,
456- siteUrl : 'https://open.rocket.chat' ,
457447 useRealName : true ,
458448 } ,
459449 } ) ;
@@ -536,7 +526,6 @@ describe('Create attachments for message URLs', () => {
536526 user : createUser ( ) ,
537527 config : {
538528 chainLimit : 3 ,
539- siteUrl : 'https://open.rocket.chat' ,
540529 useRealName : true ,
541530 } ,
542531 } ) ;
@@ -567,11 +556,7 @@ describe('Create attachments for message URLs', () => {
567556 token : 'livechatToken' ,
568557 } ) ,
569558 user : createUser ( ) ,
570- config : {
571- chainLimit : 10 ,
572- siteUrl : 'https://open.rocket.chat' ,
573- useRealName : true ,
574- } ,
559+ config : { chainLimit : 10 , useRealName : true } ,
575560 } ) ;
576561
577562 expect ( message ) . to . have . property ( 'urls' ) . and . to . have . lengthOf ( 1 ) ;
@@ -609,11 +594,7 @@ describe('Create attachments for message URLs', () => {
609594 token : 'another-token' ,
610595 } ) ,
611596 user : createUser ( ) ,
612- config : {
613- chainLimit : 10 ,
614- siteUrl : 'https://open.rocket.chat' ,
615- useRealName : true ,
616- } ,
597+ config : { chainLimit : 10 , useRealName : true } ,
617598 } ) ;
618599
619600 expect ( message ) . to . have . property ( 'urls' ) . and . to . have . lengthOf ( 1 ) ;
@@ -653,7 +634,6 @@ describe('Create attachments for message URLs', () => {
653634 user : createUser ( ) ,
654635 config : {
655636 chainLimit : 1 ,
656- siteUrl : 'https://open.rocket.chat' ,
657637 useRealName : true ,
658638 } ,
659639 } ) ;
@@ -708,7 +688,6 @@ describe('Create attachments for message URLs', () => {
708688 user : createUser ( ) ,
709689 config : {
710690 chainLimit : 1 ,
711- siteUrl : 'https://open.rocket.chat' ,
712691 useRealName : true ,
713692 } ,
714693 } ) ;
0 commit comments