Skip to content

Commit

Permalink
Update consent string maximum size to 200 bytes (#26741)
Browse files Browse the repository at this point in the history
* update maximum byte to 200

* nit
  • Loading branch information
zhouyx committed Feb 21, 2020
1 parent ccceb7b commit 1f9e6bf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
12 changes: 8 additions & 4 deletions extensions/amp-consent/0.1/consent-state-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ import {dev, devAssert, user} from '../../../src/log';
const TAG = 'CONSENT-STATE-MANAGER';
const CID_SCOPE = 'AMP-CONSENT';

/** @visibleForTesting */
export const CONSENT_STRING_MAX_LENGTH = 200;

export class ConsentStateManager {
/**
* Creates an instance of ConsentStateManager.
Expand Down Expand Up @@ -346,14 +349,15 @@ export class ConsentInstance {
}

const consentStr = consentInfo['consentString'];
if (consentStr && consentStr.length > 150) {
if (consentStr && consentStr.length > CONSENT_STRING_MAX_LENGTH) {
// Verify the length of consentString.
// 150 * 2 (utf8Encode) * 4/3 (base64) = 400 bytes.
// 200 * 2 (utf8Encode) * 4/3 (base64) = 533 bytes.
// TODO: Need utf8Encode if necessary.
user().error(
TAG,
'Cannot store consentString which length exceeds 150 ' +
'Previous stored consentInfo will be cleared'
'Cannot store consentString which length exceeds %s. ' +
'Previous stored consentInfo will be cleared',
CONSENT_STRING_MAX_LENGTH
);
// If new consentInfo value cannot be stored, need to remove previous
// value
Expand Down
12 changes: 7 additions & 5 deletions extensions/amp-consent/0.1/test/test-consent-state-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ import {
composeStoreValue,
constructConsentInfo,
} from '../consent-info';
import {ConsentInstance, ConsentStateManager} from '../consent-state-manager';
import {
CONSENT_STRING_MAX_LENGTH,
ConsentInstance,
ConsentStateManager,
} from '../consent-state-manager';
import {dev} from '../../../../src/log';
import {macroTask} from '../../../../testing/yield';
import {
Expand Down Expand Up @@ -146,9 +150,8 @@ describes.realWin('ConsentStateManager', {amp: 1}, env => {
it('update consent string that exceeds max size', function*() {
expectAsyncConsoleError(/Cannot store consentString/);
manager.registerConsentInstance('test', {});
const MAX_LENGTH = 150;
let testStr = 'a';
for (let i = 0; i < MAX_LENGTH; i++) {
for (let i = 0; i < CONSENT_STRING_MAX_LENGTH; i++) {
testStr += 'a';
}
manager.updateConsentInstanceState(
Expand Down Expand Up @@ -302,9 +305,8 @@ describes.realWin('ConsentStateManager', {amp: 1}, env => {

it('remove consentInfo when consentStr length exceeds', function*() {
expectAsyncConsoleError(/Cannot store consentString/);
const MAX_LENGTH = 150;
let testStr = 'a';
for (let i = 0; i < MAX_LENGTH; i++) {
for (let i = 0; i < CONSENT_STRING_MAX_LENGTH; i++) {
testStr += 'a';
}
instance.update(CONSENT_ITEM_STATE.ACCEPTED, testStr);
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-consent/integrating-consent.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ To add your consent management service to AMP runtime, it is expected that you:
- Meet the restrictions that the AMP runtime applies to ensure a good user experience. These includes
- Enforce the size of the consent prompt. The only two allowed sizes are the initial size (`width: 100vw`, `height: 30vh`), and the full screen size (`width: 100vw`, `height: 100%`) after user interactions.
- A default placeholder will be displayed before the consent prompt iframe is ready.
- Enforce the size of the stored consent information. 150 character length is the current limit. Please [file an issue](https://github.com/ampproject/amphtml/issues/new) if you find that not sufficient.
- Enforce the size of the stored consent information. 200 character length is the current limit. Please [file an issue](https://github.com/ampproject/amphtml/issues/new) if you find that not sufficient.
- Understand that including `<amp-consent type='yourName'></amp-consent>` on the page won't block any components by default. **Please make sure to inform your service users to block AMP components either by the `<meta name="amp-consent-blocking">` metaTag, or the `data-block-on-consent` attribute.**
- Understand that AMP Consent doesn't attempt to interpret the consent info string from the CMP. Vendors can access the consent info string from CMPs via [provided APIs](https://github.com/ampproject/amphtml/blob/master/ads/README.md#amp-consent-integration). It's up to the CMP and service provider vendors to agree on the format of the consent info string.
- Create an [Intent-To-Implement issue](../../CONTRIBUTING.md#contributing-features) stating that you'll be adding support to your CMP service to AMP. A great start point is to follow the `_ping_` CMP service implementation that the AMP team creates for testing purpose.
Expand Down

0 comments on commit 1f9e6bf

Please sign in to comment.