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

Build system: do not allow cross-module imports #8293

Merged
merged 8 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 9 additions & 10 deletions modules/audiencerunBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import {
_each,
deepAccess,
isFn,
logError,
getValue,
formatQS,
getBidIdParameter,
_each,
getValue,
isArray,
isFn,
logError,
triggerPixel,
formatQS,
} from '../src/utils.js';
import { config } from '../src/config.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER } from '../src/mediaTypes.js';
import { createEidsArray } from './userId/eids.js';
import {config} from '../src/config.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER} from '../src/mediaTypes.js';

const BIDDER_CODE = 'audiencerun';
const BASE_URL = 'https://d.audiencerun.com';
Expand Down Expand Up @@ -135,7 +134,7 @@ export const spec = {

payload.uspConsent = deepAccess(bidderRequest, 'uspConsent');
payload.schain = deepAccess(bidRequests, '0.schain');
payload.userId = deepAccess(bidRequests, '0.userId') ? createEidsArray(bidRequests[0].userId) : [];
payload.userId = deepAccess(bidRequests, '0.userIdAsEids') || []

if (bidderRequest && bidderRequest.gdprConsent) {
payload.gdpr = {
Expand Down
9 changes: 3 additions & 6 deletions modules/jixieBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {BANNER, VIDEO} from '../src/mediaTypes.js';
import {ajax} from '../src/ajax.js';
import {getRefererInfo} from '../src/refererDetection.js';
import {Renderer} from '../src/Renderer.js';
import {createEidsArray} from './userId/eids.js';

const BIDDER_CODE = 'jixie';
export const storage = getStorageManager({bidderCode: BIDDER_CODE});
Expand Down Expand Up @@ -190,12 +189,10 @@ export const spec = {
let miscDims = internal.getMiscDims();
let schain = deepAccess(validBidRequests[0], 'schain');

let eids1 = validBidRequests[0].userIdAsEids
// all available user ids are sent to our backend in the standard array layout:
if (validBidRequests[0].userId) {
let eids1 = createEidsArray(validBidRequests[0].userId);
if (eids1.length) {
eids = eids1;
}
if (eids1 && eids1.length) {
eids = eids1;
}
// we want to send this blob of info to our backend:
let pg = config.getConfig('priceGranularity');
Expand Down
27 changes: 13 additions & 14 deletions plugins/eslint/validateImports.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@

let path = require('path');
let _ = require('lodash');
let resolveFrom = require('resolve-from');
const path = require('path');
const _ = require('lodash');
const resolveFrom = require('resolve-from');
const MODULES_PATH = path.resolve(__dirname, '../../modules');

function isInDirectory(filename, dir) {
const rel = path.relative(dir, filename);
return rel && !rel.startsWith('..') && !path.isAbsolute(rel);
}

function flagErrors(context, node, importPath) {
let absFileDir = path.dirname(context.getFilename());
let absImportPath = path.resolve(absFileDir, importPath);
let absImportPath = importPath.startsWith('.') ? path.resolve(absFileDir, importPath) : require.resolve(importPath);

try {
resolveFrom(absFileDir, importPath);
Expand All @@ -20,16 +26,9 @@ function flagErrors(context, node, importPath) {
) {
context.report(node, `import "${importPath}" not in import whitelist`);
} else {
let absModulePath = path.resolve(__dirname, '../../modules');

// don't allow import of any files directly within modules folder or index.js files within modules' sub-folders
if (
path.dirname(absImportPath) === absModulePath || (
absImportPath.startsWith(absModulePath) &&
path.basename(absImportPath) === 'index.js'
)
) {
context.report(node, `import "${importPath}" cannot require module entry point`);
// do not allow cross-module imports
if (isInDirectory(absImportPath, MODULES_PATH) && (!isInDirectory(absImportPath, absFileDir) || absFileDir === MODULES_PATH)) {
context.report(node, `import "${importPath}": importing from modules is not allowed`);
}

// don't allow extension-less local imports
Expand Down
19 changes: 8 additions & 11 deletions test/spec/modules/audiencerunBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,16 +218,7 @@ describe('AudienceRun bid adapter tests', function () {

it('should add userid eids information to the request', function () {
const bid = Object.assign({}, bidRequest);
bid.userId = {
pubcid: '01EAJWWNEPN3CYMM5N8M5VXY22',
unsuported: '666',
}

const request = spec.buildRequests([bid]);
const payload = JSON.parse(request.data);

expect(payload.userId).to.exist;
expect(payload.userId).to.deep.equal([
bid.userIdAsEids = [
{
source: 'pubcid.org',
uids: [
Expand All @@ -237,7 +228,13 @@ describe('AudienceRun bid adapter tests', function () {
},
],
},
]);
];

const request = spec.buildRequests([bid]);
const payload = JSON.parse(request.data);

expect(payload.userId).to.exist;
expect(payload.userId).to.deep.equal(bid.userIdAsEids);
});

it('should add schain object if available', function() {
Expand Down
102 changes: 42 additions & 60 deletions test/spec/modules/jixieBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,71 +309,53 @@ describe('jixie Adapter', function () {

it('should populate eids when supported userIds are available', function () {
const oneSpecialBidReq = Object.assign({}, bidRequests_[0], {
userId: {
tdid: '11111111-2222-3333-4444-555555555555',
uid2: { id: 'AbCdEfGhIjKlMnO9qdQBW7qtMw8f1WTUvtkHe6u+fqLfhbtsqrJ697Z6YoI3IB9klGUv1wvlFIbwH7ELDlqQBGtj8AC1v7fMJ/Q45E7W90dts7UQLTDMLNmtHBRDXVb0Fpas4Vh3yN1jGVQNhzXC/RpGIVtZE8dCxcjfa7VfcTNcvxxxxx==' },
pubProvidedId: [{
source: 'puburl1.com',
uids: [{
id: 'pubid1',
atype: 1,
ext: {
stype: 'ppuid'
}
}]
}, {
source: 'puburl2.com',
uids: [{
id: 'pubid2'
}]
}]
}
});
const request = spec.buildRequests([oneSpecialBidReq], bidderRequest_);
const payload = JSON.parse(request.data);
expect(payload.eids).to.deep.include({
'source': 'adserver.org',
'uids': [
userIdAsEids: [
{
'id': '11111111-2222-3333-4444-555555555555',
'atype': 1,
'ext': {
'rtiPartner': 'TDID'
}
}
]
});
expect(payload.eids).to.deep.include({
'source': 'uidapi.com',
'uids': [
'source': 'adserver.org',
'uids': [
{
'id': '11111111-2222-3333-4444-555555555555',
'atype': 1,
'ext': {
'rtiPartner': 'TDID'
}
}
]
},
{
'id': 'AbCdEfGhIjKlMnO9qdQBW7qtMw8f1WTUvtkHe6u+fqLfhbtsqrJ697Z6YoI3IB9klGUv1wvlFIbwH7ELDlqQBGtj8AC1v7fMJ/Q45E7W90dts7UQLTDMLNmtHBRDXVb0Fpas4Vh3yN1jGVQNhzXC/RpGIVtZE8dCxcjfa7VfcTNcvxxxxx==',
'atype': 3
}
]
});

expect(payload.eids).to.deep.include({
'source': 'puburl1.com',
'uids': [
'source': 'uidapi.com',
'uids': [
{
'id': 'AbCdEfGhIjKlMnO9qdQBW7qtMw8f1WTUvtkHe6u+fqLfhbtsqrJ697Z6YoI3IB9klGUv1wvlFIbwH7ELDlqQBGtj8AC1v7fMJ/Q45E7W90dts7UQLTDMLNmtHBRDXVb0Fpas4Vh3yN1jGVQNhzXC/RpGIVtZE8dCxcjfa7VfcTNcvxxxxx==',
'atype': 3
}
]
},
{
'id': 'pubid1',
'atype': 1,
'ext': {
'stype': 'ppuid'
}
}
]
});

expect(payload.eids).to.deep.include({
'source': 'puburl2.com',
'uids': [
'source': 'puburl1.com',
'uids': [
{
'id': 'pubid1',
'atype': 1,
'ext': {
'stype': 'ppuid'
}
}
]
},
{
'id': 'pubid2'
}
]
'source': 'puburl2.com',
'uids': [
{
'id': 'pubid2'
}
]
},
],
});
const request = spec.buildRequests([oneSpecialBidReq], bidderRequest_);
const payload = JSON.parse(request.data);
expect(payload.eids).to.eql(oneSpecialBidReq.userIdAsEids);
});
});// describe

Expand Down