-
-
Notifications
You must be signed in to change notification settings - Fork 38
/
session.test.js
73 lines (64 loc) · 3.18 KB
/
session.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
/**
* Tests.
*/
import { Role } from './role';
import { Session } from './session.js';
describe('isValid', () => {
test('returns false if expiration date is in the past', async () => {
const session = new Session({
accessKeyId: 'AAAAAABBBBBBCCCCCCDDDDDD',
role: new Role('Foobiz', 'arn:aws:iam::123456789:role/Foobiz', 'arn:aws:iam::123456789:saml-provider/GSuite'),
secretAccessKey: '0nKJNoiu9oSJBjkb+aDvVVVvvvB+ErF33r4',
expiresAt: new Date('2020-04-19T10:32:19.000Z'),
sessionToken: 'DMMDnnnnKAkjSJi///////oiuISHJbMNBMNjkhkbljkJHGJGUGALJBjbjksbKLJHlOOKmmNAhhB',
samlAssertion: 'T2NjdXB5IE1hcnMK'
});
expect(session.isValid()).toBeFalsy();
});
test('returns true if expiration date is in the future', async () => {
const session = new Session({
accessKeyId: 'AAAAAABBBBBBCCCCCCDDDDDD',
role: new Role('Foobiz', 'arn:aws:iam::123456789:role/Foobiz', 'arn:aws:iam::123456789:saml-provider/GSuite'),
secretAccessKey: '0nKJNoiu9oSJBjkb+aDvVVVvvvB+ErF33r4',
expiresAt: new Date(`${new Date().getFullYear() + 1}-04-19T10:32:19.000Z`),
sessionToken: 'DMMDnnnnKAkjSJi///////oiuISHJbMNBMNjkhkbljkJHGJGUGALJBjbjksbKLJHlOOKmmNAhhB',
samlAssertion: 'T2NjdXB5IE1hcnMK'
});
expect(session.isValid()).toBeTruthy();
});
});
describe('toIni', () => {
test('returns content as an ini-compatible structure', () => {
const session = new Session({
accessKeyId: 'AAAAAABBBBBBCCCCCCDDDDDD',
role: new Role('Foobiz', 'arn:aws:iam::123456789:role/Foobiz', 'arn:aws:iam::123456789:saml-provider/GSuite'),
secretAccessKey: '0nKJNoiu9oSJBjkb+aDvVVVvvvB+ErF33r4',
expiresAt: new Date('2020-04-19T10:32:19.000Z'),
sessionToken: 'DMMDnnnnKAkjSJi///////oiuISHJbMNBMNjkhkbljkJHGJGUGALJBjbjksbKLJHlOOKmmNAhhB',
samlAssertion: 'T2NjdXB5IE1hcnMK'
});
expect(session.toIni('test')).toEqual({
aws_access_key_id: 'AAAAAABBBBBBCCCCCCDDDDDD',
aws_role_arn: 'arn:aws:iam::123456789:role/Foobiz',
aws_role_name: 'Foobiz',
aws_role_principal_arn: 'arn:aws:iam::123456789:saml-provider/GSuite',
aws_secret_access_key: '0nKJNoiu9oSJBjkb+aDvVVVvvvB+ErF33r4',
aws_session_expiration: '2020-04-19T10:32:19.000Z',
aws_session_token: 'DMMDnnnnKAkjSJi///////oiuISHJbMNBMNjkhkbljkJHGJGUGALJBjbjksbKLJHlOOKmmNAhhB',
aws_saml_assertion: 'T2NjdXB5IE1hcnMK'
});
});
});
describe('toJSON', () => {
test('returns content as JSON', () => {
const session = new Session({
accessKeyId: 'AAAAAABBBBBBCCCCCCDDDDDD',
role: new Role('Foobiz', 'arn:aws:iam::123456789:role/Foobiz', 'arn:aws:iam::123456789:saml-provider/GSuite'),
secretAccessKey: '0nKJNoiu9oSJBjkb+aDvVVVvvvB+ErF33r4',
expiresAt: new Date('2020-04-19T10:32:19.000Z'),
sessionToken: 'DMMDnnnnKAkjSJi///////oiuISHJbMNBMNjkhkbljkJHGJGUGALJBjbjksbKLJHlOOKmmNAhhB',
samlAssertion: 'T2NjdXB5IE1hcnMK'
});
expect(session.toJSON()).toEqual(`{"Version":1,"AccessKeyId":"AAAAAABBBBBBCCCCCCDDDDDD","SecretAccessKey":"0nKJNoiu9oSJBjkb+aDvVVVvvvB+ErF33r4","SessionToken":"DMMDnnnnKAkjSJi///////oiuISHJbMNBMNjkhkbljkJHGJGUGALJBjbjksbKLJHlOOKmmNAhhB","Expiration":"2020-04-19T10:32:19.000Z"}`);
});
});