File tree 2 files changed +30
-3
lines changed
packages/config-resolver/src
2 files changed +30
-3
lines changed Original file line number Diff line number Diff line change @@ -85,9 +85,29 @@ describe("EndpointsConfig", () => {
85
85
describe ( "throws error" , ( ) => {
86
86
const error = new Error ( "error" ) ;
87
87
88
- it ( "if region throws error" , ( ) => {
89
- region . mockRejectedValueOnce ( error ) ;
90
- return expect ( resolveEndpointsConfig ( input ) . endpoint ( ) ) . rejects . toStrictEqual ( error ) ;
88
+ describe ( "if region" , ( ) => {
89
+ it ( "throws error" , ( ) => {
90
+ region . mockRejectedValueOnce ( error ) ;
91
+ return expect ( resolveEndpointsConfig ( input ) . endpoint ( ) ) . rejects . toStrictEqual ( error ) ;
92
+ } ) ;
93
+
94
+ it ( "is invalid" , ( ) => {
95
+ [
96
+ "" ,
97
+ "has_underscore" ,
98
+ "-starts-with-dash" ,
99
+ "ends-with-dash-" ,
100
+ "-starts-and-ends-with-dash-" ,
101
+ "-" ,
102
+ "c0nt@in$-$ymb01$" ,
103
+ "0123456789012345678901234567890123456789012345678901234567890123" , // 64 characters
104
+ ] . forEach ( ( invalidRegion ) => {
105
+ region . mockResolvedValueOnce ( invalidRegion ) ;
106
+ return expect ( resolveEndpointsConfig ( input ) . endpoint ( ) ) . rejects . toStrictEqual (
107
+ new Error ( "Invalid region in client config" )
108
+ ) ;
109
+ } ) ;
110
+ } ) ;
91
111
} ) ;
92
112
93
113
describe ( "if regionInfoProvider" , ( ) => {
Original file line number Diff line number Diff line change @@ -45,9 +45,16 @@ const normalizeEndpoint = (input: EndpointsInputConfig & PreviouslyResolved): Pr
45
45
const getEndPointFromRegion = async ( input : EndpointsInputConfig & PreviouslyResolved ) => {
46
46
const { tls = true } = input ;
47
47
const region = await input . region ( ) ;
48
+
49
+ const dnsHostRegex = new RegExp ( / ^ ( [ a - z A - Z 0 - 9 ] | [ a - z A - Z 0 - 9 ] [ a - z A - Z 0 - 9 - ] { 0 , 61 } [ a - z A - Z 0 - 9 ] ) $ / ) ;
50
+ if ( ! dnsHostRegex . test ( region ) ) {
51
+ throw new Error ( "Invalid region in client config" ) ;
52
+ }
53
+
48
54
const { hostname } = ( await input . regionInfoProvider ( region ) ) ?? { } ;
49
55
if ( ! hostname ) {
50
56
throw new Error ( "Cannot resolve hostname from client config" ) ;
51
57
}
58
+
52
59
return input . urlParser ( `${ tls ? "https:" : "http:" } //${ hostname } ` ) ;
53
60
} ;
You can’t perform that action at this time.
0 commit comments