-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAwsCredentials.test.js
More file actions
101 lines (85 loc) · 2.48 KB
/
AwsCredentials.test.js
File metadata and controls
101 lines (85 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
const Test = require('thunk-test')
const assert = require('assert')
const fs = require('fs')
const AwsCredentials = require('./AwsCredentials')
const test = new Test('AwsCredentials', async function integration() {
const credentialsFilename = 'credentials-test'
const credentialsFileDirname = '.aws-test'
try {
await fs.promises.mkdir(`${__dirname}/../${credentialsFileDirname}`)
} catch {
await fs.promises.rm(`${__dirname}/../${credentialsFileDirname}`, { recursive: true })
await fs.promises.mkdir(`${__dirname}/../${credentialsFileDirname}`)
}
await fs.promises.writeFile(`${__dirname}/../${credentialsFileDirname}/${credentialsFilename}`, `
[default]
aws_access_key_id = X1
aws_secret_access_key = X2
[presidium]
aws_access_key_id = AAA
aws_secret_access_key = BBB
[missing-access-key-id]
aws_secret_access_key = BBB
[missing-secret-access-key]
aws_access_key_id = AAA
`.trim())
{
const awsCreds = await AwsCredentials('presidium', {
credentialsFileDirname,
credentialsFilename,
})
assert.equal(awsCreds.accessKeyId, 'AAA')
assert.equal(awsCreds.secretAccessKey, 'BBB')
}
{
const awsCreds = await AwsCredentials('default', {
credentialsFileDirname,
credentialsFilename,
})
assert.equal(awsCreds.accessKeyId, 'X1')
assert.equal(awsCreds.secretAccessKey, 'X2')
}
{
const awsCreds = await AwsCredentials(undefined, {
credentialsFileDirname,
credentialsFilename,
})
assert.equal(awsCreds.accessKeyId, 'X1')
assert.equal(awsCreds.secretAccessKey, 'X2')
}
{
await assert.rejects(
async () => {
await AwsCredentials('missing-access-key-id', {
credentialsFileDirname,
credentialsFilename,
})
},
new Error('unable to find aws_access_key_id for profile missing-access-key-id')
)
}
{
await assert.rejects(
async () => {
await AwsCredentials('missing-secret-access-key', {
credentialsFileDirname,
credentialsFilename,
})
},
new Error('unable to find aws_secret_access_key for profile missing-secret-access-key')
)
}
await fs.promises.rm(`${__dirname}/../${credentialsFileDirname}`, { recursive: true })
await assert.rejects(
AwsCredentials('presidium', {
credentialsFileDirname,
credentialsFilename,
recurse: false,
}),
new Error('Missing .aws/credentials file')
)
}).case()
if (process.argv[1] == __filename) {
test()
}
module.exports = test