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

usnat backwards compatibility #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions modules/cmpapi/src/encoder/segment/UsNatCoreSegment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@ export class UsNatCoreSegment extends AbstractLazilyEncodableSegment<EncodableBi
}
try {
let bitString: string = this.base64UrlEncoder.decode(encodedString);

// Necessary to maintain backwards compatibility when sensitive data processing changed from a
// length of 12 to 16 and known child sensitive data consents changed from a length of 2 to 3 in the
// DE, IA, NE, NH, NJ, TN release
if (bitString.length == 66) {
bitString =
bitString.substring(0, 48) + "00000000" + bitString.substring(48, 52) + "00" + bitString.substring(52, 62);
}

this.bitStringEncoder.decode(bitString, this.getFieldNames(), fields);
} catch (e) {
throw new DecodingError("Unable to decode UsNatCoreSegment '" + encodedString + "'");
Expand Down
55 changes: 55 additions & 0 deletions modules/cmpapi/test/GppModel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { GppModel } from "../src/encoder/GppModel";
import { expect } from "chai";
import { TcfCaV1Field } from "../src/encoder/field/TcfCaV1Field";
import { UspV1Field } from "../src/encoder/field/UspV1Field";
import { UspV1 } from "../src/encoder/section/UspV1";
import { UsNat } from "../src/encoder/section/UsNat";
import { UsNatField } from "../src/encoder/field/UsNatField";

let utcDateTime = new Date("2022-01-01T00:00:00Z");

Expand Down Expand Up @@ -706,6 +709,58 @@ describe("manifest.GppModel", (): void => {
expect(gppModel.getFieldValue("tcfeuv2", "VendorConsents")).to.eql([1, 173, 722]);
});

it("should decode DBABTA~1YYN", (): void => {
let gppString = "DBABTA~1YYN";
let gppModel = new GppModel(gppString);
gppModel.getFieldValue(UspV1.NAME, UspV1Field.VERSION);
});

it("should decode DBABLA~BVQqAAAAAgA.QA", (): void => {
let gppString = "DBABLA~BVQqAAAAAgA.QA";
let gppModel = new GppModel(gppString);
gppModel.getFieldValue(UsNat.NAME, UspV1Field.VERSION);
});

it("should decode DBABLA~BAAAAAAAAQA.QA", (): void => {
let gppString = "DBABLA~BAAAAAAAAQA.QA";
let gppModel = new GppModel(gppString);
gppModel.getFieldValue(UsNat.NAME, UspV1Field.VERSION);
expect(gppModel.getFieldValue(UsNat.NAME, UsNatField.SENSITIVE_DATA_PROCESSING)).to.eql([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
]);
expect(gppModel.getFieldValue(UsNat.NAME, UsNatField.KNOWN_CHILD_SENSITIVE_DATA_CONSENTS)).to.eql([0, 0, 0]);
});

it("should decode DBABLA~BAAAAAAAAABA.QA", (): void => {
let gppString = "DBABLA~BAAAAAAAAABA.QA";
let gppModel = new GppModel(gppString);
gppModel.getFieldValue(UsNat.NAME, UspV1Field.VERSION);
expect(gppModel.getFieldValue(UsNat.NAME, UsNatField.SENSITIVE_DATA_PROCESSING)).to.eql([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
]);
expect(gppModel.getFieldValue(UsNat.NAME, UsNatField.KNOWN_CHILD_SENSITIVE_DATA_CONSENTS)).to.eql([0, 0, 0]);
});

it("should decode DBABLA~BAAAAAABEQA.QA", (): void => {
let gppString = "DBABLA~BAAAAAABEQA.QA";
let gppModel = new GppModel(gppString);
gppModel.getFieldValue(UsNat.NAME, UspV1Field.VERSION);
expect(gppModel.getFieldValue(UsNat.NAME, UsNatField.SENSITIVE_DATA_PROCESSING)).to.eql([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
]);
expect(gppModel.getFieldValue(UsNat.NAME, UsNatField.KNOWN_CHILD_SENSITIVE_DATA_CONSENTS)).to.eql([0, 1, 0]);
});

it("should decode DBABLA~BAAAAAAAAQRA.QA", (): void => {
let gppString = "DBABLA~BAAAAAAAAQRA.QA";
let gppModel = new GppModel(gppString);
gppModel.getFieldValue(UsNat.NAME, UspV1Field.VERSION);
expect(gppModel.getFieldValue(UsNat.NAME, UsNatField.SENSITIVE_DATA_PROCESSING)).to.eql([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
]);
expect(gppModel.getFieldValue(UsNat.NAME, UsNatField.KNOWN_CHILD_SENSITIVE_DATA_CONSENTS)).to.eql([0, 0, 1]);
});

it("should decode and encode consistently", (): void => {
let fromObjectModel = new GppModel();
fromObjectModel.setFieldValue("tcfeuv2", "PurposeConsents", [
Expand Down