Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

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

Merged
merged 2 commits into from
Jan 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
});
});