Skip to content
Open
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
4 changes: 2 additions & 2 deletions extensions/amp-a4a/0.1/amp-ad-template-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
getServiceForDoc,
registerServiceBuilderForDoc,
} from '../../../src/service-helpers';
import {parseUrlDeprecated} from '../../../src/url';
import {isProxyOrigin, parseUrlDeprecated} from '../../../src/url';

/** @private {!{[key: string]: string|boolean}} */
const TEMPLATE_CORS_CONFIG = {
Expand Down Expand Up @@ -114,7 +114,7 @@ export class AmpAdTemplateHelper {
getTemplateProxyUrl_(url) {
const cdnUrlSuffix = urls.cdn.slice(8);
const loc = parseUrlDeprecated(url);
return loc.origin.indexOf(cdnUrlSuffix) > 0
return isProxyOrigin(loc)
? url
: 'https://' +
loc.hostname.replace(/-/g, '--').replace(/\./g, '-') +
Expand Down
9 changes: 9 additions & 0 deletions extensions/amp-a4a/0.1/test/test-amp-ad-template-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ describes.fakeWin('AmpAdTemplateHelper', {amp: true}, (env) => {
);
});

it('should proxy a host that only embeds the CDN name as a substring', () => {
const lookalikeUrl =
'https://cdn.ampproject.org.evil.example/amp_template_1';
expect(ampAdTemplateHelper.getTemplateProxyUrl_(lookalikeUrl)).to.equal(
'https://cdn-ampproject-org-evil-example.cdn.ampproject.org/ad/s/' +
'cdn.ampproject.org.evil.example/amp_template_1'
);
});

it('should render a template with correct values', () => {
const parentDiv = doc.createElement('div');
parentDiv./*OK*/ innerHTML =
Expand Down