-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgetAWSConfig.test.js
104 lines (87 loc) · 2.71 KB
/
getAWSConfig.test.js
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
102
103
104
'use strict';
const path = require('path');
const getMFAToken = require('./getAWSConfig');
describe('ini file from env variable', () => {
test('will return a config object', () => {
const config = getMFAToken({
argv: [],
env: {
AWS_CONFIG_FILE: path.join(__dirname, '../fixtures/example.ini')
}
}, 'default');
expect(config.mfa_serial).toBe('arn:aws:iam::333333333333:mfa/env_default');
});
test('will return a config object for a specified profile', () => {
const config = getMFAToken({
argv: [],
env: {
AWS_CONFIG_FILE: path.join(__dirname, '../fixtures/example.ini')
}
}, 'env_two');
expect(config.mfa_serial).toBe('arn:aws:iam::444444444444:mfa/env_two');
});
test('will raise an error if config file not found', () => {
function attemptToGetMFAToken () {
getMFAToken({
argv: [],
env: {
AWS_CONFIG_FILE: path.join(__dirname, '../fixtures/not/found/example.ini')
}
}, 'default');
}
expect(attemptToGetMFAToken).toThrow('no such file or directory');
});
test('will raise an error if profile not found in config', () => {
function attemptToGetMFAToken () {
getMFAToken({
argv: [],
env: {
AWS_CONFIG_FILE: path.join(__dirname, '../fixtures/example.ini')
}
}, 'not_found');
}
expect(attemptToGetMFAToken).toThrow('aws profile not found in config');
});
});
describe('ini file from user\'s aws config file', () => {
test('will return a config object', () => {
const config = getMFAToken({
argv: [],
env: {
HOME: path.join(__dirname, '../fixtures')
}
}, 'default');
expect(config.mfa_serial).toBe('arn:aws:iam::111111111111:mfa/home_default');
});
test('will return a config object for a specified profile', () => {
const config = getMFAToken({
argv: [],
env: {
HOME: path.join(__dirname, '../fixtures')
}
}, 'home_two');
expect(config.mfa_serial).toBe('arn:aws:iam::222222222222:mfa/home_two');
});
test('will raise an error if config file not found', () => {
function attemptToGetMFAToken () {
getMFAToken({
argv: [],
env: {
HOME: path.join(__dirname, '../fixtures/not/found')
}
}, 'default');
}
expect(attemptToGetMFAToken).toThrow('no such file or directory');
});
test('will raise an error if profile not found in config', () => {
function attemptToGetMFAToken () {
getMFAToken({
argv: [],
env: {
HOME: path.join(__dirname, '../fixtures')
}
}, 'not_found');
}
expect(attemptToGetMFAToken).toThrow('aws profile not found in config');
});
});