-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Adagio Bid Adapter: external script compliance #11351
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,13 +30,17 @@ pbjs.setConfig({ | |
|
||
### Bidder Settings | ||
|
||
The Adagio bid adapter uses browser local storage. Since Prebid.js 7.x, the access to it must be explicitly set. | ||
- `storageAllowed`: Adagio uses browser local storage, explicit access to it must be configured _(since Prebid.js 7.x)_ | ||
- `scriptVersion`: Adagio loads an additional script used for measurement. By default the adapter loads a specific version of this script, defined in the adapter itself. Two values can override this behavior: | ||
- `latest`: allow to always get the more recent version of the script | ||
- `none`: deactivates the feature, no script is loaded | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please make this the default |
||
|
||
```js | ||
// https://docs.prebid.org/dev-docs/publisher-api-reference/bidderSettings.html | ||
pbjs.bidderSettings = { | ||
adagio: { | ||
storageAllowed: true | ||
storageAllowed: true, | ||
scriptVersion: 'latest' | ||
} | ||
} | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1760,29 +1760,8 @@ describe('Adagio bid adapter', () => { | |
}); | ||
}); | ||
|
||
describe('adagioScriptFromLocalStorageCb()', function() { | ||
const VALID_HASH = 'Lddcw3AADdQDrPtbRJkKxvA+o1CtScGDIMNRpHB3NnlC/FYmy/9RKXelKrYj/sjuWusl5YcOpo+lbGSkk655i8EKuDiOvK6ae/imxSrmdziIp+S/TA6hTFJXcB8k1Q9OIp4CMCT52jjXgHwX6G0rp+uYoCR25B1jHaHnpH26A6I='; | ||
const INVALID_HASH = 'invalid'; | ||
const VALID_SCRIPT_CONTENT = 'var _ADAGIO=function(){};(_ADAGIO)();\n'; | ||
const INVALID_SCRIPT_CONTENT = 'var _ADAGIO=function(){//corrupted};(_ADAGIO)();\n'; | ||
const ADAGIO_LOCALSTORAGE_KEY = 'adagioScript'; | ||
|
||
beforeEach(function() { | ||
localStorage.removeItem(ADAGIO_LOCALSTORAGE_KEY); | ||
}); | ||
|
||
describe('getAdagioScript', function() { | ||
it('should run storage.getDataFromLocalStorage callback and call adagioScriptFromLocalStorageCb() ', function() { | ||
sandbox.spy(adagio, 'adagioScriptFromLocalStorageCb'); | ||
const getDataFromLocalStorageStub = sandbox.stub(storage, 'getDataFromLocalStorage').callsArg(1); | ||
localStorage.setItem(ADAGIO_LOCALSTORAGE_KEY, '// hash: ' + VALID_HASH + '\n' + VALID_SCRIPT_CONTENT); | ||
|
||
getAdagioScript(); | ||
|
||
sinon.assert.callCount(getDataFromLocalStorageStub, 1); | ||
sinon.assert.callCount(adagio.adagioScriptFromLocalStorageCb, 1); | ||
}); | ||
|
||
describe('adagio external script loading', function() { | ||
describe('external script loading regarding the user consent storageAllowed flag', function() { | ||
it('should load external script if the user consent', function() { | ||
sandbox.stub(storage, 'localStorageIsEnabled').callsArgWith(0, true); | ||
getAdagioScript(); | ||
|
@@ -1796,75 +1775,52 @@ describe('Adagio bid adapter', () => { | |
|
||
expect(loadExternalScript.called).to.be.false; | ||
}); | ||
}) | ||
|
||
it('should remove the localStorage key if exists and the user does not consent', function() { | ||
sandbox.stub(storage, 'localStorageIsEnabled').callsArgWith(0, false); | ||
localStorage.setItem(ADAGIO_LOCALSTORAGE_KEY, 'the script'); | ||
|
||
getAdagioScript(); | ||
|
||
expect(loadExternalScript.called).to.be.false; | ||
expect(localStorage.getItem(ADAGIO_LOCALSTORAGE_KEY)).to.be.null; | ||
describe('getAdagioScript with expected version accordingly to bidderSettings config', function() { | ||
beforeEach(function() { | ||
sandbox.stub(storage, 'localStorageIsEnabled').callsArgWith(0, true); | ||
}); | ||
}); | ||
|
||
it('should verify valid hash with valid script', function () { | ||
localStorage.setItem(ADAGIO_LOCALSTORAGE_KEY, '// hash: ' + VALID_HASH + '\n' + VALID_SCRIPT_CONTENT); | ||
|
||
utilsMock.expects('logInfo').withExactArgs('Adagio: start script.').once(); | ||
utilsMock.expects('logWarn').withExactArgs('Adagio: no hash found.').never(); | ||
utilsMock.expects('logWarn').withExactArgs('Adagio: invalid script found.').never(); | ||
|
||
adagioScriptFromLocalStorageCb(localStorage.getItem(ADAGIO_LOCALSTORAGE_KEY)); | ||
|
||
expect(localStorage.getItem(ADAGIO_LOCALSTORAGE_KEY)).to.equals('// hash: ' + VALID_HASH + '\n' + VALID_SCRIPT_CONTENT); | ||
utilsMock.verify(); | ||
}); | ||
|
||
it('should verify valid hash with invalid script', function () { | ||
localStorage.setItem(ADAGIO_LOCALSTORAGE_KEY, '// hash: ' + VALID_HASH + '\n' + INVALID_SCRIPT_CONTENT); | ||
|
||
utilsMock.expects('logInfo').withExactArgs('Adagio: start script').never(); | ||
utilsMock.expects('logWarn').withExactArgs('Adagio: no hash found.').never(); | ||
utilsMock.expects('logWarn').withExactArgs('Adagio: invalid script found.').once(); | ||
|
||
adagioScriptFromLocalStorageCb(localStorage.getItem(ADAGIO_LOCALSTORAGE_KEY)); | ||
|
||
expect(localStorage.getItem(ADAGIO_LOCALSTORAGE_KEY)).to.be.null; | ||
utilsMock.verify(); | ||
}); | ||
const lockedVersion = '2.0.2'; | ||
|
||
it('should verify invalid hash with valid script', function () { | ||
localStorage.setItem(ADAGIO_LOCALSTORAGE_KEY, '// hash: ' + INVALID_HASH + '\n' + VALID_SCRIPT_CONTENT); | ||
|
||
utilsMock.expects('logInfo').withExactArgs('Adagio: start script').never(); | ||
utilsMock.expects('logWarn').withExactArgs('Adagio: no hash found.').never(); | ||
utilsMock.expects('logWarn').withExactArgs('Adagio: invalid script found.').once(); | ||
|
||
adagioScriptFromLocalStorageCb(localStorage.getItem(ADAGIO_LOCALSTORAGE_KEY)); | ||
|
||
expect(localStorage.getItem(ADAGIO_LOCALSTORAGE_KEY)).to.be.null; | ||
utilsMock.verify(); | ||
}); | ||
|
||
it('should verify missing hash', function () { | ||
localStorage.setItem(ADAGIO_LOCALSTORAGE_KEY, VALID_SCRIPT_CONTENT); | ||
it('loads a determined version', function() { | ||
const version = '2.0.5'; | ||
$$PREBID_GLOBAL$$.bidderSettings.adagio.scriptVersion = version; | ||
getAdagioScript(); | ||
expect(loadExternalScript.called).to.be.true; | ||
expect(loadExternalScript.args[0][0]).to.deep.equal(`https://script.4dex.io/a/${version}/adagio.js`); | ||
}); | ||
|
||
utilsMock.expects('logInfo').withExactArgs('Adagio: start script').never(); | ||
utilsMock.expects('logWarn').withExactArgs('Adagio: no hash found.').once(); | ||
utilsMock.expects('logWarn').withExactArgs('Adagio: invalid script found.').never(); | ||
it('loads the latest external script, bypass the lock version', function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure i'm comfortable with this, we'll need to talk in committee |
||
const version = 'latest'; | ||
$$PREBID_GLOBAL$$.bidderSettings.adagio.scriptVersion = version; | ||
getAdagioScript(); | ||
expect(loadExternalScript.called).to.be.true; | ||
expect(loadExternalScript.args[0][0]).to.deep.equal(`https://script.4dex.io/a/${version}/adagio.js`); | ||
}); | ||
|
||
adagioScriptFromLocalStorageCb(localStorage.getItem(ADAGIO_LOCALSTORAGE_KEY)); | ||
it('loads the locked version, bad version provided', function() { | ||
const version = 'false'; | ||
$$PREBID_GLOBAL$$.bidderSettings.adagio.scriptVersion = version; | ||
getAdagioScript(); | ||
expect(loadExternalScript.called).to.be.true; | ||
expect(loadExternalScript.args[0][0]).to.deep.equal(`https://script.4dex.io/a/${lockedVersion}/adagio.js`); | ||
}); | ||
|
||
expect(localStorage.getItem(ADAGIO_LOCALSTORAGE_KEY)).to.be.null; | ||
utilsMock.verify(); | ||
}); | ||
it('loads nothing', function() { | ||
const version = 'none'; | ||
$$PREBID_GLOBAL$$.bidderSettings.adagio.scriptVersion = version; | ||
getAdagioScript(); | ||
expect(loadExternalScript.called).to.be.false; | ||
}); | ||
|
||
it('should return false if content script does not exist in localStorage', function() { | ||
sandbox.spy(utils, 'logWarn'); | ||
expect(adagioScriptFromLocalStorageCb(null)).to.be.undefined; | ||
sinon.assert.callCount(utils.logWarn, 1); | ||
sinon.assert.calledWith(utils.logWarn, 'Adagio: script not found.'); | ||
it('loads the locked version - default behavior', function() { | ||
delete $$PREBID_GLOBAL$$.bidderSettings.adagio.scriptVersion; | ||
getAdagioScript(); | ||
expect(loadExternalScript.called).to.be.true; | ||
expect(loadExternalScript.args[0][0]).to.deep.equal(`https://script.4dex.io/a/${lockedVersion}/adagio.js`); | ||
}); | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we'll need to discuss if we're going to let a bidder do this, likely we will not, as that was the initial plan. Why not distribute your sidecar script independently of prebid or make it another module?