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

gppControl: check for usnat consent version #12469

Merged
merged 1 commit into from
Nov 19, 2024
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
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