Skip to content

Commit

Permalink
String override initialization bug (#4368)
Browse files Browse the repository at this point in the history
  • Loading branch information
allisonking authored Oct 31, 2023
1 parent 1a8f26b commit 628c7ea
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ The types of changes are:
### Changed
- Refactor Fides.js embedded modal to not use A11y dialog [#4355](https://github.com/ethyca/fides/pull/4355)

### Fixed
- Bug where vendor opt-ins would not initialize properly based on a `fides_string` in the TCF overlay [#4368](https://github.com/ethyca/fides/pull/4368)

## [2.23.0](https://github.com/ethyca/fides/compare/2.22.1...2.23.0)

### Added
Expand Down
6 changes: 5 additions & 1 deletion clients/fides-js/src/lib/tcf/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ export const transformFidesStringToCookieKeys = (

// map tc model key to cookie key
TCF_KEY_MAP.forEach(({ tcfModelKey, cookieKey }) => {
const isVendorKey =
tcfModelKey === "vendorConsents" ||
tcfModelKey === "vendorLegitimateInterests";
if (tcfModelKey) {
const items: TcfCookieKeyConsent = {};
(tcModel[tcfModelKey] as Vector).forEach((consented, id) => {
items[id] = consented;
const key = isVendorKey ? `gvl.${id}` : id;
items[key] = consented;
});
cookieKeys[cookieKey] = items;
}
Expand Down
51 changes: 47 additions & 4 deletions clients/privacy-center/cypress/e2e/consent-banner-tcf.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const SYSTEM_1 = {
served_notice_history_id: "ser_5b1bc497-b4ba-489d-b39c-9ff352d460b0",
};
const VENDOR_1 = {
id: "2",
id: "gvl.2",
name: "Captify",
served_notice_history_id: "ser_9f3641ce-9863-4a32-b4db-ef1aac9046db",
};
Expand Down Expand Up @@ -1357,9 +1357,10 @@ describe("Fides-js TCF", () => {
[PURPOSE_2.id]: true,
1: false,
});
const vendorIdOnly = VENDOR_1.id.split(".")[1];
expect(tcData.vendor.consents).to.eql({
1: false,
[VENDOR_1.id]: true,
[vendorIdOnly]: true,
});
expect(tcData.vendor.legitimateInterests).to.eql({});
});
Expand Down Expand Up @@ -1421,9 +1422,10 @@ describe("Fides-js TCF", () => {
[PURPOSE_2.id]: true,
1: false,
});
const vendorIdOnly = VENDOR_1.id.split(".")[1];
expect(tcData.vendor.consents).to.eql({
1: false,
[VENDOR_1.id]: true,
[vendorIdOnly]: true,
});
expect(tcData.vendor.legitimateInterests).to.eql({});
});
Expand Down Expand Up @@ -1552,9 +1554,10 @@ describe("Fides-js TCF", () => {
[PURPOSE_2.id]: true,
1: false,
});
const vendorIdOnly = VENDOR_1.id.split(".")[1];
expect(tcData.vendor.consents).to.eql({
1: false,
[VENDOR_1.id]: true,
[vendorIdOnly]: true,
});
expect(tcData.vendor.legitimateInterests).to.eql({});
expect(tcData.specialFeatureOptins).to.eql({
Expand Down Expand Up @@ -1934,6 +1937,46 @@ describe("Fides-js TCF", () => {
expect(tcData.vendor.legitimateInterests).to.eql({});
});
});
it("can use a fides_string to override a vendor consent", () => {
// Opts in to all
const fidesStringOverride =
"CP0gqMAP0gqMAGXABBENATEIABaAAEAAAAAAABEAAAAA,1~";
cy.fixture("consent/experience_tcf.json").then((experience) => {
stubConfig({
options: {
isOverlayEnabled: true,
tcfEnabled: true,
fidesString: fidesStringOverride,
},
experience: experience.items[0],
});
});
cy.window().then((win) => {
win.__tcfapi("addEventListener", 2, cy.stub().as("TCFEvent"));
});
// Open the modal
cy.get("#fides-modal-link").click();

// Verify the vendor toggle
// this vendor is set to null in the experience but true in the string
cy.get("#fides-tab-Vendors").click();
cy.getByTestId(`toggle-${VENDOR_1.name}-consent`).within(() => {
cy.get("input").should("be.checked");
});

// verify CMP API
cy.get("@TCFEvent")
.its("lastCall.args")
.then(([tcData, success]) => {
expect(success).to.eql(true);
expect(tcData.eventStatus).to.eql("cmpuishown");
expect(tcData.vendor.consents).to.eql({
1: false,
2: true,
});
expect(tcData.vendor.legitimateInterests).to.eql({});
});
});
});

describe("fides_string override options", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@
],
"tcf_vendor_consents": [
{
"id": "2",
"id": "gvl.2",
"has_vendor_id": true,
"name": "Captify",
"description": "A longer description",
Expand Down Expand Up @@ -314,7 +314,7 @@
{
"cookie_max_age_seconds": 360000,
"cookie_refresh": true,
"id": "2",
"id": "gvl.2",
"has_vendor_id": true,
"name": "Captify",
"description": "A longer description",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"purpose_consent": null,
"purpose_legitimate_interests": null,
"special_purpose": null,
"vendor_consent": "2",
"vendor_consent": "gvl.2",
"vendor_legitimate_interests": null,
"feature": null,
"special_feature": null,
Expand Down

0 comments on commit 628c7ea

Please sign in to comment.