2
2
3
3
const { expect } = require ( 'chai' ) ;
4
4
const requirements = require ( './requirements.helper' ) ;
5
- const { loadCredentials } = require ( '../lib/credentialsProvider' ) ;
5
+ const { loadCredentials, isEmptyCredentials } = require ( '../lib/credentialsProvider' ) ;
6
6
7
7
const originalAccessKeyId = process . env . AWS_ACCESS_KEY_ID ;
8
8
const originalSecretAccessKey = process . env . AWS_SECRET_ACCESS_KEY ;
9
9
const originalSessionToken = process . env . AWS_SESSION_TOKEN ;
10
10
11
11
describe ( '#loadCredentials' , function ( ) {
12
- const accessKey = 'example' ;
13
- const secretKey = 'example' ;
14
- const sessionToken = 'example' ;
15
-
16
- after ( function ( ) {
17
- // After the entire suite runs, set the env back for the rest of the test run.
18
- process . env . AWS_ACCESS_KEY_ID = originalAccessKeyId ;
19
- process . env . AWS_SECRET_ACCESS_KEY = originalSecretAccessKey ;
20
- process . env . AWS_SESSION_TOKEN = originalSessionToken ;
21
- } ) ;
12
+ context ( 'isEmptyCredentials()' , ( ) => {
13
+ it ( 'returns true for an empty object' , ( ) => {
14
+ expect ( isEmptyCredentials ( 'rainyCloud' , { rainyCloud : { } } ) ) . to . be . true ;
15
+ } ) ;
22
16
23
- context ( 'when the credential provider finds credentials' , function ( ) {
24
- before ( function ( ) {
25
- process . env . AWS_ACCESS_KEY_ID = accessKey ;
26
- process . env . AWS_SECRET_ACCESS_KEY = secretKey ;
27
- process . env . AWS_SESSION_TOKEN = sessionToken ;
17
+ it ( 'returns false for an object with keys' , ( ) => {
18
+ expect ( isEmptyCredentials ( 'rainyCloud' , { rainyCloud : { password : 'secret' } } ) ) . to . be . false ;
28
19
} ) ;
29
20
30
- context ( 'when the credentials are empty' , function ( ) {
31
- const kmsProviders = { } ;
21
+ it ( 'returns false for an nullish credentials' , ( ) => {
22
+ expect ( isEmptyCredentials ( 'rainyCloud' , { rainyCloud : null } ) ) . to . be . false ;
23
+ expect ( isEmptyCredentials ( 'rainyCloud' , { rainyCloud : undefined } ) ) . to . be . false ;
24
+ expect ( isEmptyCredentials ( 'rainyCloud' , { } ) ) . to . be . false ;
25
+ } ) ;
32
26
33
- before ( function ( ) {
34
- if ( ! requirements . credentialProvidersInstalled . aws ) {
35
- this . currentTest . skipReason = 'Cannot refresh credentials without sdk provider' ;
36
- this . currentTest . skip ( ) ;
37
- return ;
38
- }
39
- } ) ;
27
+ it ( 'returns false for non object credentials' , ( ) => {
28
+ expect ( isEmptyCredentials ( 'rainyCloud' , { rainyCloud : 0 } ) ) . to . be . false ;
29
+ expect ( isEmptyCredentials ( 'rainyCloud' , { rainyCloud : false } ) ) . to . be . false ;
30
+ expect ( isEmptyCredentials ( 'rainyCloud' , { rainyCloud : Symbol ( 'secret' ) } ) ) . to . be . false ;
31
+ } ) ;
32
+ } ) ;
40
33
41
- it ( 'refreshes the aws credentials ', async function ( ) {
42
- const providers = await loadCredentials ( kmsProviders ) ;
43
- expect ( providers ) . to . deep . equal ( {
44
- aws : {
45
- accessKeyId : accessKey ,
46
- secretAccessKey : secretKey ,
47
- sessionToken : sessionToken
48
- }
49
- } ) ;
50
- } ) ;
34
+ context ( 'when using aws', ( ) => {
35
+ const accessKey = 'example' ;
36
+ const secretKey = 'example' ;
37
+ const sessionToken = 'example' ;
38
+
39
+ after ( function ( ) {
40
+ // After the entire suite runs, set the env back for the rest of the test run.
41
+ process . env . AWS_ACCESS_KEY_ID = originalAccessKeyId ;
42
+ process . env . AWS_SECRET_ACCESS_KEY = originalSecretAccessKey ;
43
+ process . env . AWS_SESSION_TOKEN = originalSessionToken ;
51
44
} ) ;
52
45
53
- context ( 'when the credentials are not empty' , function ( ) {
54
- context ( 'when aws is empty' , function ( ) {
55
- const kmsProviders = {
56
- local : {
57
- key : Buffer . alloc ( 96 )
58
- } ,
59
- aws : { }
60
- } ;
46
+ context ( 'when the credential provider finds credentials' , function ( ) {
47
+ before ( function ( ) {
48
+ process . env . AWS_ACCESS_KEY_ID = accessKey ;
49
+ process . env . AWS_SECRET_ACCESS_KEY = secretKey ;
50
+ process . env . AWS_SESSION_TOKEN = sessionToken ;
51
+ } ) ;
52
+
53
+ context ( 'when the credentials are empty' , function ( ) {
54
+ const kmsProviders = { aws : { } } ;
61
55
62
56
before ( function ( ) {
63
57
if ( ! requirements . credentialProvidersInstalled . aws ) {
@@ -67,12 +61,9 @@ describe('#loadCredentials', function () {
67
61
}
68
62
} ) ;
69
63
70
- it ( 'refreshes only the aws credentials' , async function ( ) {
64
+ it ( 'refreshes the aws credentials' , async function ( ) {
71
65
const providers = await loadCredentials ( kmsProviders ) ;
72
66
expect ( providers ) . to . deep . equal ( {
73
- local : {
74
- key : Buffer . alloc ( 96 )
75
- } ,
76
67
aws : {
77
68
accessKeyId : accessKey ,
78
69
secretAccessKey : secretKey ,
@@ -82,81 +73,84 @@ describe('#loadCredentials', function () {
82
73
} ) ;
83
74
} ) ;
84
75
85
- context ( 'when aws is not empty' , function ( ) {
86
- const kmsProviders = {
87
- local : {
88
- key : Buffer . alloc ( 96 )
89
- } ,
90
- aws : {
91
- accessKeyId : 'example'
92
- }
93
- } ;
94
-
95
- before ( function ( ) {
96
- if ( ! requirements . credentialProvidersInstalled . aws ) {
97
- this . currentTest . skipReason = 'Cannot refresh credentials without sdk provider' ;
98
- this . currentTest . skip ( ) ;
99
- return ;
100
- }
101
- } ) ;
102
-
103
- it ( 'does not refresh credentials' , async function ( ) {
104
- const providers = await loadCredentials ( kmsProviders ) ;
105
- expect ( providers ) . to . deep . equal ( kmsProviders ) ;
106
- } ) ;
107
- } ) ;
108
-
109
- context ( 'when aws does not exist' , function ( ) {
110
- const kmsProviders = {
111
- local : {
112
- key : Buffer . alloc ( 96 )
113
- }
114
- } ;
76
+ context ( 'when the credentials are not empty' , function ( ) {
77
+ context ( 'when aws is empty' , function ( ) {
78
+ const kmsProviders = {
79
+ local : {
80
+ key : Buffer . alloc ( 96 )
81
+ } ,
82
+ aws : { }
83
+ } ;
84
+
85
+ before ( function ( ) {
86
+ if ( ! requirements . credentialProvidersInstalled . aws ) {
87
+ this . currentTest . skipReason = 'Cannot refresh credentials without sdk provider' ;
88
+ this . currentTest . skip ( ) ;
89
+ return ;
90
+ }
91
+ } ) ;
115
92
116
- before ( function ( ) {
117
- if ( ! requirements . credentialProvidersInstalled . aws ) {
118
- this . currentTest . skipReason = 'Cannot refresh credentials without sdk provider' ;
119
- this . currentTest . skip ( ) ;
120
- return ;
121
- }
93
+ it ( 'refreshes only the aws credentials' , async function ( ) {
94
+ const providers = await loadCredentials ( kmsProviders ) ;
95
+ expect ( providers ) . to . deep . equal ( {
96
+ local : {
97
+ key : Buffer . alloc ( 96 )
98
+ } ,
99
+ aws : {
100
+ accessKeyId : accessKey ,
101
+ secretAccessKey : secretKey ,
102
+ sessionToken : sessionToken
103
+ }
104
+ } ) ;
105
+ } ) ;
122
106
} ) ;
123
107
124
- it ( 'refreshes ony the aws credentials' , async function ( ) {
125
- const providers = await loadCredentials ( kmsProviders ) ;
126
- expect ( providers ) . to . deep . equal ( {
108
+ context ( 'when aws is not empty' , function ( ) {
109
+ const kmsProviders = {
127
110
local : {
128
111
key : Buffer . alloc ( 96 )
129
112
} ,
130
113
aws : {
131
- accessKeyId : accessKey ,
132
- secretAccessKey : secretKey ,
133
- sessionToken : sessionToken
114
+ accessKeyId : 'example'
115
+ }
116
+ } ;
117
+
118
+ before ( function ( ) {
119
+ if ( ! requirements . credentialProvidersInstalled . aws ) {
120
+ this . currentTest . skipReason = 'Cannot refresh credentials without sdk provider' ;
121
+ this . currentTest . skip ( ) ;
122
+ return ;
134
123
}
135
124
} ) ;
125
+
126
+ it ( 'does not refresh credentials' , async function ( ) {
127
+ const providers = await loadCredentials ( kmsProviders ) ;
128
+ expect ( providers ) . to . deep . equal ( kmsProviders ) ;
129
+ } ) ;
136
130
} ) ;
137
131
} ) ;
138
132
} ) ;
139
- } ) ;
140
133
141
- context ( 'when the sdk is not installed' , function ( ) {
142
- const kmsProviders = {
143
- local : {
144
- key : Buffer . alloc ( 96 )
145
- } ,
146
- aws : { }
147
- } ;
148
-
149
- before ( function ( ) {
150
- if ( requirements . credentialProvidersInstalled . aws ) {
151
- this . currentTest . skipReason = 'Credentials will be loaded when sdk present' ;
152
- this . currentTest . skip ( ) ;
153
- return ;
154
- }
155
- } ) ;
134
+ context ( 'when the sdk is not installed' , function ( ) {
135
+ const kmsProviders = {
136
+ local : {
137
+ key : Buffer . alloc ( 96 )
138
+ } ,
139
+ aws : { }
140
+ } ;
156
141
157
- it ( 'does not refresh credentials' , async function ( ) {
158
- const providers = await loadCredentials ( kmsProviders ) ;
159
- expect ( providers ) . to . deep . equal ( kmsProviders ) ;
142
+ before ( function ( ) {
143
+ if ( requirements . credentialProvidersInstalled . aws ) {
144
+ this . currentTest . skipReason = 'Credentials will be loaded when sdk present' ;
145
+ this . currentTest . skip ( ) ;
146
+ return ;
147
+ }
148
+ } ) ;
149
+
150
+ it ( 'does not refresh credentials' , async function ( ) {
151
+ const providers = await loadCredentials ( kmsProviders ) ;
152
+ expect ( providers ) . to . deep . equal ( kmsProviders ) ;
153
+ } ) ;
160
154
} ) ;
161
155
} ) ;
162
156
} ) ;
0 commit comments