|
1 |
| -import { isFipsRegion } from "../regionConfig/isFipsRegion"; |
2 | 1 | import { getResolvedSigningRegion } from "./getResolvedSigningRegion";
|
3 | 2 |
|
4 |
| -jest.mock("../regionConfig/isFipsRegion"); |
5 |
| - |
6 | 3 | describe(getResolvedSigningRegion.name, () => {
|
7 |
| - const mockRegion = "mockRegion"; |
8 | 4 | const mockSigningRegion = "mockSigningRegion";
|
9 | 5 | const mockHostname = "mockHostname";
|
10 | 6 | const mockRegionRegex = "mockRegionRegex";
|
11 | 7 |
|
12 | 8 | const mockOptions = {
|
13 |
| - hostname: mockHostname, |
14 | 9 | regionRegex: mockRegionRegex,
|
| 10 | + useFipsEndpoint: false, |
15 | 11 | };
|
16 | 12 |
|
17 |
| - beforeEach(() => { |
18 |
| - (isFipsRegion as jest.Mock).mockReturnValue(false); |
19 |
| - }); |
20 |
| - |
21 |
| - afterEach(() => { |
22 |
| - jest.clearAllMocks(); |
23 |
| - }); |
24 |
| - |
25 | 13 | it("returns signingRegion if passed in options", () => {
|
26 |
| - expect(getResolvedSigningRegion(mockRegion, { ...mockOptions, signingRegion: mockSigningRegion })).toEqual( |
| 14 | + expect(getResolvedSigningRegion(mockHostname, { ...mockOptions, signingRegion: mockSigningRegion })).toEqual( |
27 | 15 | mockSigningRegion
|
28 | 16 | );
|
29 |
| - expect(isFipsRegion).not.toHaveBeenCalled(); |
30 | 17 | });
|
31 | 18 |
|
32 | 19 | describe("returns undefined if signingRegion is not present and", () => {
|
33 | 20 | it("region is not FIPS", () => {
|
34 |
| - expect(getResolvedSigningRegion(mockRegion, mockOptions)).not.toBeDefined(); |
35 |
| - expect(isFipsRegion).toHaveBeenCalledTimes(1); |
36 |
| - expect(isFipsRegion).toHaveBeenCalledWith(mockRegion); |
| 21 | + expect(getResolvedSigningRegion(mockHostname, mockOptions)).not.toBeDefined(); |
37 | 22 | });
|
38 | 23 |
|
39 | 24 | it("regionRegex does not return a match in hostname", () => {
|
40 |
| - (isFipsRegion as jest.Mock).mockReturnValueOnce(true); |
41 | 25 | const matchSpy = jest.spyOn(String.prototype, "match").mockReturnValueOnce(null);
|
42 | 26 |
|
43 |
| - expect(getResolvedSigningRegion(mockRegion, mockOptions)).not.toBeDefined(); |
| 27 | + expect(getResolvedSigningRegion(mockHostname, { ...mockOptions, useFipsEndpoint: true })).not.toBeDefined(); |
44 | 28 | expect(matchSpy).toHaveBeenCalledTimes(1);
|
45 | 29 | expect(matchSpy).toHaveBeenCalledWith(mockRegionRegex);
|
46 |
| - expect(isFipsRegion).toHaveBeenCalledTimes(1); |
47 |
| - expect(isFipsRegion).toHaveBeenCalledWith(mockRegion); |
48 | 30 | });
|
49 | 31 |
|
50 | 32 | it("region is not present between dots in a hostname", () => {
|
51 | 33 | const regionInHostname = "us-east-1";
|
52 |
| - (isFipsRegion as jest.Mock).mockReturnValueOnce(true); |
53 | 34 |
|
54 | 35 | expect(
|
55 |
| - getResolvedSigningRegion(mockRegion, { |
| 36 | + getResolvedSigningRegion(`test-${regionInHostname}.amazonaws.com`, { |
56 | 37 | ...mockOptions,
|
57 |
| - hostname: `test-${regionInHostname}.amazonaws.com`, |
58 | 38 | regionRegex: "^(us|eu|ap|sa|ca|me|af)\\-\\w+\\-\\d+$",
|
59 | 39 | })
|
60 | 40 | ).not.toBeDefined();
|
61 |
| - expect(isFipsRegion).toHaveBeenCalledTimes(1); |
62 |
| - expect(isFipsRegion).toHaveBeenCalledWith(mockRegion); |
63 | 41 | });
|
64 | 42 | });
|
65 | 43 |
|
66 | 44 | it("returns region from hostname if signingRegion is not present", () => {
|
67 | 45 | const regionInHostname = "us-east-1";
|
68 |
| - (isFipsRegion as jest.Mock).mockReturnValueOnce(true); |
69 | 46 |
|
70 | 47 | expect(
|
71 |
| - getResolvedSigningRegion(mockRegion, { |
| 48 | + getResolvedSigningRegion(`test.${regionInHostname}.amazonaws.com`, { |
72 | 49 | ...mockOptions,
|
73 |
| - hostname: `test.${regionInHostname}.amazonaws.com`, |
74 | 50 | regionRegex: "^(us|eu|ap|sa|ca|me|af)\\-\\w+\\-\\d+$",
|
| 51 | + useFipsEndpoint: true, |
75 | 52 | })
|
76 | 53 | ).toEqual(regionInHostname);
|
77 |
| - expect(isFipsRegion).toHaveBeenCalledTimes(1); |
78 |
| - expect(isFipsRegion).toHaveBeenCalledWith(mockRegion); |
79 | 54 | });
|
80 | 55 | });
|
0 commit comments