Skip to content

Commit 89a2b68

Browse files
authored
chore: Fix credentials.expiration (#1435)
In the SDK credentials.expiration now needs to be a `Date` object. This also removes `@aws-sdk/karma-credential-loader` See: aws/aws-sdk-js-v3#5890
1 parent 25f9610 commit 89a2b68

File tree

5 files changed

+148
-1041
lines changed

5 files changed

+148
-1041
lines changed

modules/integration-browser/karma.conf.js

+32-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
// Karma configuration
55
const { readFileSync } = require('fs')
6+
const credentialsPromise =
7+
require('@aws-sdk/credential-provider-node').defaultProvider()()
68
const webpack = require('webpack')
79

810
module.exports = function (config) {
@@ -66,8 +68,10 @@ module.exports = function (config) {
6668
},
6769
},
6870
plugins: [
71+
{
72+
'preprocessor:credentials': ['factory', createCredentialPreprocessor],
73+
},
6974
'karma-parallel',
70-
'@aws-sdk/karma-credential-loader',
7175
'karma-webpack',
7276
'karma-json-fixtures-preprocessor',
7377
'karma-chrome-launcher',
@@ -99,3 +103,30 @@ module.exports = function (config) {
99103
},
100104
})
101105
}
106+
107+
function createCredentialPreprocessor() {
108+
return async function (content, file, done) {
109+
// strip the extension from the file since it won't match the preprocessor pattern
110+
const fileName = file.originalPath
111+
// add region and credentials to each file
112+
const region = process.env.AWS_SMOKE_TEST_REGION || ''
113+
const credentials = await credentialsPromise
114+
// This will affect the generated (ES5) JS
115+
const regionCode = `var defaultRegion = '${region}';`
116+
const credentialsCode = `var credentials = ${JSON.stringify(credentials)};`
117+
// See: https://github.com/aws/aws-sdk-js-v3/issues/5890
118+
const expirationNeedsToBeDate = `credentials.expiration = new Date(credentials.expiration);`
119+
const isBrowser = `var isBrowser = true;`
120+
const contents = content.split('\n')
121+
let idx = -1
122+
for (let i = 0; i < contents.length; i++) {
123+
const line = contents[i]
124+
if (line.indexOf(fileName) !== -1) {
125+
idx = i
126+
break
127+
}
128+
}
129+
contents.splice(idx + 1, 0, regionCode, credentialsCode, expirationNeedsToBeDate, isBrowser)
130+
done(contents.join('\n'))
131+
}
132+
}

modules/integration-browser/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"@aws-crypto/client-browser": "file:../client-browser",
2121
"@aws-crypto/integration-vectors": "file:../integration-vectors",
2222
"@aws-sdk/credential-provider-node": "^3.362.0",
23-
"@aws-sdk/karma-credential-loader": "^3.38.0",
2423
"@aws-sdk/util-base64-browser": "^3.209.0",
2524
"@aws-sdk/util-utf8-browser": "^3.23.0",
2625
"@trust/keyto": "^1.0.1",

modules/material-management-browser/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"@aws-crypto/serialize": "file:../serialize",
2323
"@aws-crypto/web-crypto-backend": "file:../web-crypto-backend",
2424
"@aws-sdk/util-base64": "^3.374.0",
25+
"@aws-sdk/util-base64-browser": "^3.209.0",
2526
"tslib": "^2.2.0"
2627
},
2728
"sideEffects": false,

0 commit comments

Comments
 (0)