@@ -69,14 +69,6 @@ describe('maskSigUrl', () => {
69
69
jest . clearAllMocks ( )
70
70
} )
71
71
72
- it ( 'masks the sig parameter in the URL and sets it as a secret' , ( ) => {
73
- const url = 'https://example.com?sig=12345'
74
- const maskedUrl = maskSigUrl ( url )
75
- expect ( maskedUrl ) . toBe ( 'https://example.com/?sig=***' )
76
- expect ( setSecret ) . toHaveBeenCalledWith ( '12345' )
77
- expect ( setSecret ) . toHaveBeenCalledWith ( encodeURIComponent ( '12345' ) )
78
- } )
79
-
80
72
it ( 'returns the original URL if no sig parameter is present' , ( ) => {
81
73
const url = 'https://example.com'
82
74
const maskedUrl = maskSigUrl ( url )
@@ -85,7 +77,7 @@ describe('maskSigUrl', () => {
85
77
} )
86
78
87
79
it ( 'masks the sig parameter in the middle of the URL and sets it as a secret' , ( ) => {
88
- const url = 'https://example.com?param1=value1&sig=12345¶m2=value2'
80
+ const url = 'https://example.com/ ?param1=value1&sig=12345¶m2=value2'
89
81
const maskedUrl = maskSigUrl ( url )
90
82
expect ( maskedUrl ) . toBe (
91
83
'https://example.com/?param1=value1&sig=***¶m2=value2'
@@ -101,112 +93,13 @@ describe('maskSigUrl', () => {
101
93
expect ( setSecret ) . not . toHaveBeenCalled ( )
102
94
} )
103
95
104
- it ( 'handles URLs with special characters in signature' , ( ) => {
105
- const url = 'https://example.com?sig=abc/+=%3D'
106
- const maskedUrl = maskSigUrl ( url )
107
- expect ( maskedUrl ) . toBe ( 'https://example.com/?sig=***' )
108
-
109
- expect ( setSecret ) . toHaveBeenCalledWith ( 'abc/+' )
110
- expect ( setSecret ) . toHaveBeenCalledWith ( 'abc/ ==' )
111
- expect ( setSecret ) . toHaveBeenCalledWith ( 'abc%2F%20%3D%3D' )
112
- } )
113
-
114
- it ( 'handles relative URLs' , ( ) => {
115
- const url = '/path?param=value&sig=12345'
116
- const maskedUrl = maskSigUrl ( url )
117
- expect ( maskedUrl ) . toBe ( 'https://example.com/path?param=value&sig=***' )
118
- expect ( setSecret ) . toHaveBeenCalledWith ( '12345' )
119
- expect ( setSecret ) . toHaveBeenCalledWith ( encodeURIComponent ( '12345' ) )
120
- } )
121
-
122
- it ( 'handles URLs with uppercase SIG parameter' , ( ) => {
123
- const url = 'https://example.com?SIG=12345'
124
- const maskedUrl = maskSigUrl ( url )
125
- expect ( maskedUrl ) . toBe ( 'https://example.com/?SIG=***' )
126
- expect ( setSecret ) . toHaveBeenCalledWith ( '12345' )
127
- expect ( setSecret ) . toHaveBeenCalledWith ( encodeURIComponent ( '12345' ) )
128
- } )
129
-
130
- it ( 'handles malformed URLs using regex fallback' , ( ) => {
131
- const url = 'not:a:valid:url:but:has:sig=12345'
132
- const maskedUrl = maskSigUrl ( url )
133
- expect ( maskedUrl ) . toBe ( 'not:a:valid:url:but:has:sig=***' )
134
- expect ( setSecret ) . toHaveBeenCalledWith ( '12345' )
135
- } )
136
-
137
96
it ( 'handles URLs with fragments' , ( ) => {
138
97
const url = 'https://example.com?sig=12345#fragment'
139
98
const maskedUrl = maskSigUrl ( url )
140
99
expect ( maskedUrl ) . toBe ( 'https://example.com/?sig=***#fragment' )
141
100
expect ( setSecret ) . toHaveBeenCalledWith ( '12345' )
142
101
expect ( setSecret ) . toHaveBeenCalledWith ( encodeURIComponent ( '12345' ) )
143
102
} )
144
-
145
- it ( 'handles URLs with Sig parameter (first letter uppercase)' , ( ) => {
146
- const url = 'https://example.com?Sig=12345'
147
- const maskedUrl = maskSigUrl ( url )
148
- expect ( maskedUrl ) . toBe ( 'https://example.com/?Sig=***' )
149
- expect ( setSecret ) . toHaveBeenCalledWith ( '12345' )
150
- expect ( setSecret ) . toHaveBeenCalledWith ( encodeURIComponent ( '12345' ) )
151
- } )
152
-
153
- it ( 'handles URLs with sIg parameter (middle letter uppercase)' , ( ) => {
154
- const url = 'https://example.com?sIg=12345'
155
- const maskedUrl = maskSigUrl ( url )
156
- expect ( maskedUrl ) . toBe ( 'https://example.com/?sIg=***' )
157
- expect ( setSecret ) . toHaveBeenCalledWith ( '12345' )
158
- expect ( setSecret ) . toHaveBeenCalledWith ( encodeURIComponent ( '12345' ) )
159
- } )
160
-
161
- it ( 'handles URLs with siG parameter (last letter uppercase)' , ( ) => {
162
- const url = 'https://example.com?siG=12345'
163
- const maskedUrl = maskSigUrl ( url )
164
- expect ( maskedUrl ) . toBe ( 'https://example.com/?siG=***' )
165
- expect ( setSecret ) . toHaveBeenCalledWith ( '12345' )
166
- expect ( setSecret ) . toHaveBeenCalledWith ( encodeURIComponent ( '12345' ) )
167
- } )
168
-
169
- it ( 'handles URLs with mixed case sig parameters in the same URL' , ( ) => {
170
- const url = 'https://example.com?sig=123&SIG=456&Sig=789'
171
- const maskedUrl = maskSigUrl ( url )
172
- expect ( maskedUrl ) . toBe ( 'https://example.com/?sig=***&SIG=***&Sig=***' )
173
- expect ( setSecret ) . toHaveBeenCalledWith ( '123' )
174
- expect ( setSecret ) . toHaveBeenCalledWith ( '456' )
175
- expect ( setSecret ) . toHaveBeenCalledWith ( '789' )
176
- expect ( setSecret ) . toHaveBeenCalledWith ( encodeURIComponent ( '123' ) )
177
- expect ( setSecret ) . toHaveBeenCalledWith ( encodeURIComponent ( '456' ) )
178
- expect ( setSecret ) . toHaveBeenCalledWith ( encodeURIComponent ( '789' ) )
179
- } )
180
-
181
- it ( 'handles malformed URLs with different sig case variations' , ( ) => {
182
- const url = 'not:a:valid:url:but:has:Sig=12345'
183
- const maskedUrl = maskSigUrl ( url )
184
- expect ( maskedUrl ) . toBe ( 'not:a:valid:url:but:has:Sig=***' )
185
- expect ( setSecret ) . toHaveBeenCalledWith ( '12345' )
186
- } )
187
-
188
- it ( 'handles malformed URLs with uppercase SIG in irregular formats' , ( ) => {
189
- const url = 'something&SIG=12345&other:stuff'
190
- const maskedUrl = maskSigUrl ( url )
191
- expect ( maskedUrl ) . toBe ( 'something&SIG=***&other:stuff' )
192
- expect ( setSecret ) . toHaveBeenCalledWith ( '12345' )
193
- } )
194
-
195
- it ( 'handles sig parameter at the start of the query string' , ( ) => {
196
- const url = 'https://example.com?sig=12345¶m=value'
197
- const maskedUrl = maskSigUrl ( url )
198
- expect ( maskedUrl ) . toBe ( 'https://example.com/?sig=***¶m=value' )
199
- expect ( setSecret ) . toHaveBeenCalledWith ( '12345' )
200
- expect ( setSecret ) . toHaveBeenCalledWith ( encodeURIComponent ( '12345' ) )
201
- } )
202
-
203
- it ( 'handles sig parameter at the end of the query string' , ( ) => {
204
- const url = 'https://example.com?param=value&sig=12345'
205
- const maskedUrl = maskSigUrl ( url )
206
- expect ( maskedUrl ) . toBe ( 'https://example.com/?param=value&sig=***' )
207
- expect ( setSecret ) . toHaveBeenCalledWith ( '12345' )
208
- expect ( setSecret ) . toHaveBeenCalledWith ( encodeURIComponent ( '12345' ) )
209
- } )
210
103
} )
211
104
212
105
describe ( 'maskSecretUrls' , ( ) => {
@@ -262,77 +155,6 @@ describe('maskSecretUrls', () => {
262
155
expect ( setSecret ) . not . toHaveBeenCalled ( )
263
156
} )
264
157
265
- it ( 'handles malformed URLs in the body' , ( ) => {
266
- const body = {
267
- signed_upload_url : 'not:a:valid:url:but:has:sig=upload123' ,
268
- signed_url : 'also:not:valid:with:sig=download123'
269
- }
270
- maskSecretUrls ( body )
271
- expect ( setSecret ) . toHaveBeenCalledWith ( 'upload123' )
272
- expect ( setSecret ) . toHaveBeenCalledWith ( 'download123' )
273
- } )
274
-
275
- it ( 'handles URLs with different case variations of sig parameter' , ( ) => {
276
- const body = {
277
- signed_upload_url : 'https://upload.com?SIG=upload123' ,
278
- signed_url : 'https://download.com?Sig=download123'
279
- }
280
- maskSecretUrls ( body )
281
- expect ( setSecret ) . toHaveBeenCalledWith ( 'upload123' )
282
- expect ( setSecret ) . toHaveBeenCalledWith ( encodeURIComponent ( 'upload123' ) )
283
- expect ( setSecret ) . toHaveBeenCalledWith ( 'download123' )
284
- expect ( setSecret ) . toHaveBeenCalledWith ( encodeURIComponent ( 'download123' ) )
285
- } )
286
-
287
- it ( 'handles URLs with special characters in signature' , ( ) => {
288
- const specialSig = 'xyz!@#$'
289
- const encodedSpecialSig = encodeURIComponent ( specialSig )
290
-
291
- const body = {
292
- signed_upload_url : 'https://upload.com?sig=abc/+=%3D' ,
293
- signed_url : `https://download.com?sig=${ encodedSpecialSig } `
294
- }
295
- maskSecretUrls ( body )
296
-
297
- const allCalls = ( setSecret as jest . Mock ) . mock . calls . flat ( )
298
-
299
- expect ( allCalls ) . toContain ( 'abc/+' )
300
- expect ( allCalls ) . toContain ( 'abc/ ==' )
301
- expect ( allCalls ) . toContain ( 'abc%2F%20%3D%3D' )
302
-
303
- expect ( allCalls ) . toContain ( specialSig )
304
- } )
305
-
306
- it ( 'handles deeply nested URLs in the body' , ( ) => {
307
- const body = {
308
- data : {
309
- urls : {
310
- signed_upload_url : 'https://upload.com?sig=nested123' ,
311
- signed_url : 'https://download.com?sig=nested456'
312
- }
313
- }
314
- }
315
- maskSecretUrls ( body )
316
- expect ( setSecret ) . toHaveBeenCalledWith ( 'nested123' )
317
- expect ( setSecret ) . toHaveBeenCalledWith ( encodeURIComponent ( 'nested123' ) )
318
- expect ( setSecret ) . toHaveBeenCalledWith ( 'nested456' )
319
- expect ( setSecret ) . toHaveBeenCalledWith ( encodeURIComponent ( 'nested456' ) )
320
- } )
321
-
322
- it ( 'handles arrays of URLs in the body' , ( ) => {
323
- const body = {
324
- signed_urls : [
325
- 'https://first.com?sig=first123' ,
326
- 'https://second.com?sig=second456'
327
- ]
328
- }
329
- maskSecretUrls ( body )
330
- expect ( setSecret ) . toHaveBeenCalledWith ( 'first123' )
331
- expect ( setSecret ) . toHaveBeenCalledWith ( encodeURIComponent ( 'first123' ) )
332
- expect ( setSecret ) . toHaveBeenCalledWith ( 'second456' )
333
- expect ( setSecret ) . toHaveBeenCalledWith ( encodeURIComponent ( 'second456' ) )
334
- } )
335
-
336
158
it ( 'does nothing if body is not an object or is null' , ( ) => {
337
159
maskSecretUrls ( null )
338
160
expect ( debug ) . toHaveBeenCalledWith ( 'body is not an object or is null' )
0 commit comments