Skip to content

Commit

Permalink
Added support for multiple adobe_mc parameters.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Snyder committed Jan 2, 2024
1 parent 74f69ba commit a805174
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,17 @@ export default ({ locationSearch, dateProvider, orgId, logger }) => payload => {
}

const parsedQueryString = queryString.parse(locationSearch);
const queryStringValue = parsedQueryString[queryStringIdentityParam];
let queryStringValue = parsedQueryString[queryStringIdentityParam];

if (queryStringValue === undefined) {
return;
}
if (Array.isArray(queryStringValue)) {
logger.warn(
"Found multiple adobe_mc query string paramters, only using the last one."
);
queryStringValue = queryStringValue[queryStringValue.length - 1];
}

const properties = queryStringValue.split("|").reduce((memo, keyValue) => {
const [key, value] = keyValue.split("=");
Expand Down
76 changes: 76 additions & 0 deletions test/functional/specs/Identity/C15325238.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
Copyright 2022 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

import { t } from "testcafe";
import createFixture from "../../helpers/createFixture";
import { SECONDARY_TEST_PAGE, TEST_PAGE } from "../../helpers/constants/url";
import {
compose,
orgMainConfigMain,
debugEnabled,
thirdPartyCookiesDisabled
} from "../../helpers/constants/configParts";
import createNetworkLogger from "../../helpers/networkLogger";
import createAlloyProxy from "../../helpers/createAlloyProxy";
import getReturnedEcid from "../../helpers/networkLogger/getReturnedEcid";

// We disable third party cookies so that the domains don't share identities
// through the demdex cookies.
const config = compose(
orgMainConfigMain,
debugEnabled,
thirdPartyCookiesDisabled
);

const networkLogger = createNetworkLogger();

createFixture({
title:
"C15325238: When there are multiple adobe_mc parameters, the last one is used.",
requestHooks: [networkLogger.edgeEndpointLogs]
});

test.meta({
ID: "C15325238",
SEVERITY: "P0",
TEST_RUN: "Regression"
});

test("C15325238: When there are multiple adobe_mc parameters, the last one is used.", async () => {
const alloy = createAlloyProxy();
await alloy.configure(config);
await alloy.sendEvent({});
const { url: newUrl1 } = await alloy.appendIdentityToUrl({
url: TEST_PAGE
});

await t.navigateTo(SECONDARY_TEST_PAGE);
await alloy.configure(config);
await alloy.sendEvent({});

const { url: newUrl2 } = await alloy.appendIdentityToUrl({
url: newUrl1
});

await t.navigateTo(newUrl2);
await alloy.configure(config);
await alloy.sendEvent({});

const [ecid1, ecid2, ecid3] = networkLogger.edgeEndpointLogs.requests.map(
getReturnedEcid
);
await t.expect(ecid1).notEql(ecid2);
await t.expect(ecid2).eql(ecid3);

const { identity } = await alloy.getIdentity();
await t.expect(identity.ECID).eql(ecid2);
});
1 change: 0 additions & 1 deletion test/functional/specs/Identity/C5594865.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ const config = compose(
const networkLogger = createNetworkLogger();

createFixture({
// url: `${TEST_PAGE_URL}?adobe_mc=${adobemc}`,
title:
"C5594865: Identity can be maintained across domains via the adobe_mc query string parameter",
requestHooks: [networkLogger.edgeEndpointLogs]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe("Identity::injectAddQueryStringIdentityToPayload", () => {
"?foo=bar&adobe_mc=TS%3D1641432103%7CMCMID%3D77094828402023918047117570965393734545%7CMCORGID%3DFAF554945B90342F0A495E2C%40AdobeOrg&a=b";
date = new Date(1641432103 * 1000);
orgId = "FAF554945B90342F0A495E2C@AdobeOrg";
logger = jasmine.createSpyObj("logger", ["info"]);
logger = jasmine.createSpyObj("logger", ["info", "warn"]);
});

const run = () => {
Expand Down Expand Up @@ -163,5 +163,28 @@ describe("Identity::injectAddQueryStringIdentityToPayload", () => {
id: "06387190804794960331430905673364101813"
});
});

it("handles multiple copies of the adobe_mc param", () => {
locationSearch =
"?adobe_mc=MCMID%3Dfirst%7CMCORGID%3Dabc%7CTS%3D1653516560&adobe_mc=MCMID%3Dsecond%7CMCORGID%3Dabc%7CTS%3D1653516560";
orgId = "abc";
date = new Date(1653516560 * 1000);
run();
expect(payload.addIdentity).toHaveBeenCalledOnceWith("ECID", {
id: "second"
});
expect(logger.warn).toHaveBeenCalled();
});

it("handles multiple copies of the adobe_mc param with empty param", () => {
locationSearch =
"?adobe_mc=MCMID%3Dfirst%7CMCORGID%3Dabc%7CTS%3D1653516560&adobe_mc=";
orgId = "abc";
date = new Date(1653516560 * 1000);
run();
expect(payload.addIdentity).not.toHaveBeenCalled();
expect(logger.warn).toHaveBeenCalled();
expect(logger.info).toHaveBeenCalled();
});
});
});

0 comments on commit a805174

Please sign in to comment.