File tree 2 files changed +33
-1
lines changed
2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -1121,6 +1121,31 @@ describe(`getStore`, () => {
1121
1121
)
1122
1122
} )
1123
1123
1124
+ test ( 'Throws when the name of the store starts with the `deploy:` prefix' , async ( ) => {
1125
+ const { fetch } = new MockFetch ( )
1126
+
1127
+ globalThis . fetch = fetch
1128
+
1129
+ expect ( ( ) =>
1130
+ getStore ( {
1131
+ name : 'deploy:foo' ,
1132
+ token : apiToken ,
1133
+ siteID,
1134
+ } ) ,
1135
+ ) . toThrowError ( 'Store name cannot start with the string `deploy:`, which is a reserved namespace' )
1136
+
1137
+ const context = {
1138
+ siteID,
1139
+ token : apiToken ,
1140
+ }
1141
+
1142
+ env . NETLIFY_BLOBS_CONTEXT = Buffer . from ( JSON . stringify ( context ) ) . toString ( 'base64' )
1143
+
1144
+ expect ( ( ) => getStore ( 'deploy:foo' ) ) . toThrowError (
1145
+ 'Store name cannot start with the string `deploy:`, which is a reserved namespace' ,
1146
+ )
1147
+ } )
1148
+
1124
1149
test ( 'Throws when there is no `fetch` implementation available' , async ( ) => {
1125
1150
// @ts -expect-error Assigning a value that doesn't match the type.
1126
1151
globalThis . fetch = undefined
Original file line number Diff line number Diff line change @@ -33,7 +33,14 @@ export class Store {
33
33
34
34
constructor ( options : StoreOptions ) {
35
35
this . client = options . client
36
- this . name = 'deployID' in options ? `deploy:${ options . deployID } ` : encodeURIComponent ( options . name )
36
+
37
+ if ( 'deployID' in options ) {
38
+ this . name = `deploy:${ encodeURIComponent ( options . deployID ) } `
39
+ } else if ( options ?. name . startsWith ( 'deploy:' ) ) {
40
+ throw new Error ( 'Store name cannot start with the string `deploy:`, which is a reserved namespace' )
41
+ } else {
42
+ this . name = encodeURIComponent ( options . name )
43
+ }
37
44
}
38
45
39
46
async delete ( key : string ) {
You can’t perform that action at this time.
0 commit comments