Skip to content

Commit

Permalink
Prebid Core: Adding idImportLibrary to activity controls (#11976)
Browse files Browse the repository at this point in the history
* 11705 Adding idImportLibrary to activity controls

* module type fix

* adds tests

---------

Co-authored-by: Marcin Komorski <[email protected]>
  • Loading branch information
mkomorski and Marcin Komorski authored Jul 18, 2024
1 parent 5ef3952 commit 62099b9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
20 changes: 14 additions & 6 deletions modules/idImportLibrary.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { logInfo, logError } from '../src/utils.js';
import {getGlobal} from '../src/prebidGlobal.js';
import {ajax} from '../src/ajax.js';
import {config} from '../src/config.js';
import MD5 from 'crypto-js/md5.js';
import { ACTIVITY_ENRICH_UFPD } from '../src/activities/activities.js';
import { activityParams } from '../src/activities/activityParams.js';
import { MODULE_TYPE_PREBID } from '../src/activities/modules.js';
import { isActivityAllowed } from '../src/activities/rules.js';
import { ajax } from '../src/ajax.js';
import { config } from '../src/config.js';
import { getGlobal } from '../src/prebidGlobal.js';
import { logError, logInfo } from '../src/utils.js';

let email;
let conf;
const LOG_PRE_FIX = 'ID-Library: ';
const CONF_DEFAULT_OBSERVER_DEBOUNCE_MS = 250;
const CONF_DEFAULT_FULL_BODY_SCAN = false;
const CONF_DEFAULT_INPUT_SCAN = false;
export const CONF_DEFAULT_FULL_BODY_SCAN = false;
export const CONF_DEFAULT_INPUT_SCAN = false;
const OBSERVER_CONFIG = {
subtree: true,
attributes: true,
Expand Down Expand Up @@ -257,6 +261,10 @@ export function setConfig(config) {
_logError('The required url is not configured');
return;
}
if (!isActivityAllowed(ACTIVITY_ENRICH_UFPD, activityParams(MODULE_TYPE_PREBID, 'idImportLibrary'))) {
_logError('Permission for id import was denied by CMP');
return;
}
if (typeof config.debounce !== 'number') {
config.debounce = CONF_DEFAULT_OBSERVER_DEBOUNCE_MS;
_logInfo('Set default observer debounce to ' + CONF_DEFAULT_OBSERVER_DEBOUNCE_MS);
Expand Down
14 changes: 14 additions & 0 deletions test/spec/modules/idImportLibrary_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import * as idImportlibrary from 'modules/idImportLibrary.js';
import {getGlobal} from '../../../src/prebidGlobal.js';
import {config} from 'src/config.js';
import {hook} from '../../../src/hook.js';
import * as activities from '../../../src/activities/rules.js';
import { ACTIVITY_ENRICH_UFPD } from '../../../src/activities/activities.js';
import { CONF_DEFAULT_FULL_BODY_SCAN, CONF_DEFAULT_INPUT_SCAN } from '../../../modules/idImportLibrary.js';

var expect = require('chai').expect;

const mockMutationObserver = {
Expand Down Expand Up @@ -86,6 +90,16 @@ describe('IdImportLibrary Tests', function () {
idImportlibrary.setConfig(config);
expect(config.inputscan).to.be.equal(true);
});
it('results when activity is not allowed', function () {
sandbox.stub(activities, 'isActivityAllowed').callsFake((activity) => {
return !(activity === ACTIVITY_ENRICH_UFPD);
});
let config = { 'url': 'URL', 'debounce': 0 };
idImportlibrary.setConfig(config);
sinon.assert.called(utils.logError);
expect(config.inputscan).to.be.not.equal(CONF_DEFAULT_INPUT_SCAN);
expect(config.fullscan).to.be.not.equal(CONF_DEFAULT_FULL_BODY_SCAN);
});
});
describe('Test with email is found', function () {
let mutationObserverStub;
Expand Down

0 comments on commit 62099b9

Please sign in to comment.