-
Notifications
You must be signed in to change notification settings - Fork 619
fix(config-resolver): get signingRegion from regionRegex if not present for FIPS #2936
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e415496
chore(config-resolver): add utility isFipsRegion
trivikr a0735ab
chore: get signingRegion from regionRegex
trivikr 5098cc9
chore: move getSigningRegion to new file
trivikr 4981e1b
chore(config-resolver): rename getSigningRegion to getResolvedSigning…
trivikr 7f5f5f5
chore: pass optional signingRegion to getResolvedSigningRegion
trivikr 679b306
test(config-resolver): getResolvedSigningRegion call in getRegionInfo
trivikr 6f49282
test(config-resolver): getResolvedSigningRegion.spec.ts
trivikr c6076d2
chore(functional): move test cases which use regionRegex to supported
trivikr c85f9db
fix(config-resolver): check for dot before and after regionRegex match
trivikr 57644ef
fix(config-resolver): test for dot character before and after regionr…
trivikr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
packages/config-resolver/src/regionInfo/getResolvedSigningRegion.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { getResolvedSigningRegion } from "./getResolvedSigningRegion"; | ||
import { isFipsRegion } from "./isFipsRegion"; | ||
|
||
jest.mock("./isFipsRegion"); | ||
|
||
describe(getResolvedSigningRegion.name, () => { | ||
const mockRegion = "mockRegion"; | ||
const mockSigningRegion = "mockSigningRegion"; | ||
const mockHostname = "mockHostname"; | ||
const mockRegionRegex = "mockRegionRegex"; | ||
|
||
const mockOptions = { | ||
hostname: mockHostname, | ||
regionRegex: mockRegionRegex, | ||
}; | ||
|
||
beforeEach(() => { | ||
(isFipsRegion as jest.Mock).mockReturnValue(false); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it("returns signingRegion if passed in options", () => { | ||
expect(getResolvedSigningRegion(mockRegion, { ...mockOptions, signingRegion: mockSigningRegion })).toEqual( | ||
mockSigningRegion | ||
); | ||
expect(isFipsRegion).not.toHaveBeenCalled(); | ||
}); | ||
|
||
describe("returns undefined if signingRegion is not present and", () => { | ||
it("region is not FIPS", () => { | ||
expect(getResolvedSigningRegion(mockRegion, mockOptions)).not.toBeDefined(); | ||
expect(isFipsRegion).toHaveBeenCalledTimes(1); | ||
expect(isFipsRegion).toHaveBeenCalledWith(mockRegion); | ||
}); | ||
|
||
it("regionRegex does not return a match in hostname", () => { | ||
(isFipsRegion as jest.Mock).mockReturnValueOnce(true); | ||
const matchSpy = jest.spyOn(String.prototype, "match").mockReturnValueOnce(null); | ||
|
||
expect(getResolvedSigningRegion(mockRegion, mockOptions)).not.toBeDefined(); | ||
expect(matchSpy).toHaveBeenCalledTimes(1); | ||
expect(matchSpy).toHaveBeenCalledWith(mockRegionRegex); | ||
expect(isFipsRegion).toHaveBeenCalledTimes(1); | ||
expect(isFipsRegion).toHaveBeenCalledWith(mockRegion); | ||
}); | ||
|
||
it("region is not present between dots in a hostname", () => { | ||
const regionInHostname = "us-east-1"; | ||
(isFipsRegion as jest.Mock).mockReturnValueOnce(true); | ||
|
||
expect( | ||
getResolvedSigningRegion(mockRegion, { | ||
...mockOptions, | ||
hostname: `test-${regionInHostname}.amazonaws.com`, | ||
regionRegex: "^(us|eu|ap|sa|ca|me|af)\\-\\w+\\-\\d+$", | ||
}) | ||
).not.toBeDefined(); | ||
expect(isFipsRegion).toHaveBeenCalledTimes(1); | ||
expect(isFipsRegion).toHaveBeenCalledWith(mockRegion); | ||
}); | ||
}); | ||
|
||
it("returns region from hostname if signingRegion is not present", () => { | ||
const regionInHostname = "us-east-1"; | ||
(isFipsRegion as jest.Mock).mockReturnValueOnce(true); | ||
|
||
expect( | ||
getResolvedSigningRegion(mockRegion, { | ||
...mockOptions, | ||
hostname: `test.${regionInHostname}.amazonaws.com`, | ||
regionRegex: "^(us|eu|ap|sa|ca|me|af)\\-\\w+\\-\\d+$", | ||
}) | ||
).toEqual(regionInHostname); | ||
expect(isFipsRegion).toHaveBeenCalledTimes(1); | ||
expect(isFipsRegion).toHaveBeenCalledWith(mockRegion); | ||
}); | ||
}); |
22 changes: 22 additions & 0 deletions
22
packages/config-resolver/src/regionInfo/getResolvedSigningRegion.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { isFipsRegion } from "./isFipsRegion"; | ||
|
||
export interface GetResolvedSigningRegionOptions { | ||
hostname: string; | ||
regionRegex: string; | ||
signingRegion?: string; | ||
} | ||
|
||
export const getResolvedSigningRegion = ( | ||
region: string, | ||
{ hostname, signingRegion, regionRegex }: GetResolvedSigningRegionOptions | ||
) => { | ||
if (signingRegion) { | ||
return signingRegion; | ||
} else if (isFipsRegion(region)) { | ||
const regionRegexJs = regionRegex.replace("\\\\", "\\").replace(/^\^/g, "\\.").replace(/\$$/g, "\\."); | ||
const regionRegexmatchArray = hostname.match(regionRegexJs); | ||
if (regionRegexmatchArray) { | ||
return regionRegexmatchArray[0].slice(1, -1); | ||
} | ||
} | ||
}; |
15 changes: 15 additions & 0 deletions
15
packages/config-resolver/src/regionInfo/isFipsRegion.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { isFipsRegion } from "./isFipsRegion"; | ||
|
||
describe(isFipsRegion.name, () => { | ||
it.each([ | ||
[true, "fips-us-east-1"], | ||
[true, "us-east-1-fips"], | ||
[false, "us-east-1"], | ||
])(`returns %s for region "%s"`, (output, input) => { | ||
expect(isFipsRegion(input)).toEqual(output); | ||
}); | ||
|
||
it.each([undefined, null])("returns false for %s", (input) => { | ||
expect(isFipsRegion(input)).toEqual(false); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const isFipsRegion = (region: string) => | ||
typeof region === "string" && (region.startsWith("fips-") || region.endsWith("-fips")); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.