Skip to content

Commit ffe2b68

Browse files
dependabot[bot]kuhe
authored andcommitted
chore(deps-dev): bump happy-dom from 14.12.3 to 20.0.2 (#1749)
Bumps [happy-dom](https://github.com/capricorn86/happy-dom) from 14.12.3 to 20.0.2. - [Release notes](https://github.com/capricorn86/happy-dom/releases) - [Commits](capricorn86/happy-dom@v14.12.3...v20.0.2) --- updated-dependencies: - dependency-name: happy-dom dependency-version: 20.0.2 dependency-type: direct:development ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent f7c7b82 commit ffe2b68

File tree

8 files changed

+142
-21
lines changed

8 files changed

+142
-21
lines changed

.changeset/cold-dolls-applaud.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@smithy/config-resolver": minor
3+
---
4+
5+
validate region is hostname component

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"eslint-plugin-simple-import-sort": "7.0.0",
4949
"eslint-plugin-tsdoc": "0.2.17",
5050
"get-port": "^7.1.0",
51-
"happy-dom": "14.12.3",
51+
"happy-dom": "20.0.2",
5252
"husky": "^4.2.3",
5353
"jest": "29.7.0",
5454
"prettier": "3.2.5",

packages/config-resolver/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"@smithy/node-config-provider": "workspace:^",
2929
"@smithy/types": "workspace:^",
3030
"@smithy/util-config-provider": "workspace:^",
31+
"@smithy/util-endpoints": "workspace:^",
3132
"@smithy/util-middleware": "workspace:^",
3233
"tslib": "^2.6.2"
3334
},
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { describe, test as it, expect, vi } from "vitest";
2+
import { isValidHostLabel } from "@smithy/util-endpoints";
3+
import { checkRegion } from "./checkRegion";
4+
5+
describe("checkRegion", () => {
6+
const acceptedRegionExamples = [
7+
"us-east-1",
8+
"ap-east-1",
9+
"ap-southeast-4",
10+
"ap-northeast-3",
11+
"ap-northeast-1",
12+
"eu-west-2",
13+
"il-central-1",
14+
"mx-central-1",
15+
"eu-isoe-santaclaus-125",
16+
"us-iso-reindeer-3000",
17+
"eusc-de-gingerbread-8000",
18+
"abcd",
19+
"12345",
20+
];
21+
22+
it("does not throw when the region is a valid host label", () => {
23+
for (const region of acceptedRegionExamples) {
24+
expect(() => checkRegion(region)).not.toThrow();
25+
}
26+
});
27+
28+
it("throws when the region is not a valid host label", () => {
29+
for (const region of [
30+
"us-east-1-",
31+
"a".repeat(64),
32+
"-us-east-1",
33+
"",
34+
"!",
35+
"@",
36+
"#",
37+
"$",
38+
"%",
39+
"^",
40+
"&",
41+
"*",
42+
"(",
43+
")",
44+
".",
45+
"[",
46+
"]",
47+
";",
48+
`'`,
49+
"?",
50+
"/",
51+
"\\",
52+
"|",
53+
"+-*/",
54+
]) {
55+
expect(() => checkRegion(region)).toThrow(
56+
`Region not accepted: region="${region}" is not a valid hostname component.`
57+
);
58+
}
59+
});
60+
61+
it("caches accepted regions", () => {
62+
const di = {
63+
isValidHostLabel,
64+
};
65+
for (const region of acceptedRegionExamples) {
66+
expect(() => checkRegion(region, di.isValidHostLabel)).not.toThrow();
67+
}
68+
vi.spyOn(di, "isValidHostLabel").mockImplementation(isValidHostLabel);
69+
for (const region of acceptedRegionExamples) {
70+
expect(() => checkRegion(region, di.isValidHostLabel)).not.toThrow();
71+
}
72+
expect(di.isValidHostLabel).toHaveBeenCalledTimes(0);
73+
expect(() => checkRegion("oh-canada", di.isValidHostLabel)).not.toThrow();
74+
expect(di.isValidHostLabel).toHaveBeenCalledTimes(1);
75+
});
76+
});
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { isValidHostLabel } from "@smithy/util-endpoints";
2+
3+
/**
4+
* @internal
5+
*/
6+
const validRegions = new Set<string>();
7+
8+
/**
9+
* Checks whether region can be a host component.
10+
*
11+
* @param region - to check.
12+
* @param check - checking function.
13+
*
14+
* @internal
15+
*/
16+
export const checkRegion = (region: string, check = isValidHostLabel) => {
17+
if (!validRegions.has(region) && !check(region)) {
18+
throw new Error(`Region not accepted: region="${region}" is not a valid hostname component.`);
19+
} else {
20+
validRegions.add(region);
21+
}
22+
};

packages/config-resolver/src/regionConfig/resolveRegionConfig.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { Provider } from "@smithy/types";
22

33
import { getRealRegion } from "./getRealRegion";
44
import { isFipsRegion } from "./isFipsRegion";
5+
import { checkRegion } from "./checkRegion";
56

67
/**
78
* @public
@@ -47,11 +48,10 @@ export const resolveRegionConfig = <T>(input: T & RegionInputConfig & Previously
4748

4849
return Object.assign(input, {
4950
region: async () => {
50-
if (typeof region === "string") {
51-
return getRealRegion(region);
52-
}
53-
const providedRegion = await region();
54-
return getRealRegion(providedRegion);
51+
const providedRegion = typeof region === "function" ? await region() : region;
52+
const realRegion = getRealRegion(providedRegion);
53+
checkRegion(realRegion);
54+
return realRegion;
5555
},
5656
useFipsEndpoint: async () => {
5757
const providedRegion = typeof region === "string" ? region : await region();

packages/util-endpoints/src/lib/isValidHostLabel.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe(isValidHostLabel.name, () => {
3232
expect(isValidHostLabel(hostLabelToTest, true)).toBe(output);
3333
});
3434

35-
describe("returns false is any subdomain is invalid", () => {
35+
describe("returns false if any subdomain is invalid", () => {
3636
const validHostLabel = testCases
3737
.filter(([outputEntry]) => outputEntry === true)
3838
.map(([, value]) => value)

yarn.lock

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2514,6 +2514,7 @@ __metadata:
25142514
"@smithy/node-config-provider": "workspace:^"
25152515
"@smithy/types": "workspace:^"
25162516
"@smithy/util-config-provider": "workspace:^"
2517+
"@smithy/util-endpoints": "workspace:^"
25172518
"@smithy/util-middleware": "workspace:^"
25182519
concurrently: "npm:7.0.0"
25192520
downlevel-dts: "npm:0.10.1"
@@ -3732,6 +3733,15 @@ __metadata:
37323733
languageName: node
37333734
linkType: hard
37343735

3736+
"@types/node@npm:^20.0.0":
3737+
version: 20.19.21
3738+
resolution: "@types/node@npm:20.19.21"
3739+
dependencies:
3740+
undici-types: "npm:~6.21.0"
3741+
checksum: 10c0/a5bedcc71b363abfa425c01e69696820736614dfba03d2363df6d306d2ee6f7619b370c72b4ec75d992e5d76eaccdcdeb362276cac1cd01756db6dec2eb8227c
3742+
languageName: node
3743+
linkType: hard
3744+
37353745
"@types/normalize-package-data@npm:^2.4.0":
37363746
version: 2.4.4
37373747
resolution: "@types/normalize-package-data@npm:2.4.4"
@@ -3774,6 +3784,13 @@ __metadata:
37743784
languageName: node
37753785
linkType: hard
37763786

3787+
"@types/whatwg-mimetype@npm:^3.0.2":
3788+
version: 3.0.2
3789+
resolution: "@types/whatwg-mimetype@npm:3.0.2"
3790+
checksum: 10c0/dad39d1e4abe760a0a963c84bbdbd26b1df0eb68aff83bdf6ecbb50ad781ead777f6906d19a87007790b750f7500a12e5624d31fc6a1529d14bd19b5c3a316d1
3791+
languageName: node
3792+
linkType: hard
3793+
37773794
"@types/yargs-parser@npm:*":
37783795
version: 21.0.0
37793796
resolution: "@types/yargs-parser@npm:21.0.0"
@@ -6732,14 +6749,14 @@ __metadata:
67326749
languageName: node
67336750
linkType: hard
67346751

6735-
"happy-dom@npm:14.12.3":
6736-
version: 14.12.3
6737-
resolution: "happy-dom@npm:14.12.3"
6752+
"happy-dom@npm:20.0.2":
6753+
version: 20.0.2
6754+
resolution: "happy-dom@npm:20.0.2"
67386755
dependencies:
6739-
entities: "npm:^4.5.0"
6740-
webidl-conversions: "npm:^7.0.0"
6756+
"@types/node": "npm:^20.0.0"
6757+
"@types/whatwg-mimetype": "npm:^3.0.2"
67416758
whatwg-mimetype: "npm:^3.0.0"
6742-
checksum: 10c0/72e817bc9d03c4c0dbb794f8fb5b69aac4b4dbe0ee789a6b6a02a60298a9aa99bac766967a5c642153e5c95c02489437f878de5641ed64fd13b2271c56805df5
6759+
checksum: 10c0/d4449e087cb7566fb493f9e6ee99221c64177732bf944ec3e2f464033107832c637e201e3e78e81a8b35871d41aa510806f3f1a2f18b924fc6120226f337a845
67436760
languageName: node
67446761
linkType: hard
67456762

@@ -10067,7 +10084,7 @@ __metadata:
1006710084
eslint-plugin-tsdoc: "npm:0.2.17"
1006810085
get-port: "npm:^7.1.0"
1006910086
glob: "npm:^7.1.6"
10070-
happy-dom: "npm:14.12.3"
10087+
happy-dom: "npm:20.0.2"
1007110088
husky: "npm:^4.2.3"
1007210089
jest: "npm:29.7.0"
1007310090
prettier: "npm:3.2.5"
@@ -10991,6 +11008,13 @@ __metadata:
1099111008
languageName: node
1099211009
linkType: hard
1099311010

11011+
"undici-types@npm:~6.21.0":
11012+
version: 6.21.0
11013+
resolution: "undici-types@npm:6.21.0"
11014+
checksum: 10c0/c01ed51829b10aa72fc3ce64b747f8e74ae9b60eafa19a7b46ef624403508a54c526ffab06a14a26b3120d055e1104d7abe7c9017e83ced038ea5cf52f8d5e04
11015+
languageName: node
11016+
linkType: hard
11017+
1099411018
"unique-filename@npm:^2.0.0":
1099511019
version: 2.0.1
1099611020
resolution: "unique-filename@npm:2.0.1"
@@ -11339,13 +11363,6 @@ __metadata:
1133911363
languageName: node
1134011364
linkType: hard
1134111365

11342-
"webidl-conversions@npm:^7.0.0":
11343-
version: 7.0.0
11344-
resolution: "webidl-conversions@npm:7.0.0"
11345-
checksum: 10c0/228d8cb6d270c23b0720cb2d95c579202db3aaf8f633b4e9dd94ec2000a04e7e6e43b76a94509cdb30479bd00ae253ab2371a2da9f81446cc313f89a4213a2c4
11346-
languageName: node
11347-
linkType: hard
11348-
1134911366
"webpack-cli@npm:^6.0.1":
1135011367
version: 6.0.1
1135111368
resolution: "webpack-cli@npm:6.0.1"

0 commit comments

Comments
 (0)