Skip to content

Commit fdbc6ba

Browse files
authored
fix: Forward user attributes to kits properly when kit blocking is enabled and unplanned UAs are allowed (#947)
1 parent 9109876 commit fdbc6ba

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

src/kitBlocking.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -460,17 +460,25 @@ export default class KitBlocker {
460460
if (!this.blockUserAttributes) {
461461
return false
462462
}
463-
if (this.blockUserAttributes) {
464-
const matchedAttributes = this.dataPlanMatchLookups['user_attributes'];
465-
if (matchedAttributes === true) {
466-
return false
467-
}
468-
if (!matchedAttributes[key]) {
469-
return true
463+
const matchedAttributes = this.dataPlanMatchLookups['user_attributes'];
464+
465+
// When additionalProperties is set to true, matchedAttributes
466+
// will be a boolean, otherwise it will return an object
467+
if (typeof matchedAttributes === 'boolean' && matchedAttributes) {
468+
return false
469+
}
470+
471+
if (typeof matchedAttributes === "object") {
472+
if (matchedAttributes[key] === true) {
473+
return false;
474+
} else {
475+
return true;
470476
}
471477
}
472478

473-
return false
479+
// When "Block unplanned user attributes" is enabled and "Allow unplanned user
480+
// attributes" is also enabled in the UI, allowing unplanned user attributes will be prioritized
481+
return false;
474482
}
475483

476484
isIdentityBlocked(key: string) {

test/src/tests-kit-blocking.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import KitBlocker from '../../src/kitBlocking';
77
import Types from '../../src/types';
88
import { DataPlanVersion } from '@mparticle/data-planning-models';
99
import fetchMock from 'fetch-mock/esm/client';
10+
import { expect } from 'chai'
1011
const { findBatch, waitForCondition, fetchMockSuccess, hasIdentifyReturned } = Utils;
1112

1213
let forwarderDefaultConfiguration = Utils.forwarderDefaultConfiguration,
@@ -616,6 +617,26 @@ describe('kit blocking', () => {
616617
})
617618
});
618619

620+
it('integration test - should not throw an error when unplanned user attributes are allowed and block.ua = true', function(done) {
621+
window.mParticle.config.kitConfigs.push(forwarderDefaultConfiguration('MockForwarder'));
622+
window.mParticle.init(apiKey, window.mParticle.config);
623+
624+
// save old data points for reset later
625+
const oldDataPoints = dataPlan.dtpn.vers.version_document.data_points;
626+
// when "Allow unplanned user attributes" is enabled, the data points returned is an empty array
627+
dataPlan.dtpn.vers.version_document.data_points = [];
628+
let kitBlocker = new KitBlocker(kitBlockerDataPlan, window.mParticle.getInstance());
629+
630+
expect(() => { kitBlocker.isAttributeKeyBlocked('unplannedAttr') }).to.not.throw(TypeError, /Cannot read properties of undefined \(reading 'unplannedAttr'\)/)
631+
// "Allow unplanned user attributes" is prioritized when blocking unplanned attributes is also enabled, hence the expected value is false
632+
expect(kitBlocker.isAttributeKeyBlocked('unplannedAttr')).to.equal(false)
633+
// reset data points
634+
dataPlan.dtpn.vers.version_document.data_points = oldDataPoints;
635+
636+
done();
637+
638+
});
639+
619640
it('integration test - should allow an unplanned attribute to be set on forwarder if additionalProperties = true and blok.ua = true', function(done) {
620641
let userAttributeDataPoint = dataPlan.dtpn.vers.version_document.data_points.find(dataPoint => {
621642
return dataPoint.match.type === 'user_attributes'

0 commit comments

Comments
 (0)