Skip to content

chore: Fix credentials.expiration #1435

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion modules/integration-browser/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

// Karma configuration
const { readFileSync } = require('fs')
const credentialsPromise =
require('@aws-sdk/credential-provider-node').defaultProvider()()
const webpack = require('webpack')

module.exports = function (config) {
Expand Down Expand Up @@ -66,8 +68,10 @@ module.exports = function (config) {
},
},
plugins: [
{
'preprocessor:credentials': ['factory', createCredentialPreprocessor],
},
'karma-parallel',
'@aws-sdk/karma-credential-loader',
'karma-webpack',
'karma-json-fixtures-preprocessor',
'karma-chrome-launcher',
Expand Down Expand Up @@ -99,3 +103,30 @@ module.exports = function (config) {
},
})
}

function createCredentialPreprocessor() {
return async function (content, file, done) {
// strip the extension from the file since it won't match the preprocessor pattern
const fileName = file.originalPath
// add region and credentials to each file
const region = process.env.AWS_SMOKE_TEST_REGION || ''
const credentials = await credentialsPromise
// This will affect the generated (ES5) JS
const regionCode = `var defaultRegion = '${region}';`
const credentialsCode = `var credentials = ${JSON.stringify(credentials)};`
// See: https://github.com/aws/aws-sdk-js-v3/issues/5890
const expirationNeedsToBeDate = `credentials.expiration = new Date(credentials.expiration);`
const isBrowser = `var isBrowser = true;`
const contents = content.split('\n')
let idx = -1
for (let i = 0; i < contents.length; i++) {
const line = contents[i]
if (line.indexOf(fileName) !== -1) {
idx = i
break
}
}
contents.splice(idx + 1, 0, regionCode, credentialsCode, expirationNeedsToBeDate, isBrowser)
done(contents.join('\n'))
}
}
1 change: 0 additions & 1 deletion modules/integration-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"@aws-crypto/client-browser": "file:../client-browser",
"@aws-crypto/integration-vectors": "file:../integration-vectors",
"@aws-sdk/credential-provider-node": "^3.362.0",
"@aws-sdk/karma-credential-loader": "^3.38.0",
"@aws-sdk/util-base64-browser": "^3.209.0",
"@aws-sdk/util-utf8-browser": "^3.23.0",
"@trust/keyto": "^1.0.1",
Expand Down
1 change: 1 addition & 0 deletions modules/material-management-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@aws-crypto/serialize": "file:../serialize",
"@aws-crypto/web-crypto-backend": "file:../web-crypto-backend",
"@aws-sdk/util-base64": "^3.374.0",
"@aws-sdk/util-base64-browser": "^3.209.0",
"tslib": "^2.2.0"
},
"sideEffects": false,
Expand Down
Loading
Loading