From 557845feeaffe4ad3dcda4c8bbb31d66e03bf83a Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Tue, 5 Dec 2023 23:59:55 +0000 Subject: [PATCH 1/6] test(shared-ini-file-loader): profile name containing config file separator --- packages/shared-ini-file-loader/src/getConfigData.spec.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/shared-ini-file-loader/src/getConfigData.spec.ts b/packages/shared-ini-file-loader/src/getConfigData.spec.ts index 5064e652a32..675797d9cf5 100644 --- a/packages/shared-ini-file-loader/src/getConfigData.spec.ts +++ b/packages/shared-ini-file-loader/src/getConfigData.spec.ts @@ -21,6 +21,11 @@ describe(getConfigData.name, () => { it.each([IniSectionType.SSO_SESSION, IniSectionType.SERVICES])("includes sections with '%s' prefix", (prefix) => { const mockInput = { [[prefix, "test"].join(CONFIG_PREFIX_SEPARATOR)]: { key: "value" } }; expect(getConfigData(mockInput)).toStrictEqual(mockInput); + + // Profile name containing CONFIG_PREFIX_SEPARATOR + const profileName = ["foo", "bar"].join(CONFIG_PREFIX_SEPARATOR); + const mockInput2 = { [[prefix, profileName].join(CONFIG_PREFIX_SEPARATOR)]: { key: "value" } }; + expect(getConfigData(mockInput2)).toStrictEqual(mockInput2); }); describe("normalizes profile names", () => { From 5f63cf6acfc4a4482565127a5c15a7677be11f27 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Wed, 6 Dec 2023 00:08:32 +0000 Subject: [PATCH 2/6] fix(shared-ini-file-loader): validate IniSectionType for profile names containing config prefix separator --- packages/shared-ini-file-loader/src/getConfigData.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/shared-ini-file-loader/src/getConfigData.ts b/packages/shared-ini-file-loader/src/getConfigData.ts index bbf0b70054f..c72bae0a99b 100644 --- a/packages/shared-ini-file-loader/src/getConfigData.ts +++ b/packages/shared-ini-file-loader/src/getConfigData.ts @@ -10,13 +10,13 @@ import { CONFIG_PREFIX_SEPARATOR } from "./loadSharedConfigFiles"; */ export const getConfigData = (data: ParsedIniData): ParsedIniData => Object.entries(data) - // filter out .filter(([key]) => { - const sections = key.split(CONFIG_PREFIX_SEPARATOR); - if (sections.length === 2 && Object.values(IniSectionType).includes(sections[0] as IniSectionType)) { - return true; + if (key.indexOf(CONFIG_PREFIX_SEPARATOR) === -1) { + // filter out keys which do not contain CONFIG_PREFIX_SEPARATOR. + return false; } - return false; + // Check if prefix is a valid IniSectionType. + return Object.values(IniSectionType).includes(key.split(CONFIG_PREFIX_SEPARATOR)[0] as IniSectionType); }) // replace profile prefix, if present. .reduce( From 032ec02674f4091adf48125838b754fdeffa77aa Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Wed, 6 Dec 2023 00:09:18 +0000 Subject: [PATCH 3/6] chore: yarn changeset --- .changeset/sharp-pants-hug.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/sharp-pants-hug.md diff --git a/.changeset/sharp-pants-hug.md b/.changeset/sharp-pants-hug.md new file mode 100644 index 00000000000..dfc0790a626 --- /dev/null +++ b/.changeset/sharp-pants-hug.md @@ -0,0 +1,5 @@ +--- +"@smithy/shared-ini-file-loader": patch +--- + +Validate IniSectionType for profile names containing config prefix separator From a7258d791f98077e290966ebd2cabbcda9d2f6bc Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Wed, 6 Dec 2023 00:15:25 +0000 Subject: [PATCH 4/6] test: profile containing CONFIG_PREFIX_SEPARATOR --- packages/shared-ini-file-loader/src/getConfigData.spec.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/shared-ini-file-loader/src/getConfigData.spec.ts b/packages/shared-ini-file-loader/src/getConfigData.spec.ts index 675797d9cf5..401b13ffce5 100644 --- a/packages/shared-ini-file-loader/src/getConfigData.spec.ts +++ b/packages/shared-ini-file-loader/src/getConfigData.spec.ts @@ -43,6 +43,13 @@ describe(getConfigData.name, () => { {} ); + it("profile containing CONFIG_PREFIX_SEPARATOR", () => { + const profileName = ["foo", "bar"].join(CONFIG_PREFIX_SEPARATOR); + const mockOutput = getMockOutput([profileName]); + const mockInput = getMockInput(mockOutput); + expect(getConfigData(mockInput)).toStrictEqual(mockOutput); + }); + it("single profile", () => { const mockOutput = getMockOutput(["one"]); const mockInput = getMockInput(mockOutput); From 228f32ae3f3bb7876d653af6443a92cdb5365584 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Wed, 6 Dec 2023 00:19:23 +0000 Subject: [PATCH 5/6] fix: vremove IniSectionType.PROFILE for profile name containing separator --- packages/shared-ini-file-loader/src/getConfigData.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/shared-ini-file-loader/src/getConfigData.ts b/packages/shared-ini-file-loader/src/getConfigData.ts index c72bae0a99b..556c65fb913 100644 --- a/packages/shared-ini-file-loader/src/getConfigData.ts +++ b/packages/shared-ini-file-loader/src/getConfigData.ts @@ -11,17 +11,20 @@ import { CONFIG_PREFIX_SEPARATOR } from "./loadSharedConfigFiles"; export const getConfigData = (data: ParsedIniData): ParsedIniData => Object.entries(data) .filter(([key]) => { - if (key.indexOf(CONFIG_PREFIX_SEPARATOR) === -1) { + const indexOfSeparator = key.indexOf(CONFIG_PREFIX_SEPARATOR); + if (indexOfSeparator === -1) { // filter out keys which do not contain CONFIG_PREFIX_SEPARATOR. return false; } // Check if prefix is a valid IniSectionType. - return Object.values(IniSectionType).includes(key.split(CONFIG_PREFIX_SEPARATOR)[0] as IniSectionType); + return Object.values(IniSectionType).includes(key.substring(0, indexOfSeparator) as IniSectionType); }) - // replace profile prefix, if present. + // remove profile prefix, if present. .reduce( (acc, [key, value]) => { - const updatedKey = key.startsWith(IniSectionType.PROFILE) ? key.split(CONFIG_PREFIX_SEPARATOR)[1] : key; + const indexOfSeparator = key.indexOf(CONFIG_PREFIX_SEPARATOR); + const updatedKey = + key.substring(0, indexOfSeparator) === IniSectionType.PROFILE ? key.substring(indexOfSeparator + 1) : key; acc[updatedKey] = value; return acc; }, From f28b0fb2419b536dd9991a24891aa4cbdb2c7fd0 Mon Sep 17 00:00:00 2001 From: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Date: Tue, 5 Dec 2023 16:22:18 -0800 Subject: [PATCH 6/6] chore: update changelog --- .changeset/sharp-pants-hug.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/sharp-pants-hug.md b/.changeset/sharp-pants-hug.md index dfc0790a626..fbb00b3a6de 100644 --- a/.changeset/sharp-pants-hug.md +++ b/.changeset/sharp-pants-hug.md @@ -2,4 +2,4 @@ "@smithy/shared-ini-file-loader": patch --- -Validate IniSectionType for profile names containing config prefix separator +Process config files for profile names containing prefix separator