This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MM-13924 Ensure OpenGraph and message attachment images go through th…
…e proxy (#2331) Doing this on the app instead of the server because it might otherwise cause problems when we're requesting image dimensions. I was looking at a more generic way of doing this, but this doesn't seem like the time to add it since we're just about to kick off RC testing. #### Ticket Link https://mattermost.atlassian.net/browse/MM-13924
- Loading branch information
Showing
7 changed files
with
140 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
components/post_view/post_attachment_opengraph/post_attachment_opengraph.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. | ||
// See LICENSE.txt for license information. | ||
|
||
import {Client4} from 'mattermost-redux/client'; | ||
|
||
import PostAttachmentOpenGraph from './post_attachment_opengraph'; | ||
|
||
describe('PostAttachmentOpenGraph', () => { | ||
describe('getBestImageUrl', () => { | ||
test('should return nothing with no OpenGraph metadata', () => { | ||
const data = null; | ||
|
||
expect(PostAttachmentOpenGraph.getBestImageUrl(data, false)).toEqual(null); | ||
}); | ||
|
||
test('should return nothing with missing OpenGraph images', () => { | ||
const data = {}; | ||
|
||
expect(PostAttachmentOpenGraph.getBestImageUrl(data, false)).toEqual(null); | ||
}); | ||
|
||
test('should return nothing with no OpenGraph images', () => { | ||
const data = { | ||
images: [], | ||
}; | ||
|
||
expect(PostAttachmentOpenGraph.getBestImageUrl(data, false)).toEqual(null); | ||
}); | ||
|
||
test('should return secure_url if specified', () => { | ||
const data = { | ||
images: [{ | ||
secure_url: 'https://example.com/image.png', | ||
url: 'http:https://example.com/image.png', | ||
}], | ||
}; | ||
|
||
expect(PostAttachmentOpenGraph.getBestImageUrl(data, false)).toEqual(data.images[0].secure_url); | ||
}); | ||
|
||
test('should return url if secure_url is not specified', () => { | ||
const data = { | ||
images: [{ | ||
secure_url: '', | ||
url: 'http:https://example.com/image.png', | ||
}], | ||
}; | ||
|
||
expect(PostAttachmentOpenGraph.getBestImageUrl(data, false)).toEqual(data.images[0].url); | ||
}); | ||
|
||
test('should return a proxied image URL if the image proxy is enabled', () => { | ||
const data = { | ||
images: [{ | ||
url: 'http:https://example.com/image.png', | ||
}], | ||
}; | ||
|
||
expect(PostAttachmentOpenGraph.getBestImageUrl(data, true).endsWith(`/api/v4/image?url=${encodeURIComponent(data.images[0].url)}`)).toEqual(true); | ||
}); | ||
|
||
test('should not mangle a URL that is already proxied if the image proxy is enabled', () => { | ||
const data = { | ||
images: [{ | ||
url: `${Client4.getBaseRoute()}/image?url=${encodeURIComponent('http:https://example.com/image.png')}`, | ||
}], | ||
}; | ||
|
||
expect(PostAttachmentOpenGraph.getBestImageUrl(data, true)).toEqual(data.images[0].url); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters