Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tmedia 428 allow list themesettings domains #1137

Merged
merged 2 commits into from Oct 15, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion blocks/resizer-image-content-source-block/README.md
Expand Up @@ -66,4 +66,17 @@ ManualBlock.propTypes = {
ManualBlock.label = 'Manual Block – Arc Block';

export default ManualBlock;
```
```

The following urls are allowed by default to be resized on the client-side:

```
'images.arcpublishing.com',
's3.amazonaws.com/arc-authors/',
'static.themebuilder.aws.arc.pub',
'themebuilder-api-uploads-ap-northeast-1.s3.amazonaws.com',
'themebuilder-api-uploads-eu-central-1.s3.amazonaws.com',
'themebuilder-api-uploads-us-east-1.s3.amazonaws.com',
'themebuilder-api-uploads.s3.amazonaws.com',
```

@@ -1,7 +1,15 @@
import { allowedImageDomains as ALLOWED_IMAGE_DOMAINS } from 'fusion:environment';
import getResizedImageData from '@wpmedia/resizer-image-block';

const ARCDomains = ['images.arcpublishing.com', 's3.amazonaws.com/arc-authors/'];
const ARCDomains = [
'images.arcpublishing.com',
's3.amazonaws.com/arc-authors/',
'static.themebuilder.aws.arc.pub',
'themebuilder-api-uploads-ap-northeast-1.s3.amazonaws.com',
'themebuilder-api-uploads-eu-central-1.s3.amazonaws.com',
'themebuilder-api-uploads-us-east-1.s3.amazonaws.com',
'themebuilder-api-uploads.s3.amazonaws.com',
];

const params = {
// has to be an external image
Expand Down
Expand Up @@ -32,6 +32,7 @@ describe('the resizer image api client source block', () => {
contentSource.fetch({ raw_image_url: 'http://images.arcpublishing.com/image.jpg' });
expect(mockFn.mock.calls.length).toBe(2);

// 's3.amazonaws.com/arc-authors/', is a default allowed domain
contentSource.fetch({ raw_image_url: 'https://s3.amazonaws.com/arc-authors/marty-mcfly.jpg' });
expect(mockFn.mock.calls.length).toBe(3);

Expand All @@ -58,6 +59,7 @@ describe('the resizer image api client source block', () => {
contentSource.fetch({ raw_image_url: 'https://example.com/image.jpg' });
expect(mockFn.mock.calls.length).toBe(3);

// does not iterate the mock call because 'examples' doesn't match 'example' in mock
contentSource.fetch({ raw_image_url: 'https://examples.com/image.jpg' });
expect(mockFn.mock.calls.length).toBe(3);
});
Expand All @@ -84,4 +86,32 @@ describe('the resizer image api client source block', () => {
contentSource.fetch({ raw_image_url: 'https://my-custom-domain.com/image.jpg' });
expect(mockFn.mock.calls.length).toBe(4);
});
it('allows default arc domains to be called', () => {
const { default: contentSource } = require('./resize-image-api-client');

// iterates mock call length because defaults in ARCDomains
contentSource.fetch({ raw_image_url: 'http://themes.images.arcpublishing.com/image.jpg' });
expect(mockFn.mock.calls.length).toBe(1);

contentSource.fetch({ raw_image_url: 'http://images.arcpublishing.com/image.jpg' });
expect(mockFn.mock.calls.length).toBe(2);

contentSource.fetch({ raw_image_url: 'https://s3.amazonaws.com/arc-authors/marty-mcfly.jpg' });
expect(mockFn.mock.calls.length).toBe(3);

contentSource.fetch({ raw_image_url: 'https://static.themebuilder.aws.arc.pub/marty-mcfly.jpg' });
expect(mockFn.mock.calls.length).toBe(4);

contentSource.fetch({ raw_image_url: 'https://themebuilder-api-uploads-ap-northeast-1.s3.amazonaws.com/marty-mcfly.jpg' });
expect(mockFn.mock.calls.length).toBe(5);

contentSource.fetch({ raw_image_url: 'https://themebuilder-api-uploads-eu-central-1.s3.amazonaws.com/marty-mcfly.jpg' });
expect(mockFn.mock.calls.length).toBe(6);

contentSource.fetch({ raw_image_url: 'https://themebuilder-api-uploads-us-east-1.s3.amazonaws.com/marty-mcfly.jpg' });
expect(mockFn.mock.calls.length).toBe(7);

contentSource.fetch({ raw_image_url: 'https://themebuilder-api-uploads.s3.amazonaws.com/marty-mcfly.jpg' });
expect(mockFn.mock.calls.length).toBe(8);
});
});