Skip to content

Commit

Permalink
fix(utils): harden routing info against bad input
Browse files Browse the repository at this point in the history
  • Loading branch information
trieloff committed Jun 3, 2024
1 parent 2dca89b commit f70acda
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,15 @@ export function getForwardedHost(fhh) {
export function extractAdobeRoutingInfo(value) {
// value is a string with key value pairs, separated by a comma
// extract program, environment and tier
const pairs = value.split(',');
const routingInfo = {};
pairs.forEach((pair) => {
const keyValue = pair.trim().split('=');
const key = keyValue[0].trim();
const val = keyValue[1].trim();
routingInfo[key] = val;
});
const routingInfo = value
.split(',')
.map((pair) => pair.trim())
.filter((pair) => pair.includes('='))
.map((pair) => pair.split('='))
.reduce((acc, [key, val]) => {
acc[key] = val;
return acc;
}, {});
return `${routingInfo.tier}-p${routingInfo.program}-e${routingInfo.environment}.adobeaemcloud.net`;
}

Expand Down
1 change: 1 addition & 0 deletions test/utils.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ describe('Test Utils', () => {

it('Extract Adobe Routing Info', () => {
assert.equal('publish-p12345-e1234.adobeaemcloud.net', extractAdobeRoutingInfo('environment=1234,program=12345,tier=publish,foo=baz'));
assert.equal('undefined-pundefined-eundefined.adobeaemcloud.net', extractAdobeRoutingInfo('nope'));
});

it('Get Subsystem', () => {
Expand Down

0 comments on commit f70acda

Please sign in to comment.