Skip to content

Commit

Permalink
MM-13761 Properly request external image through proxy when viewed in…
Browse files Browse the repository at this point in the history
… preview modal (mattermost#2296)

* MM-13761 Properly request external image through proxy when viewed in preview modal

* Fix typo
  • Loading branch information
hmhealey authored Jan 31, 2019
1 parent 64d8cd9 commit 23e4b2b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export default class PostBodyAdditionalContent extends React.PureComponent {
}

renderImagePreview() {
const link = this.state.link;
let link = this.state.link;
if (!link || !this.isLinkImage(link)) {
return null;
}
Expand All @@ -280,6 +280,8 @@ export default class PostBodyAdditionalContent extends React.PureComponent {

const ext = captureExt.exec(link)[1];

link = PostUtils.getImageSrc(link, this.props.hasImageProxy);

return (
<ViewImageModal
show={this.state.showPreviewModal}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import React from 'react';
import {shallow} from 'enzyme';

import PostBodyAdditionalContent from 'components/post_view/post_body_additional_content/post_body_additional_content.jsx';
import ViewImageModal from 'components/view_image';

import * as PostUtils from 'utils/post_utils';

describe('components/post_view/PostBodyAdditionalContent', () => {
const post = {
Expand Down Expand Up @@ -66,4 +69,27 @@ describe('components/post_view/PostBodyAdditionalContent', () => {
expect(props.actions.toggleEmbedVisibility).toHaveBeenCalledTimes(1);
expect(props.actions.toggleEmbedVisibility).toBeCalledWith('post_id_1');
});

test('image link should go through image proxy in preview modal', () => {
const link = 'https://example.com/image.png';

const props = {
...baseProps,
hasImageProxy: true,
post: {
...post,
message: link,
},
};

const wrapper = shallow(
<PostBodyAdditionalContent {...props}>
<div/>
</PostBodyAdditionalContent>
);

const fileInfos = wrapper.find(ViewImageModal).prop('fileInfos');
expect(fileInfos.length).toBe(1);
expect(fileInfos[0].link).toBe(PostUtils.getImageSrc(link, true));
});
});

0 comments on commit 23e4b2b

Please sign in to comment.