From c4df229db0a5771bc3d7b0ca30820be3982765c5 Mon Sep 17 00:00:00 2001 From: Gene Levitzky Date: Thu, 12 Apr 2018 14:54:36 -0400 Subject: [PATCH] Adding TemplateValidator. --- ...templates.js => amp-ad-template-helper.js} | 2 +- .../amp-a4a/0.1/cryptographic-validator.js | 3 +- extensions/amp-a4a/0.1/template-validator.js | 106 ++++++++++++++++++ .../amp-a4a/0.1/test/test-amp-ad-templates.js | 19 ++-- .../0.1/amp-ad-network-adzerk-impl.js | 15 +-- src/utils/array.js | 13 +++ test/functional/utils/test-array.js | 16 +++ 7 files changed, 155 insertions(+), 19 deletions(-) rename extensions/amp-a4a/0.1/{amp-ad-templates.js => amp-ad-template-helper.js} (99%) create mode 100644 extensions/amp-a4a/0.1/template-validator.js diff --git a/extensions/amp-a4a/0.1/amp-ad-templates.js b/extensions/amp-a4a/0.1/amp-ad-template-helper.js similarity index 99% rename from extensions/amp-a4a/0.1/amp-ad-templates.js rename to extensions/amp-a4a/0.1/amp-ad-template-helper.js index 0be9b3b1449dd..c41847a0c271c 100644 --- a/extensions/amp-a4a/0.1/amp-ad-templates.js +++ b/extensions/amp-a4a/0.1/amp-ad-template-helper.js @@ -34,7 +34,7 @@ const TEMPLATE_CORS_CONFIG = { credentials: 'omit', }; -export class AmpAdTemplates { +export class AmpAdTemplateHelper { /** * @param {!Window} win diff --git a/extensions/amp-a4a/0.1/cryptographic-validator.js b/extensions/amp-a4a/0.1/cryptographic-validator.js index 27e2a4ad020e8..22911f7ff96cc 100644 --- a/extensions/amp-a4a/0.1/cryptographic-validator.js +++ b/extensions/amp-a4a/0.1/cryptographic-validator.js @@ -21,7 +21,6 @@ import { } from './amp-ad-type-defs'; import {SignatureVerifier, VerificationStatus} from './signature-verifier'; import {getAmpAdMetadata} from './amp-ad-utils'; -import {getDefaultBootstrapBaseUrl} from '../../../src/3p-frame'; import {signingServerURLs} from '../../../ads/_a4a-config'; import {user} from '../../../src/log'; import {utf8Decode} from '../../../src/utils/bytes'; @@ -29,7 +28,7 @@ import {utf8Decode} from '../../../src/utils/bytes'; export const SIGNATURE_VERIFIER_PROPERTY_NAME = 'AMP_FAST_FETCH_SIGNATURE_VERIFIER_'; -const TAG = 'amp-ad-render'; +const TAG = 'amp-ad-cryptographic-validator'; export class CryptographicValidator extends Validator { /** @param {!Window} win */ diff --git a/extensions/amp-a4a/0.1/template-validator.js b/extensions/amp-a4a/0.1/template-validator.js new file mode 100644 index 0000000000000..f2fa2b1d46136 --- /dev/null +++ b/extensions/amp-a4a/0.1/template-validator.js @@ -0,0 +1,106 @@ +/** + * Copyright 2018 The AMP HTML Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS-IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import {AmpAdTemplateHelper} from '../../amp-a4a/0.1/amp-ad-template-helper'; +import {Services} from '../../../src/services'; +import {Validator, ValidatorResult} from './amp-ad-type-defs'; +import {pushIfNotExist} from '../../../src/utils/array'; +import {tryParseJson} from '../../../src/json'; +import {utf8Decode} from '../../../src/utils/bytes'; + +/** @const {string} */ +export const AMP_TEMPLATED_CREATIVE_HEADER_NAME = 'AMP-template-amp-creative'; + +/** + * Validator for Template ads. + */ +export class TemplateValidator extends Validator { + + constructor() { + super(); + + /** @private {?AmpAdTemplateHelper} */ + this.ampAdTemplateHelper_ = null; + } + + /** + * @param {string} templateString + * @param {!./amp-ad-type-defs.AmpTemplateCreativeDef} parsedResponseBody + * @return {!./amp-ad-type-defs.CreativeMetaDataDef} + * @private + */ + getAmpAdMetadata_(templateString, parsedResponseBody) { + // TODO(levitzky) The following minification is for demo purposes only. Once + // launched this will either be performed server-side, or will be replaced + // by more sophisticated logic. + const minifiedCreative = templateString.replace( + /