@creator.co/wapi 1.8.8 → 1.9.0
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/README.md +0 -1
- package/dist/package-lock.json +2597 -925
- package/dist/package.json +16 -12
- package/dist/src/API/Request.d.ts +10 -0
- package/dist/src/API/Request.js +43 -3
- package/dist/src/API/Request.js.map +1 -1
- package/dist/src/Server/Router.d.ts +6 -0
- package/dist/src/Server/Router.js.map +1 -1
- package/dist/src/Server/lib/ContainerServer.js +52 -5
- package/dist/src/Server/lib/ContainerServer.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +16 -12
- package/src/API/Request.ts +56 -2
- package/src/Server/Router.ts +6 -0
- package/src/Server/lib/ContainerServer.ts +54 -5
- package/tests/AwsSdkTest.utils.ts +13 -0
- package/tests/Config/Config.test.ts +42 -32
- package/tests/Config/EnvironmentVar.test.ts +85 -73
- package/tests/Crypto/Crypto.test.ts +24 -16
- package/tests/Mailer/Mailer.test.ts +13 -9
- package/tests/Publisher/Publisher.test.ts +22 -16
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { SSMClient, GetParameterCommand } from '@aws-sdk/client-ssm'
|
|
2
|
-
import { mockClient } from 'aws-sdk-client-mock'
|
|
3
2
|
import { expect as c_expect } from 'chai'
|
|
4
3
|
|
|
5
4
|
import Configuration from '../../src/Config/Configuration.js'
|
|
5
|
+
import { mockAwsClient, mockAwsCommand, mockAwsResult } from '../AwsSdkTest.utils.js'
|
|
6
6
|
import { SampleConfig } from '../Test.utils.js'
|
|
7
7
|
|
|
8
|
-
const SSMMock =
|
|
8
|
+
const SSMMock = mockAwsClient(SSMClient)
|
|
9
9
|
const config = new Configuration<typeof SampleConfig>(SampleConfig, 'my-prefix')
|
|
10
10
|
describe(`Optional remote environment`, () => {
|
|
11
11
|
// reset mock
|
|
@@ -27,35 +27,39 @@ describe(`Optional remote environment`, () => {
|
|
|
27
27
|
})
|
|
28
28
|
|
|
29
29
|
test('Optional value with null value', async () => {
|
|
30
|
-
SSMMock.on(GetParameterCommand).resolves(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
SSMMock.on(mockAwsCommand(GetParameterCommand)).resolves(
|
|
31
|
+
mockAwsResult({
|
|
32
|
+
Parameter: {
|
|
33
|
+
Value: undefined,
|
|
34
|
+
},
|
|
35
|
+
})
|
|
36
|
+
)
|
|
35
37
|
const token = await config.asyncGet('TOKEN_SECRET_FALSY')
|
|
36
38
|
c_expect(token).is.undefined
|
|
37
39
|
})
|
|
38
40
|
|
|
39
41
|
test('Optional value with empty response', async () => {
|
|
40
|
-
SSMMock.on(GetParameterCommand).resolves({})
|
|
42
|
+
SSMMock.on(mockAwsCommand(GetParameterCommand)).resolves(mockAwsResult({}))
|
|
41
43
|
const token = await config.asyncGet('TOKEN_SECRET_FALSY')
|
|
42
44
|
c_expect(token).is.undefined
|
|
43
45
|
})
|
|
44
46
|
|
|
45
47
|
test('Optional value with valid response', async () => {
|
|
46
48
|
const value = 'abc'
|
|
47
|
-
SSMMock.on(GetParameterCommand).resolves(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
SSMMock.on(mockAwsCommand(GetParameterCommand)).resolves(
|
|
50
|
+
mockAwsResult({
|
|
51
|
+
Parameter: {
|
|
52
|
+
Value: value,
|
|
53
|
+
},
|
|
54
|
+
})
|
|
55
|
+
)
|
|
52
56
|
const token = await config.asyncGet('TOKEN_SECRET_FALSY')
|
|
53
57
|
c_expect(token).is.not.undefined
|
|
54
58
|
c_expect(token).to.be.equals(value)
|
|
55
59
|
})
|
|
56
60
|
|
|
57
61
|
test('Optional value rejection', async () => {
|
|
58
|
-
SSMMock.on(GetParameterCommand).rejects(new Error('failed!'))
|
|
62
|
+
SSMMock.on(mockAwsCommand(GetParameterCommand)).rejects(new Error('failed!'))
|
|
59
63
|
const token = await config.asyncGet('TOKEN_SECRET_FALSY')
|
|
60
64
|
c_expect(token).is.undefined
|
|
61
65
|
})
|
|
@@ -81,11 +85,13 @@ describe(`Required remote environment`, () => {
|
|
|
81
85
|
})
|
|
82
86
|
|
|
83
87
|
test('Required value with null value', async () => {
|
|
84
|
-
SSMMock.on(GetParameterCommand).resolves(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
88
|
+
SSMMock.on(mockAwsCommand(GetParameterCommand)).resolves(
|
|
89
|
+
mockAwsResult({
|
|
90
|
+
Parameter: {
|
|
91
|
+
Value: undefined,
|
|
92
|
+
},
|
|
93
|
+
})
|
|
94
|
+
)
|
|
89
95
|
let err = null
|
|
90
96
|
try {
|
|
91
97
|
await config.asyncGet('TOKEN_SECRET')
|
|
@@ -97,7 +103,7 @@ describe(`Required remote environment`, () => {
|
|
|
97
103
|
})
|
|
98
104
|
|
|
99
105
|
test('Required value with empty response', async () => {
|
|
100
|
-
SSMMock.on(GetParameterCommand).resolves({})
|
|
106
|
+
SSMMock.on(mockAwsCommand(GetParameterCommand)).resolves(mockAwsResult({}))
|
|
101
107
|
let err = null
|
|
102
108
|
try {
|
|
103
109
|
await config.asyncGet('TOKEN_SECRET')
|
|
@@ -110,18 +116,20 @@ describe(`Required remote environment`, () => {
|
|
|
110
116
|
|
|
111
117
|
test('Required value with valid response', async () => {
|
|
112
118
|
const value = 'abc'
|
|
113
|
-
SSMMock.on(GetParameterCommand).resolves(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
119
|
+
SSMMock.on(mockAwsCommand(GetParameterCommand)).resolves(
|
|
120
|
+
mockAwsResult({
|
|
121
|
+
Parameter: {
|
|
122
|
+
Value: value,
|
|
123
|
+
},
|
|
124
|
+
})
|
|
125
|
+
)
|
|
118
126
|
const token = await config.asyncGet('TOKEN_SECRET')
|
|
119
127
|
c_expect(token).is.not.undefined
|
|
120
128
|
c_expect(token).to.be.equals(value)
|
|
121
129
|
})
|
|
122
130
|
|
|
123
131
|
test('Required value rejection', async () => {
|
|
124
|
-
SSMMock.on(GetParameterCommand).rejects(new Error('failed!'))
|
|
132
|
+
SSMMock.on(mockAwsCommand(GetParameterCommand)).rejects(new Error('failed!'))
|
|
125
133
|
let err = null
|
|
126
134
|
try {
|
|
127
135
|
await config.asyncGet('TOKEN_SECRET')
|
|
@@ -185,17 +193,19 @@ describe(`Caching test`, () => {
|
|
|
185
193
|
const value = '123'
|
|
186
194
|
const key = 'TOKEN_SECRET'
|
|
187
195
|
// initial fetch
|
|
188
|
-
SSMMock.on(GetParameterCommand).resolves(
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
196
|
+
SSMMock.on(mockAwsCommand(GetParameterCommand)).resolves(
|
|
197
|
+
mockAwsResult({
|
|
198
|
+
Parameter: {
|
|
199
|
+
Value: value,
|
|
200
|
+
},
|
|
201
|
+
})
|
|
202
|
+
)
|
|
193
203
|
const v = await config.asyncGet(key)
|
|
194
204
|
c_expect(v).is.not.null
|
|
195
205
|
c_expect(v).to.be.equals(value)
|
|
196
206
|
// subsequent fetch
|
|
197
207
|
SSMMock.reset()
|
|
198
|
-
SSMMock.on(GetParameterCommand).rejects(new Error('failed!'))
|
|
208
|
+
SSMMock.on(mockAwsCommand(GetParameterCommand)).rejects(new Error('failed!'))
|
|
199
209
|
const v2 = await config.asyncGet(key)
|
|
200
210
|
c_expect(v2).is.not.null
|
|
201
211
|
c_expect(v2).to.be.equals(value)
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { SecretsManagerClient, GetSecretValueCommand } from '@aws-sdk/client-secrets-manager'
|
|
2
2
|
import { SSMClient, GetParameterCommand } from '@aws-sdk/client-ssm'
|
|
3
|
-
import { mockClient } from 'aws-sdk-client-mock'
|
|
4
3
|
import { expect } from 'chai'
|
|
5
4
|
|
|
6
5
|
import EnvironmentVar, { EnvironmentType } from '../../src/Config/EnvironmentVar.js'
|
|
6
|
+
import { mockAwsClient, mockAwsCommand, mockAwsResult } from '../AwsSdkTest.utils.js'
|
|
7
7
|
|
|
8
|
-
const SSMMock =
|
|
9
|
-
const SecretsManagerMock =
|
|
8
|
+
const SSMMock = mockAwsClient(SSMClient)
|
|
9
|
+
const SecretsManagerMock = mockAwsClient(SecretsManagerClient)
|
|
10
10
|
|
|
11
11
|
function testRemoteEnv(mock, type, command) {
|
|
12
12
|
describe(`Optional ${type} environment`, () => {
|
|
@@ -16,17 +16,19 @@ function testRemoteEnv(mock, type, command) {
|
|
|
16
16
|
})
|
|
17
17
|
|
|
18
18
|
test('Does not accept sync resolve', async () => {
|
|
19
|
-
mock.on(command).resolves(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
19
|
+
mock.on(mockAwsCommand(command)).resolves(
|
|
20
|
+
mockAwsResult({
|
|
21
|
+
...(type == EnvironmentType.PlainRemote
|
|
22
|
+
? {
|
|
23
|
+
Parameter: {
|
|
24
|
+
Value: undefined,
|
|
25
|
+
},
|
|
26
|
+
}
|
|
27
|
+
: {
|
|
28
|
+
SecretString: undefined,
|
|
29
|
+
}),
|
|
30
|
+
})
|
|
31
|
+
)
|
|
30
32
|
let err = null
|
|
31
33
|
try {
|
|
32
34
|
const env = new EnvironmentVar('abc', type, true)
|
|
@@ -39,24 +41,26 @@ function testRemoteEnv(mock, type, command) {
|
|
|
39
41
|
})
|
|
40
42
|
|
|
41
43
|
test('Optional value with null value', async () => {
|
|
42
|
-
mock.on(command).resolves(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
44
|
+
mock.on(mockAwsCommand(command)).resolves(
|
|
45
|
+
mockAwsResult({
|
|
46
|
+
...(type == EnvironmentType.PlainRemote
|
|
47
|
+
? {
|
|
48
|
+
Parameter: {
|
|
49
|
+
Value: undefined,
|
|
50
|
+
},
|
|
51
|
+
}
|
|
52
|
+
: {
|
|
53
|
+
SecretString: undefined,
|
|
54
|
+
}),
|
|
55
|
+
})
|
|
56
|
+
)
|
|
53
57
|
const env = new EnvironmentVar('abc', type, true)
|
|
54
58
|
const token = await env.resolve()
|
|
55
59
|
expect(token).is.undefined
|
|
56
60
|
})
|
|
57
61
|
|
|
58
62
|
test('Optional value with empty response', async () => {
|
|
59
|
-
mock.on(command).resolves({})
|
|
63
|
+
mock.on(mockAwsCommand(command)).resolves(mockAwsResult({}))
|
|
60
64
|
const env = new EnvironmentVar('abc', type, true)
|
|
61
65
|
const token = await env.resolve()
|
|
62
66
|
expect(token).is.undefined
|
|
@@ -64,17 +68,19 @@ function testRemoteEnv(mock, type, command) {
|
|
|
64
68
|
|
|
65
69
|
test('Optional value with valid response', async () => {
|
|
66
70
|
const value = 'abc'
|
|
67
|
-
mock.on(command).resolves(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
71
|
+
mock.on(mockAwsCommand(command)).resolves(
|
|
72
|
+
mockAwsResult({
|
|
73
|
+
...(type == EnvironmentType.PlainRemote
|
|
74
|
+
? {
|
|
75
|
+
Parameter: {
|
|
76
|
+
Value: value,
|
|
77
|
+
},
|
|
78
|
+
}
|
|
79
|
+
: {
|
|
80
|
+
SecretString: value,
|
|
81
|
+
}),
|
|
82
|
+
})
|
|
83
|
+
)
|
|
78
84
|
const env = new EnvironmentVar(value, type, true)
|
|
79
85
|
const token = await env.resolve()
|
|
80
86
|
expect(token).is.not.undefined
|
|
@@ -83,7 +89,7 @@ function testRemoteEnv(mock, type, command) {
|
|
|
83
89
|
|
|
84
90
|
test('Optional value rejection', async () => {
|
|
85
91
|
const value = 'abc'
|
|
86
|
-
mock.on(command).rejects(new Error('failed!'))
|
|
92
|
+
mock.on(mockAwsCommand(command)).rejects(new Error('failed!'))
|
|
87
93
|
const env = new EnvironmentVar(value, type, true)
|
|
88
94
|
const token = await env.resolve()
|
|
89
95
|
expect(token).is.undefined
|
|
@@ -97,17 +103,19 @@ function testRemoteEnv(mock, type, command) {
|
|
|
97
103
|
})
|
|
98
104
|
|
|
99
105
|
test('Does not accept sync resolve', async () => {
|
|
100
|
-
mock.on(command).resolves(
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
106
|
+
mock.on(mockAwsCommand(command)).resolves(
|
|
107
|
+
mockAwsResult({
|
|
108
|
+
...(type == EnvironmentType.PlainRemote
|
|
109
|
+
? {
|
|
110
|
+
Parameter: {
|
|
111
|
+
Value: undefined,
|
|
112
|
+
},
|
|
113
|
+
}
|
|
114
|
+
: {
|
|
115
|
+
SecretString: undefined,
|
|
116
|
+
}),
|
|
117
|
+
})
|
|
118
|
+
)
|
|
111
119
|
let err = null
|
|
112
120
|
try {
|
|
113
121
|
const env = new EnvironmentVar('abc', type)
|
|
@@ -120,17 +128,19 @@ function testRemoteEnv(mock, type, command) {
|
|
|
120
128
|
})
|
|
121
129
|
|
|
122
130
|
test('Required fails when null', async () => {
|
|
123
|
-
mock.on(command).resolves(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
131
|
+
mock.on(mockAwsCommand(command)).resolves(
|
|
132
|
+
mockAwsResult({
|
|
133
|
+
...(type == EnvironmentType.PlainRemote
|
|
134
|
+
? {
|
|
135
|
+
Parameter: {
|
|
136
|
+
Value: undefined,
|
|
137
|
+
},
|
|
138
|
+
}
|
|
139
|
+
: {
|
|
140
|
+
SecretString: undefined,
|
|
141
|
+
}),
|
|
142
|
+
})
|
|
143
|
+
)
|
|
134
144
|
let err = null
|
|
135
145
|
try {
|
|
136
146
|
const env = new EnvironmentVar('abc', type)
|
|
@@ -144,7 +154,7 @@ function testRemoteEnv(mock, type, command) {
|
|
|
144
154
|
})
|
|
145
155
|
|
|
146
156
|
test('Required fails when empty response', async () => {
|
|
147
|
-
mock.on(command).resolves({})
|
|
157
|
+
mock.on(mockAwsCommand(command)).resolves(mockAwsResult({}))
|
|
148
158
|
let err = null
|
|
149
159
|
try {
|
|
150
160
|
const env = new EnvironmentVar('abc', type)
|
|
@@ -158,17 +168,19 @@ function testRemoteEnv(mock, type, command) {
|
|
|
158
168
|
|
|
159
169
|
test('Required value with valid response', async () => {
|
|
160
170
|
const value = 'abc'
|
|
161
|
-
mock.on(command).resolves(
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
171
|
+
mock.on(mockAwsCommand(command)).resolves(
|
|
172
|
+
mockAwsResult({
|
|
173
|
+
...(type == EnvironmentType.PlainRemote
|
|
174
|
+
? {
|
|
175
|
+
Parameter: {
|
|
176
|
+
Value: value,
|
|
177
|
+
},
|
|
178
|
+
}
|
|
179
|
+
: {
|
|
180
|
+
SecretString: value,
|
|
181
|
+
}),
|
|
182
|
+
})
|
|
183
|
+
)
|
|
172
184
|
const env = new EnvironmentVar(value, type)
|
|
173
185
|
const token = await env.resolve()
|
|
174
186
|
expect(token).is.not.undefined
|
|
@@ -176,7 +188,7 @@ function testRemoteEnv(mock, type, command) {
|
|
|
176
188
|
})
|
|
177
189
|
|
|
178
190
|
test('Required value rejection', async () => {
|
|
179
|
-
mock.on(command).rejects(new Error('failed!'))
|
|
191
|
+
mock.on(mockAwsCommand(command)).rejects(new Error('failed!'))
|
|
180
192
|
let err = null
|
|
181
193
|
try {
|
|
182
194
|
const env = new EnvironmentVar('abc', type)
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { DecryptCommand, EncryptCommand, KMSClient } from '@aws-sdk/client-kms'
|
|
2
|
-
import { mockClient } from 'aws-sdk-client-mock'
|
|
3
2
|
import { expect } from 'chai'
|
|
4
3
|
|
|
5
4
|
import Crypto from '../../src/Crypto/Crypto.js'
|
|
5
|
+
import { mockAwsClient, mockAwsCommand, mockAwsResult } from '../AwsSdkTest.utils.js'
|
|
6
6
|
|
|
7
|
-
const KMSMock =
|
|
7
|
+
const KMSMock = mockAwsClient(KMSClient)
|
|
8
8
|
|
|
9
9
|
function fakeEncryption(v) {
|
|
10
10
|
const f = new TextEncoder().encode(v)
|
|
@@ -23,9 +23,11 @@ describe('Encryption', () => {
|
|
|
23
23
|
const provider = new Crypto('ca-central-1', 'abc123')
|
|
24
24
|
test('Encrypts json object', async () => {
|
|
25
25
|
const encryptionObj = { userID: 123 }
|
|
26
|
-
KMSMock.on(EncryptCommand).resolves(
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
KMSMock.on(mockAwsCommand(EncryptCommand)).resolves(
|
|
27
|
+
mockAwsResult({
|
|
28
|
+
CiphertextBlob: new TextEncoder().encode(JSON.stringify(encryptionObj)),
|
|
29
|
+
})
|
|
30
|
+
)
|
|
29
31
|
const token = await provider.encryptData(encryptionObj)
|
|
30
32
|
expect(token).is.not.null
|
|
31
33
|
expect(token).to.be.equals(fakeEncryption(JSON.stringify(encryptionObj)))
|
|
@@ -33,9 +35,11 @@ describe('Encryption', () => {
|
|
|
33
35
|
|
|
34
36
|
test('Encrypts string', async () => {
|
|
35
37
|
const encryptionText = 'Hello encryption!'
|
|
36
|
-
KMSMock.on(EncryptCommand).resolves(
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
KMSMock.on(mockAwsCommand(EncryptCommand)).resolves(
|
|
39
|
+
mockAwsResult({
|
|
40
|
+
CiphertextBlob: new TextEncoder().encode(encryptionText),
|
|
41
|
+
})
|
|
42
|
+
)
|
|
39
43
|
const token = await provider.encryptData(encryptionText)
|
|
40
44
|
expect(token).is.not.null
|
|
41
45
|
expect(token).to.be.equals(fakeEncryption(encryptionText))
|
|
@@ -43,7 +47,7 @@ describe('Encryption', () => {
|
|
|
43
47
|
|
|
44
48
|
test('Fails to encrypt a number', async () => {
|
|
45
49
|
const encryptionText = 123
|
|
46
|
-
KMSMock.on(EncryptCommand).rejects(new Error('failed'))
|
|
50
|
+
KMSMock.on(mockAwsCommand(EncryptCommand)).rejects(new Error('failed'))
|
|
47
51
|
const token = await provider.encryptData(encryptionText)
|
|
48
52
|
expect(token).is.null
|
|
49
53
|
})
|
|
@@ -58,9 +62,11 @@ describe('Decryption', () => {
|
|
|
58
62
|
const provider = new Crypto('ca-central-1', 'abc123')
|
|
59
63
|
test('Decrypts json object', async () => {
|
|
60
64
|
const encryptionObj = { userID: 123 }
|
|
61
|
-
KMSMock.on(DecryptCommand).resolves(
|
|
62
|
-
|
|
63
|
-
|
|
65
|
+
KMSMock.on(mockAwsCommand(DecryptCommand)).resolves(
|
|
66
|
+
mockAwsResult({
|
|
67
|
+
Plaintext: fakeDecryption(JSON.stringify(encryptionObj)),
|
|
68
|
+
})
|
|
69
|
+
)
|
|
64
70
|
const token = await provider.decryptData(fakeEncryption(JSON.stringify(encryptionObj)))
|
|
65
71
|
expect(token).is.not.null
|
|
66
72
|
expect(token).to.be.equals(JSON.stringify(encryptionObj))
|
|
@@ -68,9 +74,11 @@ describe('Decryption', () => {
|
|
|
68
74
|
|
|
69
75
|
test('Decrypts string', async () => {
|
|
70
76
|
const encryptionText = 'abc123'
|
|
71
|
-
KMSMock.on(DecryptCommand).resolves(
|
|
72
|
-
|
|
73
|
-
|
|
77
|
+
KMSMock.on(mockAwsCommand(DecryptCommand)).resolves(
|
|
78
|
+
mockAwsResult({
|
|
79
|
+
Plaintext: fakeDecryption(encryptionText),
|
|
80
|
+
})
|
|
81
|
+
)
|
|
74
82
|
const token = await provider.decryptData(fakeEncryption(encryptionText))
|
|
75
83
|
expect(token).is.not.null
|
|
76
84
|
expect(token).to.be.equals(encryptionText)
|
|
@@ -78,7 +86,7 @@ describe('Decryption', () => {
|
|
|
78
86
|
|
|
79
87
|
test('Fails to decrypt a number', async () => {
|
|
80
88
|
const encryptionText = 123
|
|
81
|
-
KMSMock.on(DecryptCommand).rejects(new Error('failed'))
|
|
89
|
+
KMSMock.on(mockAwsCommand(DecryptCommand)).rejects(new Error('failed'))
|
|
82
90
|
// @ts-ignore
|
|
83
91
|
const token = await provider.decryptData(encryptionText)
|
|
84
92
|
expect(token).is.null
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { SESv2Client, SendEmailCommand } from '@aws-sdk/client-sesv2'
|
|
2
|
-
import { mockClient } from 'aws-sdk-client-mock'
|
|
3
2
|
import { expect } from 'chai'
|
|
4
3
|
|
|
5
4
|
import Mailer from '../../src/Mailer/Mailer.js'
|
|
5
|
+
import { mockAwsClient, mockAwsCommand, mockAwsResult } from '../AwsSdkTest.utils.js'
|
|
6
6
|
|
|
7
|
-
const SESMock =
|
|
7
|
+
const SESMock = mockAwsClient(SESv2Client)
|
|
8
8
|
|
|
9
9
|
describe('SendRaw', () => {
|
|
10
10
|
// reset mock
|
|
@@ -16,9 +16,11 @@ describe('SendRaw', () => {
|
|
|
16
16
|
|
|
17
17
|
test('Send raw with success', async () => {
|
|
18
18
|
const messageId = 'id-123'
|
|
19
|
-
SESMock.on(SendEmailCommand).resolves(
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
SESMock.on(mockAwsCommand(SendEmailCommand)).resolves(
|
|
20
|
+
mockAwsResult({
|
|
21
|
+
MessageId: messageId,
|
|
22
|
+
})
|
|
23
|
+
)
|
|
22
24
|
const res = await provider.sendRawEmail('test@test.com', 'My message', 'My subject')
|
|
23
25
|
expect(res).is.not.null
|
|
24
26
|
console.log(res)
|
|
@@ -32,16 +34,18 @@ describe('SendRaw', () => {
|
|
|
32
34
|
const subject = 'My subject'
|
|
33
35
|
const cc = 'test@test3.com'
|
|
34
36
|
const replyTo = 'test@test4.com'
|
|
35
|
-
SESMock.on(SendEmailCommand).resolves(
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
SESMock.on(mockAwsCommand(SendEmailCommand)).resolves(
|
|
38
|
+
mockAwsResult({
|
|
39
|
+
MessageId: messageId,
|
|
40
|
+
})
|
|
41
|
+
)
|
|
38
42
|
const res = await provider.sendRawEmail(to, msg, subject, cc, from, replyTo)
|
|
39
43
|
expect(res).is.not.null
|
|
40
44
|
console.log(res)
|
|
41
45
|
})
|
|
42
46
|
|
|
43
47
|
test('Send raw with failure', async () => {
|
|
44
|
-
SESMock.on(SendEmailCommand).rejects(new Error('failed!'))
|
|
48
|
+
SESMock.on(mockAwsCommand(SendEmailCommand)).rejects(new Error('failed!'))
|
|
45
49
|
let res: any = null,
|
|
46
50
|
err: any = null
|
|
47
51
|
try {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { SNSClient, PublishCommand } from '@aws-sdk/client-sns'
|
|
2
|
-
import { mockClient } from 'aws-sdk-client-mock'
|
|
3
2
|
import { expect } from 'chai'
|
|
4
3
|
|
|
5
4
|
import Publisher from '../../src/Publisher/Publisher.js'
|
|
5
|
+
import { mockAwsClient, mockAwsCommand, mockAwsResult } from '../AwsSdkTest.utils.js'
|
|
6
6
|
|
|
7
|
-
const SNSMock =
|
|
7
|
+
const SNSMock = mockAwsClient(SNSClient)
|
|
8
8
|
|
|
9
9
|
describe('SNS Pub-Sub', () => {
|
|
10
10
|
// reset mock
|
|
@@ -20,12 +20,14 @@ describe('SNS Pub-Sub', () => {
|
|
|
20
20
|
const msg = { text: '123' }
|
|
21
21
|
const topic = '123'
|
|
22
22
|
const messageId = 'id-123'
|
|
23
|
-
SNSMock.on(PublishCommand, {
|
|
23
|
+
SNSMock.on(mockAwsCommand(PublishCommand), {
|
|
24
24
|
Message: JSON.stringify(msg),
|
|
25
25
|
TopicArn: topic,
|
|
26
|
-
}).resolves(
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
}).resolves(
|
|
27
|
+
mockAwsResult({
|
|
28
|
+
MessageId: messageId,
|
|
29
|
+
})
|
|
30
|
+
)
|
|
29
31
|
const res = await provider.publishOnTopic(msg, topic)
|
|
30
32
|
expect(res).is.not.null
|
|
31
33
|
expect(res?.MessageId).to.be.equals(messageId)
|
|
@@ -35,12 +37,14 @@ describe('SNS Pub-Sub', () => {
|
|
|
35
37
|
const msg = { text: '123' }
|
|
36
38
|
const topic = '123'
|
|
37
39
|
const messageId = 'id-123'
|
|
38
|
-
SNSMock.on(PublishCommand, {
|
|
40
|
+
SNSMock.on(mockAwsCommand(PublishCommand), {
|
|
39
41
|
Message: JSON.stringify(msg),
|
|
40
42
|
TopicArn: topic,
|
|
41
|
-
}).resolves(
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
}).resolves(
|
|
44
|
+
mockAwsResult({
|
|
45
|
+
MessageId: messageId,
|
|
46
|
+
})
|
|
47
|
+
)
|
|
44
48
|
const res = await provider.publishOnTopic(msg, topic, {
|
|
45
49
|
FifoGroup: 123,
|
|
46
50
|
})
|
|
@@ -51,7 +55,7 @@ describe('SNS Pub-Sub', () => {
|
|
|
51
55
|
test('Publish failure', async () => {
|
|
52
56
|
const msg = { text: '123' }
|
|
53
57
|
const topic = '123'
|
|
54
|
-
SNSMock.on(PublishCommand).rejects(new Error('failed!'))
|
|
58
|
+
SNSMock.on(mockAwsCommand(PublishCommand)).rejects(new Error('failed!'))
|
|
55
59
|
const res = await provider.publishOnTopic(msg, topic)
|
|
56
60
|
expect(res).is.undefined
|
|
57
61
|
})
|
|
@@ -71,12 +75,14 @@ describe('SNS SMS', () => {
|
|
|
71
75
|
const msg = 'hello world'
|
|
72
76
|
const phoneNumber = '+16042001234'
|
|
73
77
|
const messageId = 'id-123'
|
|
74
|
-
SNSMock.on(PublishCommand, {
|
|
78
|
+
SNSMock.on(mockAwsCommand(PublishCommand), {
|
|
75
79
|
Message: msg,
|
|
76
80
|
PhoneNumber: phoneNumber,
|
|
77
|
-
}).resolves(
|
|
78
|
-
|
|
79
|
-
|
|
81
|
+
}).resolves(
|
|
82
|
+
mockAwsResult({
|
|
83
|
+
MessageId: messageId,
|
|
84
|
+
})
|
|
85
|
+
)
|
|
80
86
|
const res = await provider.publishSMS(msg, phoneNumber)
|
|
81
87
|
expect(res).is.not.null
|
|
82
88
|
expect(res?.MessageId).to.be.equals(messageId)
|
|
@@ -85,7 +91,7 @@ describe('SNS SMS', () => {
|
|
|
85
91
|
test('Publish failure', async () => {
|
|
86
92
|
const msg = 'hello world'
|
|
87
93
|
const phoneNumber = '+16042001234'
|
|
88
|
-
SNSMock.on(PublishCommand).rejects(new Error('failed!'))
|
|
94
|
+
SNSMock.on(mockAwsCommand(PublishCommand)).rejects(new Error('failed!'))
|
|
89
95
|
const res = await provider.publishSMS(msg, phoneNumber)
|
|
90
96
|
expect(res).is.undefined
|
|
91
97
|
})
|