-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgetMFAToken.test.js
52 lines (42 loc) · 1.08 KB
/
getMFAToken.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
'use strict';
const concat = require('concat-stream');
const { PassThrough } = require('stream');
const getMFAToken = require('./getMFAToken');
test('will print MFA token prompt to stderr', () => {
expect.assertions(1);
return new Promise((resolve, reject) => {
const stderr = new PassThrough();
const stdin = new PassThrough();
stderr.pipe(concat((output) => {
expect(output.toString('utf8')).toMatch('🔒 AWS MFA token:');
resolve();
}));
setTimeout(() => {
stdin.write('12345\n');
}, 1);
return getMFAToken({
argv: [],
env: {},
stderr,
stdin,
stdout: new PassThrough()
}).then(() => stderr.end(), () => stderr.end()).catch(reject);
});
});
test('will resolve with the MFA token', () => {
expect.assertions(1);
const stderr = new PassThrough();
const stdin = new PassThrough();
setTimeout(() => {
stdin.write('12345\n');
}, 1);
return getMFAToken({
argv: [],
env: {},
stderr,
stdin,
stdout: new PassThrough()
}).then((token) => {
expect(token).toBe('12345');
});
});