Skip to content

Commit

Permalink
gppControl: check for usnat consent version (#12469)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgirardi authored Nov 19, 2024
1 parent b67898b commit c6bf9cb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
3 changes: 3 additions & 0 deletions libraries/mspa/activityControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ export function mspaRule(sids, getConsent, denies, applicableSids = () => gppDat
if (consent == null) {
return {allow: false, reason: 'consent data not available'};
}
if (consent.Version !== 1) {
return {allow: false, reason: `unsupported consent specification version "${consent.Version}"`}
}
if (denies(consent)) {
return {allow: false};
}
Expand Down
20 changes: 13 additions & 7 deletions test/spec/libraries/mspa/activityControls_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,18 @@ describe('mspaRule', () => {
expect(mkRule()().allow).to.equal(false);
});

it('should deny when consent is using version != 1', () => {
consent = {Version: 2};
expect(mkRule()().allow).to.equal(false);
})

Object.entries({
'denies': true,
'allows': false
}).forEach(([t, denied]) => {
it(`should check if deny fn ${t}`, () => {
denies.returns(denied);
consent = {mock: 'value'};
consent = {mock: 'value', Version: 1};
const result = mkRule()();
sinon.assert.calledWith(denies, consent);
if (denied) {
Expand All @@ -212,6 +217,7 @@ describe('setupRules', () => {
parsedSections: {
mockApi: [
{
Version: 1,
mock: 'consent'
}
]
Expand All @@ -226,14 +232,14 @@ describe('setupRules', () => {
it('should use flatten section data for the given api', () => {
runSetup('mockApi', [1]);
expect(isAllowed('mockActivity', {})).to.equal(false);
sinon.assert.calledWith(rules.mockActivity, {mock: 'consent'})
sinon.assert.calledWith(rules.mockActivity, consent.parsedSections.mockApi[0])
});

it('should accept already flattened section data', () => {
consent.parsedSections.mockApi = {flat: 'consent'};
consent.parsedSections.mockApi = {flat: 'consent', Version: 1};
runSetup('mockApi', [1]);
isAllowed('mockActivity', {});
sinon.assert.calledWith(rules.mockActivity, {flat: 'consent'})
sinon.assert.calledWith(rules.mockActivity, consent.parsedSections.mockApi)
})

it('should not choke when no consent data is available', () => {
Expand All @@ -248,11 +254,11 @@ describe('setupRules', () => {
});

it('should pass flattened consent through normalizeConsent', () => {
const normalize = sinon.stub().returns({normalized: 'consent'})
const normalize = sinon.stub().returns({normalized: 'consent', Version: 1})
runSetup('mockApi', [1], normalize);
expect(isAllowed('mockActivity', {})).to.equal(false);
sinon.assert.calledWith(normalize, {mock: 'consent'});
sinon.assert.calledWith(rules.mockActivity, {normalized: 'consent'});
sinon.assert.calledWith(normalize, {mock: 'consent', Version: 1});
sinon.assert.calledWith(rules.mockActivity, {normalized: 'consent', Version: 1});
});

it('should return a function that unregisters activity controls', () => {
Expand Down

0 comments on commit c6bf9cb

Please sign in to comment.