@creator.co/wapi 1.2.2 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.cjs +29 -22
- package/.github/workflows/npmpublish.yml +2 -5
- package/.github/workflows/prs.yml +1 -1
- package/README.md +1 -3
- package/dist/index.d.ts +11 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/jest.config.d.ts +3 -0
- package/dist/jest.config.js +34 -0
- package/dist/jest.config.js.map +1 -0
- package/dist/package.json +64 -0
- package/dist/src/API/Request.d.ts +140 -0
- package/dist/src/API/Request.js +182 -0
- package/dist/src/API/Request.js.map +1 -0
- package/dist/src/API/Response.d.ts +256 -0
- package/dist/src/API/Response.js +398 -0
- package/dist/src/API/Response.js.map +1 -0
- package/dist/src/API/Utils.d.ts +63 -0
- package/dist/src/API/Utils.js +104 -0
- package/dist/src/API/Utils.js.map +1 -0
- package/dist/src/BaseEvent/EventProcessor.d.ts +81 -0
- package/dist/src/BaseEvent/EventProcessor.js +182 -0
- package/dist/src/BaseEvent/EventProcessor.js.map +1 -0
- package/dist/src/BaseEvent/Process.d.ts +74 -0
- package/dist/src/BaseEvent/Process.js +142 -0
- package/dist/src/BaseEvent/Process.js.map +1 -0
- package/dist/src/BaseEvent/Transaction.d.ts +29 -0
- package/dist/src/BaseEvent/Transaction.js +244 -0
- package/dist/src/BaseEvent/Transaction.js.map +1 -0
- package/dist/src/Config/Configuration.d.ts +131 -0
- package/dist/src/Config/Configuration.js +153 -0
- package/dist/src/Config/Configuration.js.map +1 -0
- package/dist/src/Config/EnvironmentVar.d.ts +101 -0
- package/dist/src/Config/EnvironmentVar.js +213 -0
- package/dist/src/Config/EnvironmentVar.js.map +1 -0
- package/dist/src/Crypto/Crypto.d.ts +57 -0
- package/dist/src/Crypto/Crypto.js +126 -0
- package/dist/src/Crypto/Crypto.js.map +1 -0
- package/dist/src/Crypto/JWT.d.ts +64 -0
- package/dist/src/Crypto/JWT.js +74 -0
- package/dist/src/Crypto/JWT.js.map +1 -0
- package/dist/src/Globals.d.ts +161 -0
- package/dist/src/Globals.js +173 -0
- package/dist/src/Globals.js.map +1 -0
- package/dist/src/Logger/Logger.d.ts +180 -0
- package/dist/src/Logger/Logger.js +412 -0
- package/dist/src/Logger/Logger.js.map +1 -0
- package/dist/src/Mailer/Mailer.d.ts +107 -0
- package/dist/src/Mailer/Mailer.js +313 -0
- package/dist/src/Mailer/Mailer.js.map +1 -0
- package/dist/src/Publisher/Publisher.d.ts +47 -0
- package/dist/src/Publisher/Publisher.js +141 -0
- package/dist/src/Publisher/Publisher.js.map +1 -0
- package/dist/src/Server/RouteResolver.d.ts +41 -0
- package/dist/src/Server/RouteResolver.js +135 -0
- package/dist/src/Server/RouteResolver.js.map +1 -0
- package/dist/src/Server/Router.d.ts +104 -0
- package/dist/src/Server/Router.js +45 -0
- package/dist/src/Server/Router.js.map +1 -0
- package/dist/src/Server/lib/ContainerServer.d.ts +58 -0
- package/dist/src/Server/lib/ContainerServer.js +143 -0
- package/dist/src/Server/lib/ContainerServer.js.map +1 -0
- package/dist/src/Server/lib/Server.d.ts +60 -0
- package/dist/src/Server/lib/Server.js +137 -0
- package/dist/src/Server/lib/Server.js.map +1 -0
- package/dist/src/Server/lib/container/GenericHandler.d.ts +4 -0
- package/dist/src/Server/lib/container/GenericHandler.js +138 -0
- package/dist/src/Server/lib/container/GenericHandler.js.map +1 -0
- package/dist/src/Server/lib/container/GenericHandlerEvent.d.ts +67 -0
- package/dist/src/Server/lib/container/GenericHandlerEvent.js +189 -0
- package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +1 -0
- package/dist/src/Server/lib/container/HealthHandler.d.ts +3 -0
- package/dist/src/Server/lib/container/HealthHandler.js +45 -0
- package/dist/src/Server/lib/container/HealthHandler.js.map +1 -0
- package/dist/src/Server/lib/container/Proxy.d.ts +95 -0
- package/dist/src/Server/lib/container/Proxy.js +201 -0
- package/dist/src/Server/lib/container/Proxy.js.map +1 -0
- package/dist/src/Server/lib/container/Utils.d.ts +18 -0
- package/dist/src/Server/lib/container/Utils.js +84 -0
- package/dist/src/Server/lib/container/Utils.js.map +1 -0
- package/dist/src/Validation/Validator.d.ts +21 -0
- package/dist/src/Validation/Validator.js +48 -0
- package/dist/src/Validation/Validator.js.map +1 -0
- package/index.ts +12 -10
- package/jest.config.ts +14 -21
- package/package.json +3 -3
- package/src/API/Request.ts +17 -35
- package/src/API/Response.ts +24 -42
- package/src/API/Utils.ts +5 -7
- package/src/BaseEvent/EventProcessor.ts +16 -24
- package/src/BaseEvent/Process.ts +7 -12
- package/src/BaseEvent/Transaction.ts +25 -43
- package/src/Config/Configuration.ts +8 -14
- package/src/Config/EnvironmentVar.ts +10 -20
- package/src/Crypto/Crypto.ts +10 -10
- package/src/Crypto/JWT.ts +4 -10
- package/src/Globals.ts +19 -25
- package/src/Logger/Logger.ts +36 -51
- package/src/Mailer/Mailer.ts +19 -31
- package/src/Publisher/Publisher.ts +7 -12
- package/src/Server/RouteResolver.ts +5 -6
- package/src/Server/Router.ts +7 -12
- package/src/Server/lib/ContainerServer.ts +5 -5
- package/src/Server/lib/Server.ts +26 -38
- package/src/Server/lib/container/GenericHandler.ts +8 -13
- package/src/Server/lib/container/GenericHandlerEvent.ts +21 -35
- package/src/Server/lib/container/HealthHandler.ts +2 -2
- package/src/Server/lib/container/Proxy.ts +26 -38
- package/src/Server/lib/container/Utils.ts +2 -2
- package/src/Validation/Validator.ts +6 -6
- package/tests/API/Request.test.ts +107 -111
- package/tests/API/Response.test.ts +86 -91
- package/tests/API/Utils.test.ts +64 -64
- package/tests/BaseEvent/EventProcessor.test.ts +68 -84
- package/tests/BaseEvent/Process.test.ts +11 -11
- package/tests/BaseEvent/Transaction.test.ts +44 -53
- package/tests/Config/Config.test.ts +50 -50
- package/tests/Config/EnvironmentVar.test.ts +50 -59
- package/tests/Crypto/Crypto.test.ts +20 -22
- package/tests/Crypto/JWT.test.ts +40 -40
- package/tests/Logger/Logger.test.ts +24 -36
- package/tests/Mailer/Mailer.test.ts +21 -29
- package/tests/Publisher/Publisher.test.ts +18 -18
- package/tests/Server/RouteResolver.test.ts +56 -59
- package/tests/Server/Router.test.ts +16 -16
- package/tests/Server/lib/ContainerServer.test.ts +83 -85
- package/tests/Server/lib/Server.test.ts +4 -4
- package/tests/Server/lib/container/GenericHandler.test.ts +31 -41
- package/tests/Server/lib/container/GenericHandlerEvent.test.ts +35 -36
- package/tests/Server/lib/container/HealthHandler.test.ts +7 -7
- package/tests/Server/lib/container/Proxy.test.ts +66 -79
- package/tests/Server/lib/container/Utils.test.ts +16 -17
- package/tests/Test.utils.ts +9 -9
- package/tests/Validation/Validator.test.ts +28 -40
- package/tests/main.test.ts +2 -2
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
import { SSMClient, GetParameterCommand } from
|
|
2
|
-
import { mockClient } from
|
|
3
|
-
import { expect } from
|
|
1
|
+
import { SSMClient, GetParameterCommand } from '@aws-sdk/client-ssm'
|
|
2
|
+
import { mockClient } from 'aws-sdk-client-mock'
|
|
3
|
+
import { expect } from 'chai'
|
|
4
4
|
|
|
5
|
-
import Configuration from
|
|
6
|
-
import { SampleConfig, SampleConfigSchema } from
|
|
5
|
+
import Configuration from '../../src/Config/Configuration'
|
|
6
|
+
import { SampleConfig, SampleConfigSchema } from '../Test.utils'
|
|
7
7
|
|
|
8
8
|
const SSMMock = mockClient(SSMClient)
|
|
9
|
-
const config = new Configuration<SampleConfigSchema>(SampleConfig,
|
|
9
|
+
const config = new Configuration<SampleConfigSchema>(SampleConfig, 'my-prefix')
|
|
10
10
|
describe(`Optional remote environment`, () => {
|
|
11
11
|
// reset mock
|
|
12
12
|
beforeEach(() => {
|
|
13
13
|
SSMMock.reset()
|
|
14
|
-
config[
|
|
14
|
+
config['resetCache']()
|
|
15
15
|
})
|
|
16
16
|
|
|
17
|
-
test(
|
|
17
|
+
test('Does not accept sync get', async () => {
|
|
18
18
|
let err = null
|
|
19
19
|
try {
|
|
20
20
|
// @ts-ignore
|
|
21
|
-
config.get(
|
|
21
|
+
config.get('TOKEN_SECRET')
|
|
22
22
|
} catch (e) {
|
|
23
23
|
err = e
|
|
24
24
|
}
|
|
25
25
|
expect(err).is.not.null
|
|
26
|
-
expect(err?.[
|
|
26
|
+
expect(err?.['message']).is.not.null
|
|
27
27
|
})
|
|
28
28
|
|
|
29
|
-
test(
|
|
29
|
+
test('Optional value with null value', async () => {
|
|
30
30
|
SSMMock.on(GetParameterCommand).resolves({
|
|
31
31
|
Parameter: {
|
|
32
32
|
Value: undefined,
|
|
33
33
|
},
|
|
34
34
|
})
|
|
35
|
-
const token = await config.asyncGet(
|
|
35
|
+
const token = await config.asyncGet('TOKEN_SECRET_FALSY')
|
|
36
36
|
expect(token).is.undefined
|
|
37
37
|
})
|
|
38
38
|
|
|
39
|
-
test(
|
|
39
|
+
test('Optional value with empty response', async () => {
|
|
40
40
|
SSMMock.on(GetParameterCommand).resolves({})
|
|
41
|
-
const token = await config.asyncGet(
|
|
41
|
+
const token = await config.asyncGet('TOKEN_SECRET_FALSY')
|
|
42
42
|
expect(token).is.undefined
|
|
43
43
|
})
|
|
44
44
|
|
|
45
|
-
test(
|
|
46
|
-
const value =
|
|
45
|
+
test('Optional value with valid response', async () => {
|
|
46
|
+
const value = 'abc'
|
|
47
47
|
SSMMock.on(GetParameterCommand).resolves({
|
|
48
48
|
Parameter: {
|
|
49
49
|
Value: value,
|
|
50
50
|
},
|
|
51
51
|
})
|
|
52
|
-
const token = await config.asyncGet(
|
|
52
|
+
const token = await config.asyncGet('TOKEN_SECRET_FALSY')
|
|
53
53
|
expect(token).is.not.undefined
|
|
54
54
|
expect(token).to.be.equals(value)
|
|
55
55
|
})
|
|
56
56
|
|
|
57
|
-
test(
|
|
58
|
-
SSMMock.on(GetParameterCommand).rejects(new Error(
|
|
59
|
-
const token = await config.asyncGet(
|
|
57
|
+
test('Optional value rejection', async () => {
|
|
58
|
+
SSMMock.on(GetParameterCommand).rejects(new Error('failed!'))
|
|
59
|
+
const token = await config.asyncGet('TOKEN_SECRET_FALSY')
|
|
60
60
|
expect(token).is.undefined
|
|
61
61
|
})
|
|
62
62
|
})
|
|
@@ -65,22 +65,22 @@ describe(`Required remote environment`, () => {
|
|
|
65
65
|
// reset mock
|
|
66
66
|
beforeEach(() => {
|
|
67
67
|
SSMMock.reset()
|
|
68
|
-
config[
|
|
68
|
+
config['resetCache']()
|
|
69
69
|
})
|
|
70
70
|
|
|
71
|
-
test(
|
|
71
|
+
test('Does not accept sync get', async () => {
|
|
72
72
|
let err = null
|
|
73
73
|
try {
|
|
74
74
|
// @ts-ignore
|
|
75
|
-
config.get(
|
|
75
|
+
config.get('TOKEN_SECRET')
|
|
76
76
|
} catch (e) {
|
|
77
77
|
err = e
|
|
78
78
|
}
|
|
79
79
|
expect(err).is.not.null
|
|
80
|
-
expect(err?.[
|
|
80
|
+
expect(err?.['message']).is.not.null
|
|
81
81
|
})
|
|
82
82
|
|
|
83
|
-
test(
|
|
83
|
+
test('Required value with null value', async () => {
|
|
84
84
|
SSMMock.on(GetParameterCommand).resolves({
|
|
85
85
|
Parameter: {
|
|
86
86
|
Value: undefined,
|
|
@@ -88,80 +88,80 @@ describe(`Required remote environment`, () => {
|
|
|
88
88
|
})
|
|
89
89
|
let err = null
|
|
90
90
|
try {
|
|
91
|
-
await config.asyncGet(
|
|
91
|
+
await config.asyncGet('TOKEN_SECRET')
|
|
92
92
|
} catch (e) {
|
|
93
93
|
err = e
|
|
94
94
|
}
|
|
95
95
|
expect(err).is.not.null
|
|
96
|
-
expect(err?.[
|
|
96
|
+
expect(err?.['message']).is.not.null
|
|
97
97
|
})
|
|
98
98
|
|
|
99
|
-
test(
|
|
99
|
+
test('Required value with empty response', async () => {
|
|
100
100
|
SSMMock.on(GetParameterCommand).resolves({})
|
|
101
101
|
let err = null
|
|
102
102
|
try {
|
|
103
|
-
await config.asyncGet(
|
|
103
|
+
await config.asyncGet('TOKEN_SECRET')
|
|
104
104
|
} catch (e) {
|
|
105
105
|
err = e
|
|
106
106
|
}
|
|
107
107
|
expect(err).is.not.null
|
|
108
|
-
expect(err?.[
|
|
108
|
+
expect(err?.['message']).is.not.null
|
|
109
109
|
})
|
|
110
110
|
|
|
111
|
-
test(
|
|
112
|
-
const value =
|
|
111
|
+
test('Required value with valid response', async () => {
|
|
112
|
+
const value = 'abc'
|
|
113
113
|
SSMMock.on(GetParameterCommand).resolves({
|
|
114
114
|
Parameter: {
|
|
115
115
|
Value: value,
|
|
116
116
|
},
|
|
117
117
|
})
|
|
118
|
-
const token = await config.asyncGet(
|
|
118
|
+
const token = await config.asyncGet('TOKEN_SECRET')
|
|
119
119
|
expect(token).is.not.undefined
|
|
120
120
|
expect(token).to.be.equals(value)
|
|
121
121
|
})
|
|
122
122
|
|
|
123
|
-
test(
|
|
124
|
-
SSMMock.on(GetParameterCommand).rejects(new Error(
|
|
123
|
+
test('Required value rejection', async () => {
|
|
124
|
+
SSMMock.on(GetParameterCommand).rejects(new Error('failed!'))
|
|
125
125
|
let err = null
|
|
126
126
|
try {
|
|
127
|
-
await config.asyncGet(
|
|
127
|
+
await config.asyncGet('TOKEN_SECRET')
|
|
128
128
|
} catch (e) {
|
|
129
129
|
err = e
|
|
130
130
|
}
|
|
131
131
|
expect(err).is.not.null
|
|
132
|
-
expect(err?.[
|
|
132
|
+
expect(err?.['message']).is.not.null
|
|
133
133
|
})
|
|
134
134
|
})
|
|
135
135
|
|
|
136
136
|
describe(`Optional local environment`, () => {
|
|
137
137
|
beforeEach(() => {
|
|
138
|
-
config[
|
|
138
|
+
config['resetCache']()
|
|
139
139
|
})
|
|
140
140
|
|
|
141
|
-
test(
|
|
142
|
-
const token = config.get(
|
|
141
|
+
test('Optional value with null value', async () => {
|
|
142
|
+
const token = config.get('PATH123')
|
|
143
143
|
expect(token).is.undefined
|
|
144
144
|
})
|
|
145
145
|
})
|
|
146
146
|
|
|
147
147
|
describe(`Required local environment`, () => {
|
|
148
148
|
beforeEach(() => {
|
|
149
|
-
config[
|
|
149
|
+
config['resetCache']()
|
|
150
150
|
})
|
|
151
151
|
|
|
152
|
-
test(
|
|
152
|
+
test('Required value with null value', async () => {
|
|
153
153
|
let err = null
|
|
154
154
|
try {
|
|
155
|
-
config.get(
|
|
155
|
+
config.get('PATH_FALSY')
|
|
156
156
|
} catch (e) {
|
|
157
157
|
err = e
|
|
158
158
|
}
|
|
159
159
|
expect(err).is.not.null
|
|
160
|
-
expect(err?.[
|
|
160
|
+
expect(err?.['message']).is.not.null
|
|
161
161
|
})
|
|
162
162
|
|
|
163
|
-
test(
|
|
164
|
-
const key =
|
|
163
|
+
test('Required value with valid response', async () => {
|
|
164
|
+
const key = 'PATH'
|
|
165
165
|
const v = config.get(key)
|
|
166
166
|
expect(v).is.not.null
|
|
167
167
|
expect(v).to.be.equals(process.env[key])
|
|
@@ -169,9 +169,9 @@ describe(`Required local environment`, () => {
|
|
|
169
169
|
})
|
|
170
170
|
|
|
171
171
|
describe(`Caching test`, () => {
|
|
172
|
-
test(
|
|
173
|
-
const value =
|
|
174
|
-
const key =
|
|
172
|
+
test('Does cache previous fetched value', async () => {
|
|
173
|
+
const value = '123'
|
|
174
|
+
const key = 'TOKEN_SECRET'
|
|
175
175
|
// initial fetch
|
|
176
176
|
SSMMock.on(GetParameterCommand).resolves({
|
|
177
177
|
Parameter: {
|
|
@@ -183,7 +183,7 @@ describe(`Caching test`, () => {
|
|
|
183
183
|
expect(v).to.be.equals(value)
|
|
184
184
|
// subsequent fetch
|
|
185
185
|
SSMMock.reset()
|
|
186
|
-
SSMMock.on(GetParameterCommand).rejects(new Error(
|
|
186
|
+
SSMMock.on(GetParameterCommand).rejects(new Error('failed!'))
|
|
187
187
|
const v2 = await config.asyncGet(key)
|
|
188
188
|
expect(v2).is.not.null
|
|
189
189
|
expect(v2).to.be.equals(value)
|
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
import { expect } from "chai"
|
|
8
|
-
|
|
9
|
-
import EnvironmentVar, {
|
|
10
|
-
EnvironmentType,
|
|
11
|
-
} from "../../src/Config/EnvironmentVar"
|
|
1
|
+
import { SecretsManagerClient, GetSecretValueCommand } from '@aws-sdk/client-secrets-manager'
|
|
2
|
+
import { SSMClient, GetParameterCommand } from '@aws-sdk/client-ssm'
|
|
3
|
+
import { mockClient } from 'aws-sdk-client-mock'
|
|
4
|
+
import { expect } from 'chai'
|
|
5
|
+
|
|
6
|
+
import EnvironmentVar, { EnvironmentType } from '../../src/Config/EnvironmentVar'
|
|
12
7
|
|
|
13
8
|
const SSMMock = mockClient(SSMClient)
|
|
14
9
|
const SecretsManagerMock = mockClient(SecretsManagerClient)
|
|
@@ -20,7 +15,7 @@ function testRemoteEnv(mock, type, command) {
|
|
|
20
15
|
mock.reset()
|
|
21
16
|
})
|
|
22
17
|
|
|
23
|
-
test(
|
|
18
|
+
test('Does not accept sync resolve', async () => {
|
|
24
19
|
mock.on(command).resolves({
|
|
25
20
|
Parameter: {
|
|
26
21
|
Value: undefined,
|
|
@@ -28,35 +23,35 @@ function testRemoteEnv(mock, type, command) {
|
|
|
28
23
|
})
|
|
29
24
|
let err = null
|
|
30
25
|
try {
|
|
31
|
-
const env = new EnvironmentVar(
|
|
26
|
+
const env = new EnvironmentVar('abc', type, true)
|
|
32
27
|
env.syncResolve()
|
|
33
28
|
} catch (e) {
|
|
34
29
|
err = e
|
|
35
30
|
}
|
|
36
31
|
expect(err).is.not.null
|
|
37
|
-
expect(err?.[
|
|
32
|
+
expect(err?.['message']).is.not.null
|
|
38
33
|
})
|
|
39
34
|
|
|
40
|
-
test(
|
|
35
|
+
test('Optional value with null value', async () => {
|
|
41
36
|
mock.on(command).resolves({
|
|
42
37
|
Parameter: {
|
|
43
38
|
Value: undefined,
|
|
44
39
|
},
|
|
45
40
|
})
|
|
46
|
-
const env = new EnvironmentVar(
|
|
41
|
+
const env = new EnvironmentVar('abc', type, true)
|
|
47
42
|
const token = await env.resolve()
|
|
48
43
|
expect(token).is.undefined
|
|
49
44
|
})
|
|
50
45
|
|
|
51
|
-
test(
|
|
46
|
+
test('Optional value with empty response', async () => {
|
|
52
47
|
mock.on(command).resolves({})
|
|
53
|
-
const env = new EnvironmentVar(
|
|
48
|
+
const env = new EnvironmentVar('abc', type, true)
|
|
54
49
|
const token = await env.resolve()
|
|
55
50
|
expect(token).is.undefined
|
|
56
51
|
})
|
|
57
52
|
|
|
58
|
-
test(
|
|
59
|
-
const value =
|
|
53
|
+
test('Optional value with valid response', async () => {
|
|
54
|
+
const value = 'abc'
|
|
60
55
|
mock.on(command).resolves({
|
|
61
56
|
Parameter: {
|
|
62
57
|
Value: value,
|
|
@@ -68,9 +63,9 @@ function testRemoteEnv(mock, type, command) {
|
|
|
68
63
|
expect(token).to.be.equals(value)
|
|
69
64
|
})
|
|
70
65
|
|
|
71
|
-
test(
|
|
72
|
-
const value =
|
|
73
|
-
mock.on(command).rejects(new Error(
|
|
66
|
+
test('Optional value rejection', async () => {
|
|
67
|
+
const value = 'abc'
|
|
68
|
+
mock.on(command).rejects(new Error('failed!'))
|
|
74
69
|
const env = new EnvironmentVar(value, type, true)
|
|
75
70
|
const token = await env.resolve()
|
|
76
71
|
expect(token).is.undefined
|
|
@@ -83,7 +78,7 @@ function testRemoteEnv(mock, type, command) {
|
|
|
83
78
|
mock.reset()
|
|
84
79
|
})
|
|
85
80
|
|
|
86
|
-
test(
|
|
81
|
+
test('Does not accept sync resolve', async () => {
|
|
87
82
|
mock.on(command).resolves({
|
|
88
83
|
Parameter: {
|
|
89
84
|
Value: undefined,
|
|
@@ -91,16 +86,16 @@ function testRemoteEnv(mock, type, command) {
|
|
|
91
86
|
})
|
|
92
87
|
let err = null
|
|
93
88
|
try {
|
|
94
|
-
const env = new EnvironmentVar(
|
|
89
|
+
const env = new EnvironmentVar('abc', type)
|
|
95
90
|
env.syncResolve()
|
|
96
91
|
} catch (e) {
|
|
97
92
|
err = e
|
|
98
93
|
}
|
|
99
94
|
expect(err).is.not.null
|
|
100
|
-
expect(err?.[
|
|
95
|
+
expect(err?.['message']).is.not.null
|
|
101
96
|
})
|
|
102
97
|
|
|
103
|
-
test(
|
|
98
|
+
test('Required fails when null', async () => {
|
|
104
99
|
mock.on(command).resolves({
|
|
105
100
|
Parameter: {
|
|
106
101
|
Value: undefined,
|
|
@@ -108,31 +103,31 @@ function testRemoteEnv(mock, type, command) {
|
|
|
108
103
|
})
|
|
109
104
|
let err = null
|
|
110
105
|
try {
|
|
111
|
-
const env = new EnvironmentVar(
|
|
106
|
+
const env = new EnvironmentVar('abc', type)
|
|
112
107
|
await env.resolve()
|
|
113
108
|
} catch (e) {
|
|
114
109
|
err = e
|
|
115
110
|
}
|
|
116
111
|
console.log(err)
|
|
117
112
|
expect(err).is.not.null
|
|
118
|
-
expect(err?.[
|
|
113
|
+
expect(err?.['message']).is.not.null
|
|
119
114
|
})
|
|
120
115
|
|
|
121
|
-
test(
|
|
116
|
+
test('Required fails when empty response', async () => {
|
|
122
117
|
mock.on(command).resolves({})
|
|
123
118
|
let err = null
|
|
124
119
|
try {
|
|
125
|
-
const env = new EnvironmentVar(
|
|
120
|
+
const env = new EnvironmentVar('abc', type)
|
|
126
121
|
await env.resolve()
|
|
127
122
|
} catch (e) {
|
|
128
123
|
err = e
|
|
129
124
|
}
|
|
130
125
|
expect(err).is.not.null
|
|
131
|
-
expect(err?.[
|
|
126
|
+
expect(err?.['message']).is.not.null
|
|
132
127
|
})
|
|
133
128
|
|
|
134
|
-
test(
|
|
135
|
-
const value =
|
|
129
|
+
test('Required value with valid response', async () => {
|
|
130
|
+
const value = 'abc'
|
|
136
131
|
mock.on(command).resolves({
|
|
137
132
|
Parameter: {
|
|
138
133
|
Value: value,
|
|
@@ -144,44 +139,40 @@ function testRemoteEnv(mock, type, command) {
|
|
|
144
139
|
expect(token).to.be.equals(value)
|
|
145
140
|
})
|
|
146
141
|
|
|
147
|
-
test(
|
|
148
|
-
mock.on(command).rejects(new Error(
|
|
142
|
+
test('Required value rejection', async () => {
|
|
143
|
+
mock.on(command).rejects(new Error('failed!'))
|
|
149
144
|
let err = null
|
|
150
145
|
try {
|
|
151
|
-
const env = new EnvironmentVar(
|
|
146
|
+
const env = new EnvironmentVar('abc', type)
|
|
152
147
|
await env.resolve()
|
|
153
148
|
} catch (e) {
|
|
154
149
|
err = e
|
|
155
150
|
}
|
|
156
151
|
expect(err).is.not.null
|
|
157
|
-
expect(err?.[
|
|
152
|
+
expect(err?.['message']).is.not.null
|
|
158
153
|
})
|
|
159
154
|
})
|
|
160
155
|
}
|
|
161
156
|
|
|
162
157
|
/* Remote envs test */
|
|
163
158
|
testRemoteEnv(SSMMock, EnvironmentType.PlainRemote, GetParameterCommand)
|
|
164
|
-
testRemoteEnv(
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
)
|
|
169
|
-
|
|
170
|
-
describe("Optional Local environment", () => {
|
|
171
|
-
test("Does accept async resolve", async () => {
|
|
172
|
-
const env = new EnvironmentVar("PATH123", EnvironmentType.Local, true)
|
|
159
|
+
testRemoteEnv(SecretsManagerMock, EnvironmentType.SecureRemote, GetSecretValueCommand)
|
|
160
|
+
|
|
161
|
+
describe('Optional Local environment', () => {
|
|
162
|
+
test('Does accept async resolve', async () => {
|
|
163
|
+
const env = new EnvironmentVar('PATH123', EnvironmentType.Local, true)
|
|
173
164
|
const v = await env.resolve()
|
|
174
165
|
expect(v).is.undefined
|
|
175
166
|
})
|
|
176
167
|
|
|
177
|
-
test(
|
|
178
|
-
const env = new EnvironmentVar(
|
|
168
|
+
test('Optional value with null value', async () => {
|
|
169
|
+
const env = new EnvironmentVar('PATH123', EnvironmentType.Local, true)
|
|
179
170
|
const token = env.syncResolve()
|
|
180
171
|
expect(token).is.undefined
|
|
181
172
|
})
|
|
182
173
|
|
|
183
|
-
test(
|
|
184
|
-
const key =
|
|
174
|
+
test('Optional value with valid value', async () => {
|
|
175
|
+
const key = 'PATH'
|
|
185
176
|
const env = new EnvironmentVar(key, EnvironmentType.Local, true)
|
|
186
177
|
const token = env.syncResolve()
|
|
187
178
|
expect(token).is.not.undefined
|
|
@@ -189,30 +180,30 @@ describe("Optional Local environment", () => {
|
|
|
189
180
|
})
|
|
190
181
|
})
|
|
191
182
|
|
|
192
|
-
describe(
|
|
193
|
-
test(
|
|
194
|
-
const key =
|
|
183
|
+
describe('Required local environment', () => {
|
|
184
|
+
test('Does accept async resolve', async () => {
|
|
185
|
+
const key = 'PATH'
|
|
195
186
|
const env = new EnvironmentVar(key, EnvironmentType.Local)
|
|
196
187
|
const v = await env.resolve()
|
|
197
188
|
expect(v).is.not.null
|
|
198
189
|
expect(v).to.be.equals(process.env[key])
|
|
199
190
|
})
|
|
200
191
|
|
|
201
|
-
test(
|
|
192
|
+
test('Required fails when null', async () => {
|
|
202
193
|
let err = null
|
|
203
194
|
try {
|
|
204
|
-
const env = new EnvironmentVar(
|
|
195
|
+
const env = new EnvironmentVar('PATH123', EnvironmentType.Local)
|
|
205
196
|
env.syncResolve()
|
|
206
197
|
} catch (e) {
|
|
207
198
|
err = e
|
|
208
199
|
}
|
|
209
200
|
console.log(err)
|
|
210
201
|
expect(err).is.not.null
|
|
211
|
-
expect(err?.[
|
|
202
|
+
expect(err?.['message']).is.not.null
|
|
212
203
|
})
|
|
213
204
|
|
|
214
|
-
test(
|
|
215
|
-
const key =
|
|
205
|
+
test('Required value with valid value', async () => {
|
|
206
|
+
const key = 'PATH'
|
|
216
207
|
const env = new EnvironmentVar(key, EnvironmentType.Local)
|
|
217
208
|
const v = env.syncResolve()
|
|
218
209
|
expect(v).is.not.null
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { DecryptCommand, EncryptCommand, KMSClient } from
|
|
2
|
-
import { mockClient } from
|
|
3
|
-
import { expect } from
|
|
1
|
+
import { DecryptCommand, EncryptCommand, KMSClient } from '@aws-sdk/client-kms'
|
|
2
|
+
import { mockClient } from 'aws-sdk-client-mock'
|
|
3
|
+
import { expect } from 'chai'
|
|
4
4
|
|
|
5
|
-
import Crypto from
|
|
5
|
+
import Crypto from '../../src/Crypto/Crypto'
|
|
6
6
|
|
|
7
7
|
const KMSMock = mockClient(KMSClient)
|
|
8
8
|
|
|
9
9
|
function fakeEncryption(v) {
|
|
10
10
|
const f = new TextEncoder().encode(v)
|
|
11
|
-
return Buffer.from(f as any,
|
|
11
|
+
return Buffer.from(f as any, 'utf8').toString('hex')
|
|
12
12
|
}
|
|
13
13
|
function fakeDecryption(v) {
|
|
14
14
|
return new TextEncoder().encode(v)
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
describe(
|
|
17
|
+
describe('Encryption', () => {
|
|
18
18
|
// reset mock
|
|
19
19
|
beforeEach(() => {
|
|
20
20
|
KMSMock.reset()
|
|
21
21
|
})
|
|
22
22
|
|
|
23
|
-
const provider = new Crypto(
|
|
24
|
-
test(
|
|
23
|
+
const provider = new Crypto('ca-central-1', 'abc123')
|
|
24
|
+
test('Encrypts json object', async () => {
|
|
25
25
|
const encryptionObj = { userID: 123 }
|
|
26
26
|
KMSMock.on(EncryptCommand).resolves({
|
|
27
27
|
CiphertextBlob: new TextEncoder().encode(JSON.stringify(encryptionObj)),
|
|
@@ -31,8 +31,8 @@ describe("Encryption", () => {
|
|
|
31
31
|
expect(token).to.be.equals(fakeEncryption(JSON.stringify(encryptionObj)))
|
|
32
32
|
})
|
|
33
33
|
|
|
34
|
-
test(
|
|
35
|
-
const encryptionText =
|
|
34
|
+
test('Encrypts string', async () => {
|
|
35
|
+
const encryptionText = 'Hello encryption!'
|
|
36
36
|
KMSMock.on(EncryptCommand).resolves({
|
|
37
37
|
CiphertextBlob: new TextEncoder().encode(encryptionText),
|
|
38
38
|
})
|
|
@@ -41,35 +41,33 @@ describe("Encryption", () => {
|
|
|
41
41
|
expect(token).to.be.equals(fakeEncryption(encryptionText))
|
|
42
42
|
})
|
|
43
43
|
|
|
44
|
-
test(
|
|
44
|
+
test('Fails to encrypt a number', async () => {
|
|
45
45
|
const encryptionText = 123
|
|
46
|
-
KMSMock.on(EncryptCommand).rejects(new Error(
|
|
46
|
+
KMSMock.on(EncryptCommand).rejects(new Error('failed'))
|
|
47
47
|
const token = await provider.encryptData(encryptionText)
|
|
48
48
|
expect(token).is.null
|
|
49
49
|
})
|
|
50
50
|
})
|
|
51
51
|
|
|
52
|
-
describe(
|
|
52
|
+
describe('Decryption', () => {
|
|
53
53
|
// reset mock
|
|
54
54
|
beforeEach(() => {
|
|
55
55
|
KMSMock.reset()
|
|
56
56
|
})
|
|
57
57
|
|
|
58
|
-
const provider = new Crypto(
|
|
59
|
-
test(
|
|
58
|
+
const provider = new Crypto('ca-central-1', 'abc123')
|
|
59
|
+
test('Decrypts json object', async () => {
|
|
60
60
|
const encryptionObj = { userID: 123 }
|
|
61
61
|
KMSMock.on(DecryptCommand).resolves({
|
|
62
62
|
Plaintext: fakeDecryption(JSON.stringify(encryptionObj)),
|
|
63
63
|
})
|
|
64
|
-
const token = await provider.decryptData(
|
|
65
|
-
fakeEncryption(JSON.stringify(encryptionObj)),
|
|
66
|
-
)
|
|
64
|
+
const token = await provider.decryptData(fakeEncryption(JSON.stringify(encryptionObj)))
|
|
67
65
|
expect(token).is.not.null
|
|
68
66
|
expect(token).to.be.equals(JSON.stringify(encryptionObj))
|
|
69
67
|
})
|
|
70
68
|
|
|
71
|
-
test(
|
|
72
|
-
const encryptionText =
|
|
69
|
+
test('Decrypts string', async () => {
|
|
70
|
+
const encryptionText = 'abc123'
|
|
73
71
|
KMSMock.on(DecryptCommand).resolves({
|
|
74
72
|
Plaintext: fakeDecryption(encryptionText),
|
|
75
73
|
})
|
|
@@ -78,9 +76,9 @@ describe("Decryption", () => {
|
|
|
78
76
|
expect(token).to.be.equals(encryptionText)
|
|
79
77
|
})
|
|
80
78
|
|
|
81
|
-
test(
|
|
79
|
+
test('Fails to decrypt a number', async () => {
|
|
82
80
|
const encryptionText = 123
|
|
83
|
-
KMSMock.on(DecryptCommand).rejects(new Error(
|
|
81
|
+
KMSMock.on(DecryptCommand).rejects(new Error('failed'))
|
|
84
82
|
// @ts-ignore
|
|
85
83
|
const token = await provider.decryptData(encryptionText)
|
|
86
84
|
expect(token).is.null
|