• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

prebid / Prebid.js / #306

01 Jul 2025 06:03PM UTC coverage: 90.335% (-0.07%) from 90.409%
#306

push

travis-ci

prebidjs-release
Prebid 9.53.1 release

43587 of 54762 branches covered (79.59%)

64461 of 71358 relevant lines covered (90.33%)

148.96 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.12
/modules/dsaControl.js
1
import {config} from '../src/config.js';
1✔
2
import {auctionManager} from '../src/auctionManager.js';
3
import {timedBidResponseHook} from '../src/utils/perfMetrics.js';
4
import { REJECTION_REASON } from '../src/constants.js';
5
import {getHook} from '../src/hook.js';
6
import {logInfo, logWarn} from '../src/utils.js';
7

8
let expiryHandle;
9
let dsaAuctions = {};
1✔
10

11
export const addBidResponseHook = timedBidResponseHook('dsa', function (fn, adUnitCode, bid, reject) {
1✔
12
  if (!dsaAuctions.hasOwnProperty(bid.auctionId)) {
16!
13
    dsaAuctions[bid.auctionId] = auctionManager.index.getAuction(bid)?.getFPD?.()?.global?.regs?.ext?.dsa;
16✔
14
  }
15
  const dsaRequest = dsaAuctions[bid.auctionId];
16✔
16
  let rejectReason;
17
  if (dsaRequest) {
16✔
18
    if (!bid.meta?.dsa) {
15✔
19
      if (dsaRequest.dsarequired === 1) {
5✔
20
        // request says dsa is supported; response does not have dsa info; warn about it
21
        logWarn(`dsaControl: ${REJECTION_REASON.DSA_REQUIRED}; will still be accepted as regs.ext.dsa.dsarequired = 1`, bid);
1✔
22
      } else if ([2, 3].includes(dsaRequest.dsarequired)) {
4✔
23
        // request says dsa is required; response does not have dsa info; reject it
24
        rejectReason = REJECTION_REASON.DSA_REQUIRED;
2✔
25
      }
26
    } else {
27
      if (dsaRequest.pubrender === 0 && bid.meta.dsa.adrender === 0) {
10✔
28
        // request says publisher can't render; response says advertiser won't; reject it
29
        rejectReason = REJECTION_REASON.DSA_MISMATCH;
2✔
30
      } else if (dsaRequest.pubrender === 2 && bid.meta.dsa.adrender === 1) {
8✔
31
        // request says publisher will render; response says advertiser will; reject it
32
        rejectReason = REJECTION_REASON.DSA_MISMATCH;
2✔
33
      }
34
    }
35
  }
36
  if (rejectReason) {
16✔
37
    reject(rejectReason);
6✔
38
  } else {
39
    return fn.call(this, adUnitCode, bid, reject);
10✔
40
  }
41
});
42

43
function toggleHooks(enabled) {
44
  if (enabled && expiryHandle == null) {
17✔
45
    getHook('addBidResponse').before(addBidResponseHook);
1✔
46
    expiryHandle = auctionManager.onExpiry(auction => {
1✔
47
      delete dsaAuctions[auction.getAuctionId()];
×
48
    });
49
    logInfo('dsaControl: DSA bid validation is enabled')
1✔
50
  } else if (!enabled && expiryHandle != null) {
16✔
51
    getHook('addBidResponse').getHooks({hook: addBidResponseHook}).remove();
1✔
52
    expiryHandle();
1✔
53
    expiryHandle = null;
1✔
54
    logInfo('dsaControl: DSA bid validation is disabled')
1✔
55
  }
56
}
57

58
export function reset() {
59
  toggleHooks(false);
16✔
60
  dsaAuctions = {};
16✔
61
}
62

63
toggleHooks(true);
1✔
64

65
config.getConfig('consentManagement', (cfg) => {
1✔
66
  toggleHooks(cfg.consentManagement?.dsa?.validateBids ?? true);
×
67
});
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc