@adobe/aio-lib-web 7.1.0 → 7.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
name: Dependabot Coverage Upload
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
issue_comment:
|
|
5
|
+
types: [created]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
check:
|
|
9
|
+
if: github.event.issue.pull_request != null && github.event.comment.body == '/upload-coverage'
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
outputs:
|
|
12
|
+
allowed: ${{ steps.gate.outputs.allowed }}
|
|
13
|
+
steps:
|
|
14
|
+
- name: Gate check
|
|
15
|
+
id: gate
|
|
16
|
+
run: |
|
|
17
|
+
set -euo pipefail
|
|
18
|
+
PERM=$(gh api "repos/$GITHUB_REPOSITORY/collaborators/$COMMENT_USER_LOGIN/permission" --jq '.permission' 2>/dev/null || echo "none")
|
|
19
|
+
if [ "$PERM" = "admin" ] || [ "$PERM" = "maintain" ]; then
|
|
20
|
+
echo "allowed=true" >> $GITHUB_OUTPUT
|
|
21
|
+
else
|
|
22
|
+
echo "allowed=false" >> $GITHUB_OUTPUT
|
|
23
|
+
fi
|
|
24
|
+
env:
|
|
25
|
+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
26
|
+
COMMENT_USER_LOGIN: ${{ github.event.comment.user.login }}
|
|
27
|
+
|
|
28
|
+
upload:
|
|
29
|
+
needs: check
|
|
30
|
+
if: needs.check.outputs.allowed == 'true'
|
|
31
|
+
uses: adobe/aio-reusable-workflows/.github/workflows/dependabot-coverage-upload.yml@main
|
|
32
|
+
secrets:
|
|
33
|
+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
name: PR Review
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
types: [opened, reopened, synchronize]
|
|
6
|
+
issue_comment:
|
|
7
|
+
types: [created]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
check:
|
|
11
|
+
# NOTE: comment body matching is exact — /review or /pr-reviewer with no trailing spaces, newlines, or mixed case
|
|
12
|
+
# This does not fail the workflow; non-matching comments simply do not trigger the job
|
|
13
|
+
if: |
|
|
14
|
+
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false) ||
|
|
15
|
+
(github.event_name == 'issue_comment' && github.event.issue.pull_request != null &&
|
|
16
|
+
(github.event.comment.body == '/review' || github.event.comment.body == '/pr-reviewer'))
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
outputs:
|
|
19
|
+
allowed: ${{ steps.gate.outputs.allowed }}
|
|
20
|
+
pr_number: ${{ steps.gate.outputs.pr_number }}
|
|
21
|
+
head_sha: ${{ steps.gate.outputs.head_sha }}
|
|
22
|
+
steps:
|
|
23
|
+
- name: Gate check
|
|
24
|
+
id: gate
|
|
25
|
+
run: |
|
|
26
|
+
set -euo pipefail
|
|
27
|
+
if [ "$EVENT_NAME" = "pull_request" ]; then
|
|
28
|
+
echo "allowed=true" >> $GITHUB_OUTPUT
|
|
29
|
+
echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
|
|
30
|
+
echo "head_sha=$HEAD_SHA" >> $GITHUB_OUTPUT
|
|
31
|
+
else
|
|
32
|
+
# Fall back to "none" if user is not a collaborator (gh api returns 404) so allowed=false is output cleanly
|
|
33
|
+
PERM=$(gh api repos/$GITHUB_REPOSITORY/collaborators/$COMMENT_USER_LOGIN/permission --jq '.permission' 2>/dev/null || echo "none")
|
|
34
|
+
# Intentionally require admin or maintain; write collaborators are excluded to
|
|
35
|
+
# limit who can trigger potentially expensive/sensitive review automation.
|
|
36
|
+
if [ "$PERM" = "admin" ] || [ "$PERM" = "maintain" ]; then
|
|
37
|
+
DATA=$(gh api repos/$GITHUB_REPOSITORY/pulls/$ISSUE_NUMBER)
|
|
38
|
+
echo "allowed=true" >> $GITHUB_OUTPUT
|
|
39
|
+
echo "pr_number=$ISSUE_NUMBER" >> $GITHUB_OUTPUT
|
|
40
|
+
echo "head_sha=$(echo "$DATA" | jq -r '.head.sha')" >> $GITHUB_OUTPUT
|
|
41
|
+
else
|
|
42
|
+
echo "allowed=false" >> $GITHUB_OUTPUT
|
|
43
|
+
fi
|
|
44
|
+
fi
|
|
45
|
+
env:
|
|
46
|
+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
47
|
+
EVENT_NAME: ${{ github.event_name }}
|
|
48
|
+
PR_NUMBER: ${{ github.event.pull_request.number }}
|
|
49
|
+
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
|
|
50
|
+
COMMENT_USER_LOGIN: ${{ github.event.comment.user.login }}
|
|
51
|
+
ISSUE_NUMBER: ${{ github.event.issue.number }}
|
|
52
|
+
# GITHUB_REPOSITORY is set automatically by GitHub Actions (owner/repo)
|
|
53
|
+
|
|
54
|
+
review:
|
|
55
|
+
needs: check
|
|
56
|
+
if: needs.check.outputs.allowed == 'true'
|
|
57
|
+
uses: adobe/aio-reusable-workflows/.github/workflows/pr-review.yml@main
|
|
58
|
+
with:
|
|
59
|
+
pr_number: ${{ needs.check.outputs.pr_number }}
|
|
60
|
+
head_sha: ${{ needs.check.outputs.head_sha }}
|
|
61
|
+
secrets:
|
|
62
|
+
AWS_BEARER_TOKEN_BEDROCK: ${{ secrets.APP_BUILDER_AWS_BEARER_TOKEN_BEDROCK }}
|
package/lib/remote-storage.js
CHANGED
|
@@ -24,22 +24,6 @@ const { codes, logAndThrow } = require('./StorageError')
|
|
|
24
24
|
|
|
25
25
|
const fileExtensionPattern = /\*\.[0-9a-zA-Z]+$/
|
|
26
26
|
|
|
27
|
-
// /**
|
|
28
|
-
// * Joins url path parts
|
|
29
|
-
// * @param {...string} args url parts
|
|
30
|
-
// * @returns {string}
|
|
31
|
-
// */
|
|
32
|
-
function urlJoin (...args) {
|
|
33
|
-
let start = ''
|
|
34
|
-
if (args[0] &&
|
|
35
|
-
args[0].startsWith('/')) {
|
|
36
|
-
start = '/'
|
|
37
|
-
}
|
|
38
|
-
return start + args.map(a => a && a.replace(/(^\/|\/$)/g, ''))
|
|
39
|
-
.filter(a => a) // remove empty strings / nulls
|
|
40
|
-
.join('/')
|
|
41
|
-
}
|
|
42
|
-
|
|
43
27
|
module.exports = class RemoteStorage {
|
|
44
28
|
/**
|
|
45
29
|
* @param {object} creds
|
|
@@ -153,7 +137,7 @@ module.exports = class RemoteStorage {
|
|
|
153
137
|
const cacheControlString = this._getCacheControlConfig(mimeType, appConfig.app)
|
|
154
138
|
const uploadParams = {
|
|
155
139
|
Bucket: this.bucket,
|
|
156
|
-
Key:
|
|
140
|
+
Key: this._urlJoin(prefix, path.basename(file)),
|
|
157
141
|
Body: content
|
|
158
142
|
}
|
|
159
143
|
// if we found it in the global config, we will use it ( for now )
|
|
@@ -170,9 +154,6 @@ module.exports = class RemoteStorage {
|
|
|
170
154
|
delete responseHeaders['adp-cache-control']
|
|
171
155
|
}
|
|
172
156
|
|
|
173
|
-
if (appConfig.auditUserId) {
|
|
174
|
-
responseHeaders['adp-AuditUserId'] = appConfig.auditUserId
|
|
175
|
-
}
|
|
176
157
|
// we only set metadata if we have added anything to responseHeaders object
|
|
177
158
|
// it is not null, but could be empty
|
|
178
159
|
if (Object.keys(responseHeaders).length > 0) {
|
|
@@ -296,7 +277,7 @@ module.exports = class RemoteStorage {
|
|
|
296
277
|
// base directory returns ".", ignore that.
|
|
297
278
|
prefixDirectory = prefixDirectory === '.' ? '' : prefixDirectory
|
|
298
279
|
// newPrefix is now the initial prefix plus the files relative directory path.
|
|
299
|
-
const newPrefix =
|
|
280
|
+
const newPrefix = this._urlJoin(prefix, prefixDirectory)
|
|
300
281
|
const s3Res = await this.uploadFile(f, newPrefix, appConfig, dir)
|
|
301
282
|
if (postFileUploadCallback) {
|
|
302
283
|
postFileUploadCallback(f)
|
|
@@ -309,6 +290,41 @@ module.exports = class RemoteStorage {
|
|
|
309
290
|
return allResults
|
|
310
291
|
}
|
|
311
292
|
|
|
293
|
+
/**
|
|
294
|
+
* Joins file path parts into a URL-friendly S3 key
|
|
295
|
+
* Normalizes paths by:
|
|
296
|
+
* - Preserving leading slash if first part starts with '/'
|
|
297
|
+
* - Removing leading/trailing slashes from each part
|
|
298
|
+
* - Converting Windows backslashes to forward slashes
|
|
299
|
+
* - Removing double slashes
|
|
300
|
+
* - Filtering out empty/null parts
|
|
301
|
+
* @param {...string} args - Path parts to join
|
|
302
|
+
* @returns {string} Normalized S3 key path
|
|
303
|
+
*/
|
|
304
|
+
_urlJoin (...args) {
|
|
305
|
+
// Preserve leading slash if first argument starts with one
|
|
306
|
+
const hasLeadingSlash = args[0] && args[0].startsWith('/')
|
|
307
|
+
|
|
308
|
+
// Normalize each path part:
|
|
309
|
+
// 1. Remove leading and trailing slashes (^\/ matches start, \/$ matches end)
|
|
310
|
+
// 2. Convert Windows backslashes to forward slashes
|
|
311
|
+
// 3. Filter out empty/null values
|
|
312
|
+
const normalizedParts = args
|
|
313
|
+
.map(part => {
|
|
314
|
+
if (!part) return null
|
|
315
|
+
// Remove leading/trailing slashes and convert backslashes to forward slashes
|
|
316
|
+
return part.replace(/(^\/|\/$)/g, '').replace(/\\/g, '/')
|
|
317
|
+
})
|
|
318
|
+
.filter(part => part) // Remove empty strings and nulls
|
|
319
|
+
|
|
320
|
+
// Join parts with '/' and remove any double slashes that may result
|
|
321
|
+
const joined = normalizedParts.join('/')
|
|
322
|
+
const withoutDoubleSlashes = joined.replace(/\/+/g, '/')
|
|
323
|
+
|
|
324
|
+
// Restore leading slash if original first part had one
|
|
325
|
+
return hasLeadingSlash ? '/' + withoutDoubleSlashes : withoutDoubleSlashes
|
|
326
|
+
}
|
|
327
|
+
|
|
312
328
|
/**
|
|
313
329
|
* Get cache control string based on mime type and config
|
|
314
330
|
* @param {string|boolean} mimeType - string if valid mimeType or false for unknown files
|
|
@@ -318,16 +334,27 @@ module.exports = class RemoteStorage {
|
|
|
318
334
|
const cacheControlStr = 's-maxage=60'
|
|
319
335
|
if (!mimeType) {
|
|
320
336
|
return null
|
|
321
|
-
} else if (mimeType === mime.lookup('html')) {
|
|
322
|
-
return `${cacheControlStr}, max-age=${appConfig.htmlCacheDuration}`
|
|
323
|
-
} else if (mimeType === mime.lookup('js')) {
|
|
324
|
-
return `${cacheControlStr}, max-age=${appConfig.jsCacheDuration}`
|
|
325
|
-
} else if (mimeType === mime.lookup('css')) {
|
|
326
|
-
return `${cacheControlStr}, max-age=${appConfig.cssCacheDuration}`
|
|
327
|
-
} else if (mimeType.startsWith('image')) {
|
|
328
|
-
return `${cacheControlStr}, max-age=${appConfig.imageCacheDuration}`
|
|
329
|
-
} else {
|
|
330
|
-
return null
|
|
331
337
|
}
|
|
338
|
+
if (mimeType === mime.lookup('html')) {
|
|
339
|
+
if (appConfig.htmlCacheDuration) {
|
|
340
|
+
return `${cacheControlStr}, max-age=${appConfig.htmlCacheDuration}`
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
if (mimeType === mime.lookup('js')) {
|
|
344
|
+
if (appConfig.jsCacheDuration) {
|
|
345
|
+
return `${cacheControlStr}, max-age=${appConfig.jsCacheDuration}`
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
if (mimeType === mime.lookup('css')) {
|
|
349
|
+
if (appConfig.cssCacheDuration) {
|
|
350
|
+
return `${cacheControlStr}, max-age=${appConfig.cssCacheDuration}`
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
if (mimeType.startsWith('image')) {
|
|
354
|
+
if (appConfig.imageCacheDuration) {
|
|
355
|
+
return `${cacheControlStr}, max-age=${appConfig.imageCacheDuration}`
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
return null
|
|
332
359
|
}
|
|
333
360
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/aio-lib-web",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.2.0",
|
|
4
4
|
"description": "Utility tooling library to build and deploy Adobe I/O Project Firefly app static sites to CDN",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"directories": {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"author": "Adobe Inc.",
|
|
11
11
|
"license": "Apache-2.0",
|
|
12
12
|
"engines": {
|
|
13
|
-
"node": ">=
|
|
13
|
+
"node": ">=20"
|
|
14
14
|
},
|
|
15
15
|
"repository": "adobe/aio-lib-web",
|
|
16
16
|
"homepage": "https://github.com/adobe/aio-lib-web",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@adobe/aio-lib-core-config": "^5",
|
|
33
33
|
"@adobe/aio-lib-core-logging": "^3",
|
|
34
34
|
"@adobe/aio-lib-core-tvm": "^4",
|
|
35
|
-
"@aws-sdk/client-s3": "^3.
|
|
35
|
+
"@aws-sdk/client-s3": "^3.1045.0",
|
|
36
36
|
"@smithy/node-http-handler": "^4.0.2",
|
|
37
37
|
"core-js": "^3.25.1",
|
|
38
38
|
"fs-extra": "^11",
|
|
@@ -176,6 +176,269 @@ describe('RemoteStorage', () => {
|
|
|
176
176
|
})
|
|
177
177
|
})
|
|
178
178
|
|
|
179
|
+
describe('_urlJoin', () => {
|
|
180
|
+
let rs
|
|
181
|
+
|
|
182
|
+
beforeEach(() => {
|
|
183
|
+
rs = new RemoteStorage(global.fakeTVMResponse)
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
describe('basic path joining', () => {
|
|
187
|
+
test('joins simple path parts', () => {
|
|
188
|
+
expect(rs._urlJoin('prefix', 'file.js')).toBe('prefix/file.js')
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
test('joins multiple path parts', () => {
|
|
192
|
+
expect(rs._urlJoin('prefix', 'deep', 'nested', 'file.js')).toBe('prefix/deep/nested/file.js')
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
test('handles single part', () => {
|
|
196
|
+
expect(rs._urlJoin('file.js')).toBe('file.js')
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
test('handles empty string parts', () => {
|
|
200
|
+
expect(rs._urlJoin('prefix', '', 'file.js')).toBe('prefix/file.js')
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
test('handles null parts', () => {
|
|
204
|
+
expect(rs._urlJoin('prefix', null, 'file.js')).toBe('prefix/file.js')
|
|
205
|
+
})
|
|
206
|
+
|
|
207
|
+
test('handles undefined parts', () => {
|
|
208
|
+
expect(rs._urlJoin('prefix', undefined, 'file.js')).toBe('prefix/file.js')
|
|
209
|
+
})
|
|
210
|
+
|
|
211
|
+
test('handles all empty/null parts', () => {
|
|
212
|
+
expect(rs._urlJoin('', null, undefined)).toBe('')
|
|
213
|
+
})
|
|
214
|
+
})
|
|
215
|
+
|
|
216
|
+
describe('leading slash preservation', () => {
|
|
217
|
+
test('preserves leading slash from first argument', () => {
|
|
218
|
+
expect(rs._urlJoin('/prefix', 'file.js')).toBe('/prefix/file.js')
|
|
219
|
+
})
|
|
220
|
+
|
|
221
|
+
test('preserves leading slash with multiple parts', () => {
|
|
222
|
+
expect(rs._urlJoin('/prefix', 'deep', 'file.js')).toBe('/prefix/deep/file.js')
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
test('does not add leading slash when first part does not have one', () => {
|
|
226
|
+
expect(rs._urlJoin('prefix', 'file.js')).toBe('prefix/file.js')
|
|
227
|
+
})
|
|
228
|
+
|
|
229
|
+
test('handles leading slash with single part', () => {
|
|
230
|
+
expect(rs._urlJoin('/file.js')).toBe('/file.js')
|
|
231
|
+
})
|
|
232
|
+
})
|
|
233
|
+
|
|
234
|
+
describe('trailing slash removal', () => {
|
|
235
|
+
test('removes trailing slash from parts', () => {
|
|
236
|
+
expect(rs._urlJoin('prefix/', 'file.js')).toBe('prefix/file.js')
|
|
237
|
+
})
|
|
238
|
+
|
|
239
|
+
test('removes trailing slash from multiple parts', () => {
|
|
240
|
+
expect(rs._urlJoin('prefix/', 'deep/', 'file.js')).toBe('prefix/deep/file.js')
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
test('removes trailing slash from last part', () => {
|
|
244
|
+
expect(rs._urlJoin('prefix', 'file.js/')).toBe('prefix/file.js')
|
|
245
|
+
})
|
|
246
|
+
|
|
247
|
+
test('removes trailing slash while preserving leading slash', () => {
|
|
248
|
+
expect(rs._urlJoin('/prefix/', 'file.js')).toBe('/prefix/file.js')
|
|
249
|
+
})
|
|
250
|
+
})
|
|
251
|
+
|
|
252
|
+
describe('leading slash removal', () => {
|
|
253
|
+
test('removes leading slash from non-first parts', () => {
|
|
254
|
+
expect(rs._urlJoin('prefix', '/deep', 'file.js')).toBe('prefix/deep/file.js')
|
|
255
|
+
})
|
|
256
|
+
|
|
257
|
+
test('removes leading slash from middle parts', () => {
|
|
258
|
+
expect(rs._urlJoin('prefix', '/deep', '/nested', 'file.js')).toBe('prefix/deep/nested/file.js')
|
|
259
|
+
})
|
|
260
|
+
|
|
261
|
+
test('preserves leading slash only on first part', () => {
|
|
262
|
+
expect(rs._urlJoin('/prefix', '/deep', '/file.js')).toBe('/prefix/deep/file.js')
|
|
263
|
+
})
|
|
264
|
+
})
|
|
265
|
+
|
|
266
|
+
describe('Windows backslash conversion', () => {
|
|
267
|
+
test('converts Windows backslashes to forward slashes', () => {
|
|
268
|
+
expect(rs._urlJoin('prefix\\deep', 'file.js')).toBe('prefix/deep/file.js')
|
|
269
|
+
})
|
|
270
|
+
|
|
271
|
+
test('converts backslashes in single part', () => {
|
|
272
|
+
expect(rs._urlJoin('prefix\\deep\\file.js')).toBe('prefix/deep/file.js')
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
test('converts backslashes in multiple parts', () => {
|
|
276
|
+
expect(rs._urlJoin('prefix\\deep', 'nested\\file.js')).toBe('prefix/deep/nested/file.js')
|
|
277
|
+
})
|
|
278
|
+
|
|
279
|
+
test('converts backslashes while preserving leading slash', () => {
|
|
280
|
+
expect(rs._urlJoin('/prefix\\deep', 'file.js')).toBe('/prefix/deep/file.js')
|
|
281
|
+
})
|
|
282
|
+
|
|
283
|
+
test('converts mixed backslashes and forward slashes', () => {
|
|
284
|
+
expect(rs._urlJoin('prefix\\deep', 'nested/file.js')).toBe('prefix/deep/nested/file.js')
|
|
285
|
+
})
|
|
286
|
+
|
|
287
|
+
test('handles Windows-style path with backslashes', () => {
|
|
288
|
+
expect(rs._urlJoin('fakeprefix\\deep\\dir', 'index.js')).toBe('fakeprefix/deep/dir/index.js')
|
|
289
|
+
})
|
|
290
|
+
})
|
|
291
|
+
|
|
292
|
+
describe('double slash removal', () => {
|
|
293
|
+
test('removes double slashes from joined path', () => {
|
|
294
|
+
expect(rs._urlJoin('prefix', '', 'file.js')).toBe('prefix/file.js')
|
|
295
|
+
})
|
|
296
|
+
|
|
297
|
+
test('removes multiple consecutive slashes', () => {
|
|
298
|
+
expect(rs._urlJoin('prefix//deep', 'file.js')).toBe('prefix/deep/file.js')
|
|
299
|
+
})
|
|
300
|
+
|
|
301
|
+
test('removes triple slashes', () => {
|
|
302
|
+
expect(rs._urlJoin('prefix///deep', 'file.js')).toBe('prefix/deep/file.js')
|
|
303
|
+
})
|
|
304
|
+
|
|
305
|
+
test('removes double slashes in middle of path', () => {
|
|
306
|
+
expect(rs._urlJoin('prefix', '//deep', 'file.js')).toBe('prefix/deep/file.js')
|
|
307
|
+
})
|
|
308
|
+
|
|
309
|
+
test('handles double slashes with leading slash', () => {
|
|
310
|
+
expect(rs._urlJoin('/prefix', '//deep', 'file.js')).toBe('/prefix/deep/file.js')
|
|
311
|
+
})
|
|
312
|
+
|
|
313
|
+
test('removes double slashes created by empty parts', () => {
|
|
314
|
+
expect(rs._urlJoin('prefix', '', '', 'file.js')).toBe('prefix/file.js')
|
|
315
|
+
})
|
|
316
|
+
})
|
|
317
|
+
|
|
318
|
+
describe('edge cases with slashes', () => {
|
|
319
|
+
test('handles part that is just a slash', () => {
|
|
320
|
+
expect(rs._urlJoin('prefix', '/', 'file.js')).toBe('prefix/file.js')
|
|
321
|
+
})
|
|
322
|
+
|
|
323
|
+
test('handles part that is just backslash', () => {
|
|
324
|
+
expect(rs._urlJoin('prefix', '\\', 'file.js')).toBe('prefix/file.js')
|
|
325
|
+
})
|
|
326
|
+
|
|
327
|
+
test('handles multiple slashes-only parts', () => {
|
|
328
|
+
expect(rs._urlJoin('prefix', '/', '/', 'file.js')).toBe('prefix/file.js')
|
|
329
|
+
})
|
|
330
|
+
|
|
331
|
+
test('handles leading slash with empty parts', () => {
|
|
332
|
+
expect(rs._urlJoin('/prefix', '', 'file.js')).toBe('/prefix/file.js')
|
|
333
|
+
})
|
|
334
|
+
})
|
|
335
|
+
|
|
336
|
+
describe('real-world S3 key scenarios', () => {
|
|
337
|
+
test('creates S3 key from prefix and filename', () => {
|
|
338
|
+
expect(rs._urlJoin('fakeprefix', 'index.js')).toBe('fakeprefix/index.js')
|
|
339
|
+
})
|
|
340
|
+
|
|
341
|
+
test('creates S3 key with nested directories', () => {
|
|
342
|
+
expect(rs._urlJoin('fakeprefix', 'deep', 'dir', 'index.js')).toBe('fakeprefix/deep/dir/index.js')
|
|
343
|
+
})
|
|
344
|
+
|
|
345
|
+
test('handles Windows-style prefix with trailing backslash', () => {
|
|
346
|
+
expect(rs._urlJoin('fakeprefix\\deep\\dir\\', 'index.js')).toBe('fakeprefix/deep/dir/index.js')
|
|
347
|
+
})
|
|
348
|
+
|
|
349
|
+
test('handles prefix with leading slash', () => {
|
|
350
|
+
expect(rs._urlJoin('/fakeprefix', 'index.js')).toBe('/fakeprefix/index.js')
|
|
351
|
+
})
|
|
352
|
+
|
|
353
|
+
test('handles relative directory path', () => {
|
|
354
|
+
expect(rs._urlJoin('deep', 'index.js')).toBe('deep/index.js')
|
|
355
|
+
})
|
|
356
|
+
|
|
357
|
+
test('handles empty prefix', () => {
|
|
358
|
+
expect(rs._urlJoin('', 'index.js')).toBe('index.js')
|
|
359
|
+
})
|
|
360
|
+
|
|
361
|
+
test('handles prefix with mixed separators', () => {
|
|
362
|
+
expect(rs._urlJoin('prefix\\deep', 'nested/file.js')).toBe('prefix/deep/nested/file.js')
|
|
363
|
+
})
|
|
364
|
+
})
|
|
365
|
+
|
|
366
|
+
describe('special characters and edge cases', () => {
|
|
367
|
+
test('handles file with no extension', () => {
|
|
368
|
+
expect(rs._urlJoin('prefix', 'file')).toBe('prefix/file')
|
|
369
|
+
})
|
|
370
|
+
|
|
371
|
+
test('handles file with multiple dots', () => {
|
|
372
|
+
expect(rs._urlJoin('prefix', 'file.min.js')).toBe('prefix/file.min.js')
|
|
373
|
+
})
|
|
374
|
+
|
|
375
|
+
test('handles path with spaces', () => {
|
|
376
|
+
expect(rs._urlJoin('prefix', 'file name.js')).toBe('prefix/file name.js')
|
|
377
|
+
})
|
|
378
|
+
|
|
379
|
+
test('handles path with special characters', () => {
|
|
380
|
+
expect(rs._urlJoin('prefix', 'file-name_123.js')).toBe('prefix/file-name_123.js')
|
|
381
|
+
})
|
|
382
|
+
|
|
383
|
+
test('handles very long path', () => {
|
|
384
|
+
const longPath = Array(10).fill('deep').join('/')
|
|
385
|
+
expect(rs._urlJoin('prefix', longPath, 'file.js')).toBe(`prefix/${longPath}/file.js`)
|
|
386
|
+
})
|
|
387
|
+
|
|
388
|
+
test('handles path starting with dot', () => {
|
|
389
|
+
expect(rs._urlJoin('prefix', '.hidden', 'file.js')).toBe('prefix/.hidden/file.js')
|
|
390
|
+
})
|
|
391
|
+
|
|
392
|
+
test('handles path with dot-dot', () => {
|
|
393
|
+
expect(rs._urlJoin('prefix', '..', 'file.js')).toBe('prefix/../file.js')
|
|
394
|
+
})
|
|
395
|
+
})
|
|
396
|
+
|
|
397
|
+
describe('empty and null handling', () => {
|
|
398
|
+
test('returns empty string for no arguments', () => {
|
|
399
|
+
expect(rs._urlJoin()).toBe('')
|
|
400
|
+
})
|
|
401
|
+
|
|
402
|
+
test('returns empty string for single empty string', () => {
|
|
403
|
+
expect(rs._urlJoin('')).toBe('')
|
|
404
|
+
})
|
|
405
|
+
|
|
406
|
+
test('filters out all empty parts', () => {
|
|
407
|
+
expect(rs._urlJoin('', '', '')).toBe('')
|
|
408
|
+
})
|
|
409
|
+
|
|
410
|
+
test('handles mix of valid and empty parts', () => {
|
|
411
|
+
expect(rs._urlJoin('', 'prefix', '', 'file.js', '')).toBe('prefix/file.js')
|
|
412
|
+
})
|
|
413
|
+
|
|
414
|
+
test('handles null in middle', () => {
|
|
415
|
+
expect(rs._urlJoin('prefix', null, 'file.js')).toBe('prefix/file.js')
|
|
416
|
+
})
|
|
417
|
+
|
|
418
|
+
test('handles undefined in middle', () => {
|
|
419
|
+
expect(rs._urlJoin('prefix', undefined, 'file.js')).toBe('prefix/file.js')
|
|
420
|
+
})
|
|
421
|
+
})
|
|
422
|
+
|
|
423
|
+
describe('complex combinations', () => {
|
|
424
|
+
test('combines all normalization features', () => {
|
|
425
|
+
expect(rs._urlJoin('/prefix\\deep/', '//nested/', '\\file.js')).toBe('/prefix/deep/nested/file.js')
|
|
426
|
+
})
|
|
427
|
+
|
|
428
|
+
test('handles Windows path with leading slash', () => {
|
|
429
|
+
expect(rs._urlJoin('/prefix\\deep\\dir', 'index.js')).toBe('/prefix/deep/dir/index.js')
|
|
430
|
+
})
|
|
431
|
+
|
|
432
|
+
test('handles multiple trailing slashes', () => {
|
|
433
|
+
expect(rs._urlJoin('prefix///', 'deep///', 'file.js')).toBe('prefix/deep/file.js')
|
|
434
|
+
})
|
|
435
|
+
|
|
436
|
+
test('handles mixed separators and slashes', () => {
|
|
437
|
+
expect(rs._urlJoin('prefix\\deep', '/nested', '\\file.js')).toBe('prefix/deep/nested/file.js')
|
|
438
|
+
})
|
|
439
|
+
})
|
|
440
|
+
})
|
|
441
|
+
|
|
179
442
|
test('folderExists missing prefix', async () => {
|
|
180
443
|
const rs = new RemoteStorage(global.fakeTVMResponse)
|
|
181
444
|
await expect(rs.folderExists()).rejects.toEqual(expect.objectContaining({ message: 'prefix must be a valid string' }))
|
|
@@ -191,6 +454,20 @@ describe('RemoteStorage', () => {
|
|
|
191
454
|
await expect(rs.uploadFile()).rejects.toEqual(expect.objectContaining({ message: 'prefix must be a valid string' }))
|
|
192
455
|
})
|
|
193
456
|
|
|
457
|
+
test('uploadFile with windows path', async () => {
|
|
458
|
+
const rs = new RemoteStorage(global.fakeTVMResponse)
|
|
459
|
+
// Create file using platform-agnostic paths
|
|
460
|
+
await global.addFakeFiles(vol, 'fakeDir', { 'deep/index.js': 'fake content' })
|
|
461
|
+
// Use platform-specific path for file reading (must match actual file system)
|
|
462
|
+
const filePath = path.join('fakeDir', 'deep', 'index.js')
|
|
463
|
+
// Test that Windows-style backslashes in prefix are normalized correctly
|
|
464
|
+
const prefixPath = 'fakeprefix\\deep\\dir\\'
|
|
465
|
+
await expect(rs.uploadFile(filePath, prefixPath, global.fakeConfig, 'fakeDir')).resolves.toBeUndefined()
|
|
466
|
+
expect(mockS3.putObject).toHaveBeenCalledWith(
|
|
467
|
+
expect.objectContaining({ Bucket: 'fake-bucket', Key: 'fakeprefix/deep/dir/index.js' })
|
|
468
|
+
)
|
|
469
|
+
})
|
|
470
|
+
|
|
194
471
|
test('uploadDir missing prefix', async () => {
|
|
195
472
|
const rs = new RemoteStorage(global.fakeTVMResponse)
|
|
196
473
|
await expect(rs.uploadDir()).rejects.toEqual(expect.objectContaining({ message: 'prefix must be a valid string' }))
|
|
@@ -327,6 +604,34 @@ describe('RemoteStorage', () => {
|
|
|
327
604
|
expect(response).toBe(null)
|
|
328
605
|
})
|
|
329
606
|
|
|
607
|
+
test('cachecontrol string for html when htmlCacheDuration is not defined', async () => {
|
|
608
|
+
const rs = new RemoteStorage(global.fakeTVMResponse)
|
|
609
|
+
const appConfigWithoutHtmlCache = global.configWithMissing(global.fakeConfig.app, 'htmlCacheDuration')
|
|
610
|
+
const response = rs._getCacheControlConfig('text/html', appConfigWithoutHtmlCache)
|
|
611
|
+
expect(response).toBe(null)
|
|
612
|
+
})
|
|
613
|
+
|
|
614
|
+
test('cachecontrol string for JS when jsCacheDuration is not defined', async () => {
|
|
615
|
+
const rs = new RemoteStorage(global.fakeTVMResponse)
|
|
616
|
+
const appConfigWithoutJsCache = global.configWithMissing(global.fakeConfig.app, 'jsCacheDuration')
|
|
617
|
+
const response = rs._getCacheControlConfig('application/javascript', appConfigWithoutJsCache)
|
|
618
|
+
expect(response).toBe(null)
|
|
619
|
+
})
|
|
620
|
+
|
|
621
|
+
test('cachecontrol string for CSS when cssCacheDuration is not defined', async () => {
|
|
622
|
+
const rs = new RemoteStorage(global.fakeTVMResponse)
|
|
623
|
+
const appConfigWithoutCssCache = global.configWithMissing(global.fakeConfig.app, 'cssCacheDuration')
|
|
624
|
+
const response = rs._getCacheControlConfig('text/css', appConfigWithoutCssCache)
|
|
625
|
+
expect(response).toBe(null)
|
|
626
|
+
})
|
|
627
|
+
|
|
628
|
+
test('cachecontrol string for image when imageCacheDuration is not defined', async () => {
|
|
629
|
+
const rs = new RemoteStorage(global.fakeTVMResponse)
|
|
630
|
+
const appConfigWithoutImageCache = global.configWithMissing(global.fakeConfig.app, 'imageCacheDuration')
|
|
631
|
+
const response = rs._getCacheControlConfig('image/jpeg', appConfigWithoutImageCache)
|
|
632
|
+
expect(response).toBe(null)
|
|
633
|
+
})
|
|
634
|
+
|
|
330
635
|
// response header tests
|
|
331
636
|
test('get response header from config with multiple rules', async () => {
|
|
332
637
|
const rs = new RemoteStorage(global.fakeTVMResponse)
|
|
@@ -606,30 +911,12 @@ describe('RemoteStorage', () => {
|
|
|
606
911
|
expect(putObjectCall.Metadata).not.toHaveProperty('adp-cache-control')
|
|
607
912
|
})
|
|
608
913
|
|
|
609
|
-
test('uploadFile
|
|
610
|
-
global.addFakeFiles(vol, 'fakeDir', { 'index.js': 'fake content' })
|
|
611
|
-
const rs = new RemoteStorage(global.fakeTVMResponse)
|
|
612
|
-
const fakeConfig = { ...global.fakeConfig, auditUserId: 'test-user-123' }
|
|
613
|
-
await rs.uploadFile('fakeDir/index.js', 'fakeprefix', fakeConfig, 'fakeDir')
|
|
614
|
-
const body = Buffer.from('fake content', 'utf8')
|
|
615
|
-
const expected = {
|
|
616
|
-
Bucket: 'fake-bucket',
|
|
617
|
-
Key: 'fakeprefix/index.js',
|
|
618
|
-
Body: body,
|
|
619
|
-
ContentType: 'application/javascript',
|
|
620
|
-
Metadata: expect.objectContaining({
|
|
621
|
-
'adp-AuditUserId': 'test-user-123'
|
|
622
|
-
})
|
|
623
|
-
}
|
|
624
|
-
expect(mockS3.putObject).toHaveBeenCalledWith(expect.objectContaining(expected))
|
|
625
|
-
})
|
|
626
|
-
|
|
627
|
-
test('uploadFile does not set Metadata when responseHeaders is empty and auditUserId is not set', async () => {
|
|
914
|
+
test('uploadFile does not set Metadata when responseHeaders is empty', async () => {
|
|
628
915
|
global.addFakeFiles(vol, 'fakeDir', { 'index.js': 'fake content' })
|
|
629
916
|
const rs = new RemoteStorage(global.fakeTVMResponse)
|
|
630
917
|
const fakeConfig = {
|
|
631
918
|
app: global.fakeConfig.app
|
|
632
|
-
// No web.response-headers
|
|
919
|
+
// No web.response-headers
|
|
633
920
|
}
|
|
634
921
|
await rs.uploadFile('fakeDir/index.js', 'fakeprefix', fakeConfig, 'fakeDir')
|
|
635
922
|
const body = Buffer.from('fake content', 'utf8')
|
|
@@ -643,12 +930,12 @@ describe('RemoteStorage', () => {
|
|
|
643
930
|
})
|
|
644
931
|
})
|
|
645
932
|
|
|
646
|
-
test('uploadFile sets CacheControl even when responseHeaders is empty
|
|
933
|
+
test('uploadFile sets CacheControl even when responseHeaders is empty', async () => {
|
|
647
934
|
global.addFakeFiles(vol, 'fakeDir', { 'index.html': 'fake content' })
|
|
648
935
|
const rs = new RemoteStorage(global.fakeTVMResponse)
|
|
649
936
|
const fakeConfig = {
|
|
650
937
|
app: global.fakeConfig.app
|
|
651
|
-
// No web.response-headers
|
|
938
|
+
// No web.response-headers
|
|
652
939
|
}
|
|
653
940
|
await rs.uploadFile('fakeDir/index.html', 'fakeprefix', fakeConfig, 'fakeDir')
|
|
654
941
|
const body = Buffer.from('fake content', 'utf8')
|