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

Consent Management module bug fix. #2588

Merged
merged 26 commits into from
May 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2fba6a2
ET-1691: Pulsepoint Analytics adapter for Prebid. (#1)
anand-venkatraman Oct 14, 2016
ca17acb
Merge remote-tracking branch 'upstream/master'
anand-venkatraman Oct 25, 2016
5da43c3
Adding bidRequest to bidFactory.createBid method as per https://githu…
anand-venkatraman Oct 25, 2016
cf41114
Merge branch 'master' of https://github.com/prebid/Prebid.js
anand-venkatraman Nov 8, 2016
62756a9
ET-1765: Adding support for additional params in PulsePoint adapter (#2)
anand-venkatraman Nov 9, 2016
f8fabb7
Merge branch 'master' of https://github.com/prebid/Prebid.js
anand-venkatraman Dec 8, 2016
b9af15c
ET-1850: Fixing https://github.com/prebid/Prebid.js/issues/866
anand-venkatraman Dec 8, 2016
6523c25
Merge pull request #3 from pulsepointinc/ET-1850
anand-venkatraman Dec 8, 2016
b5eeb7f
Minor fix
anand-venkatraman Dec 8, 2016
0f33ef5
Merge branch 'master' of https://github.com/prebid/Prebid.js
anand-venkatraman Mar 1, 2017
b5dbd34
Merge branch 'master' of https://github.com/prebid/Prebid.js
anand-venkatraman Jun 27, 2017
d6fcd11
Merge branch 'master' of https://github.com/prebid/Prebid.js
anand-venkatraman Jul 17, 2017
fce16ad
Merge branch 'master' of https://github.com/prebid/Prebid.js
anand-venkatraman Aug 15, 2017
9833867
Merge branch 'master' of https://github.com/prebid/Prebid.js
anand-venkatraman Sep 22, 2017
70924c5
Merge branch 'master' of https://github.com/prebid/Prebid.js
anand-venkatraman Oct 12, 2017
41f4aca
Merge branch 'master' of https://github.com/prebid/Prebid.js
anand-venkatraman Nov 13, 2017
aae98a7
Adding mandatory parameters to Bid
anand-venkatraman Nov 13, 2017
6d546ed
Merge from upstream
anand-venkatraman Nov 27, 2017
a04a18f
Merge branch 'master' of https://github.com/prebid/Prebid.js
anand-venkatraman Mar 7, 2018
467e9e3
Merge branch 'master' of https://github.com/prebid/Prebid.js
anand-venkatraman Apr 20, 2018
af1b3db
Merge branch 'master' of https://github.com/prebid/Prebid.js
anand-venkatraman Apr 30, 2018
a438b67
Merge branch 'master' of https://github.com/prebid/Prebid.js
anand-venkatraman May 4, 2018
e2fa8c3
Merge branch 'master' of https://github.com/prebid/Prebid.js
anand-venkatraman May 21, 2018
6db9eb4
Merge branch 'master' of https://github.com/prebid/Prebid.js
anand-venkatraman May 22, 2018
0a44c5a
GDPR Bug Fix with String response
anand-venkatraman May 22, 2018
6456879
minor
anand-venkatraman May 22, 2018
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
3 changes: 2 additions & 1 deletion modules/consentManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as utils from 'src/utils';
import { config } from 'src/config';
import { gdprDataHandler } from 'src/adaptermanager';
import includes from 'core-js/library/fn/array/includes';
import strIncludes from 'core-js/library/fn/string/includes';

const DEFAULT_CMP = 'iab';
const DEFAULT_CONSENT_TIMEOUT = 10000;
Expand Down Expand Up @@ -131,7 +132,7 @@ function lookupIabConsent(cmpSuccess, cmpError, adUnits) {

function readPostMessageResponse(event) {
// small customization to prevent reading strings from other sources that aren't JSON.stringified
let json = (typeof event.data === 'string' && includes(event.data, 'cmpReturn')) ? JSON.parse(event.data) : event.data;
let json = (typeof event.data === 'string' && strIncludes(event.data, 'cmpReturn')) ? JSON.parse(event.data) : event.data;
if (json.__cmpReturn) {
let i = json.__cmpReturn;
cmpCallbacks[i.callId](i.returnValue, i.success);
Expand Down
97 changes: 66 additions & 31 deletions test/spec/modules/consentManagement_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,60 +201,95 @@ describe('consentManagement', function () {

describe('CMP workflow for iframed page', () => {
let eventStub = sinon.stub();
let cmpStub = sinon.stub();
let postMessageStub = sinon.stub();
let ifr = null;

beforeEach(() => {
didHookReturn = false;
window.__cmp = function() {};
sinon.stub(utils, 'logError');
sinon.stub(utils, 'logWarn');
ifr = createIFrameMarker();
});

afterEach(() => {
config.resetConfig();
$$PREBID_GLOBAL$$.requestBids.removeHook(requestBidsHook);
eventStub.restore();
cmpStub.restore();
postMessageStub.restore();
delete window.__cmp;
utils.logError.restore();
utils.logWarn.restore();
resetConsentData();
document.body.removeChild(ifr);
});

it('should return the consent string from a postmessage + addEventListener response', () => {
let testConsentData = {
data: {
__cmpReturn: {
returnValue: {
gdprApplies: true,
metadata: 'BOJy+UqOJy+UqABAB+AAAAAZ+A=='
}
function createIFrameMarker() {
var ifr = document.createElement('iframe');
ifr.width = 0;
ifr.height = 0;
ifr.name = '__cmpLocator';
document.body.appendChild(ifr);
return ifr;
}

testIFramedPage('with/JSON response', {
data: {
__cmpReturn: {
returnValue: {
gdprApplies: true,
metadata: 'BOJy+UqOJy+UqABAB+AAAAAZ+A=='
}
}
};
eventStub = sinon.stub(window, 'addEventListener').callsFake((...args) => {
args[1](testConsentData);
});
cmpStub = sinon.stub(window, '__cmp').callsFake((...args) => {
args[2]({
gdprApplies: true,
metadata: 'BOJy+UqOJy+UqABAB+AAAAAZ+A=='
}
}, false);

testIFramedPage('with/String response', {
data: {
__cmpReturn: {
returnValue: {
gdprApplies: true,
metadata: 'BOJy+UqOJy+UqABAB+AAAAAZ+A=='
}
}
}
}, true);

function testIFramedPage(testName, testConsentData, messageFormatString) {
it(`should return the consent string from a postmessage + addEventListener response - ${testName}`, () => {
let messageListener;
eventStub = sinon.stub(window, 'addEventListener').callsFake((...args) => {
// save reference to event listener for message
// so we can return the data when the message arrives via 'postMessage'
messageListener = args[1];
});
// when the iframed window sends a message to the window
// containing the CMP, intercept it and respond back with data
// on the message listener.
postMessageStub = sinon.stub(window, 'postMessage').callsFake((...args) => {
if (messageListener && args[0] && args[0].__cmpCall) {
// take the callId from request and stamp it on the response.
testConsentData.data.__cmpReturn.callId = args[0].__cmpCall.callId;
// serialize the data part to String if requested
messageListener(messageFormatString ? {
data: JSON.stringify(testConsentData.data)
} : testConsentData);
}
});
});

setConfig(goodConfigWithAllowAuction);
setConfig(goodConfigWithAllowAuction);

requestBidsHook({}, () => {
didHookReturn = true;
});
let consent = gdprDataHandler.getConsentData();
requestBidsHook({}, () => {
didHookReturn = true;
});
let consent = gdprDataHandler.getConsentData();

sinon.assert.notCalled(utils.logWarn);
sinon.assert.notCalled(utils.logError);
expect(didHookReturn).to.be.true;
expect(consent.consentString).to.equal('BOJy+UqOJy+UqABAB+AAAAAZ+A==');
expect(consent.gdprApplies).to.be.true;
});
sinon.assert.notCalled(utils.logWarn);
sinon.assert.notCalled(utils.logError);
expect(didHookReturn).to.be.true;
expect(consent.consentString).to.equal('BOJy+UqOJy+UqABAB+AAAAAZ+A==');
expect(consent.gdprApplies).to.be.true;
});
}
});

describe('CMP workflow for normal pages:', () => {
Expand Down