@creator.co/wapi 1.2.2 → 1.2.3
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 +1 -1
- package/.github/workflows/prs.yml +1 -1
- package/index.ts +12 -10
- package/jest.config.ts +19 -19
- package/package.json +1 -1
- 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,70 +1,69 @@
|
|
|
1
|
-
import { APIGatewayProxyEvent, Context } from
|
|
2
|
-
import { expect } from
|
|
3
|
-
import { Request } from
|
|
1
|
+
import { APIGatewayProxyEvent, Context } from 'aws-lambda'
|
|
2
|
+
import { expect } from 'chai'
|
|
3
|
+
import { Request } from 'express'
|
|
4
4
|
|
|
5
|
-
import GenericHandlerEvent from
|
|
5
|
+
import GenericHandlerEvent from '../../../../src/Server/lib/container/GenericHandlerEvent'
|
|
6
6
|
|
|
7
|
-
describe(
|
|
8
|
-
test(
|
|
7
|
+
describe('GenericHandlerEvent invocation paths', () => {
|
|
8
|
+
test('Simple success', async () => {
|
|
9
9
|
const event = new GenericHandlerEvent(
|
|
10
10
|
<Request>(<unknown>{
|
|
11
|
-
socket: { remoteAddress:
|
|
11
|
+
socket: { remoteAddress: '127.0.0.1' },
|
|
12
12
|
}),
|
|
13
13
|
async (event: APIGatewayProxyEvent, context: Context) => {
|
|
14
14
|
expect(context.getRemainingTimeInMillis()).to.not.be.null
|
|
15
|
-
context.succeed(
|
|
16
|
-
}
|
|
15
|
+
context.succeed('Success')
|
|
16
|
+
}
|
|
17
17
|
)
|
|
18
18
|
const resp = await event.invoke()
|
|
19
19
|
expect(resp).to.not.be.null
|
|
20
20
|
expect(resp.err).to.be.null
|
|
21
|
-
expect(resp.data).to.be.equals(
|
|
21
|
+
expect(resp.data).to.be.equals('Success')
|
|
22
22
|
})
|
|
23
23
|
|
|
24
|
-
test(
|
|
24
|
+
test('Simple failure', async () => {
|
|
25
25
|
const event = new GenericHandlerEvent(
|
|
26
26
|
<Request>(<unknown>{}),
|
|
27
27
|
async (event: APIGatewayProxyEvent, context: Context) => {
|
|
28
|
-
context.fail(
|
|
29
|
-
}
|
|
28
|
+
context.fail('Error!')
|
|
29
|
+
}
|
|
30
30
|
)
|
|
31
31
|
const resp = await event.invoke()
|
|
32
32
|
expect(resp).to.not.be.null
|
|
33
33
|
expect(resp.data).to.be.undefined
|
|
34
|
-
expect(resp.err).to.be.equals(
|
|
34
|
+
expect(resp.err).to.be.equals('Error!')
|
|
35
35
|
})
|
|
36
36
|
|
|
37
|
-
test(
|
|
37
|
+
test('Simple done (errored)', async () => {
|
|
38
38
|
const event = new GenericHandlerEvent(
|
|
39
39
|
<Request>(<unknown>{}),
|
|
40
40
|
async (event: APIGatewayProxyEvent, context: Context) => {
|
|
41
|
-
context.done(new Error(
|
|
42
|
-
}
|
|
41
|
+
context.done(new Error('Error!'))
|
|
42
|
+
}
|
|
43
43
|
)
|
|
44
44
|
const resp = await event.invoke()
|
|
45
45
|
expect(resp).to.not.be.null
|
|
46
46
|
expect(resp.data).to.be.undefined
|
|
47
|
-
expect(resp.err).to.be.an(
|
|
48
|
-
if (resp.err instanceof Error)
|
|
49
|
-
expect(resp.err?.message).to.be.equals("Error!")
|
|
47
|
+
expect(resp.err).to.be.an('Error')
|
|
48
|
+
if (resp.err instanceof Error) expect(resp.err?.message).to.be.equals('Error!')
|
|
50
49
|
})
|
|
51
50
|
|
|
52
|
-
test(
|
|
51
|
+
test('Simple done (success)', async () => {
|
|
53
52
|
const event = new GenericHandlerEvent(
|
|
54
53
|
<Request>(<unknown>{}),
|
|
55
54
|
async (event: APIGatewayProxyEvent, context: Context) => {
|
|
56
|
-
context.done(undefined,
|
|
57
|
-
}
|
|
55
|
+
context.done(undefined, 'Success!')
|
|
56
|
+
}
|
|
58
57
|
)
|
|
59
58
|
const resp = await event.invoke()
|
|
60
59
|
expect(resp).to.not.be.null
|
|
61
60
|
expect(resp.err).to.be.undefined
|
|
62
|
-
expect(resp.data).to.be.equals(
|
|
61
|
+
expect(resp.data).to.be.equals('Success!')
|
|
63
62
|
})
|
|
64
63
|
|
|
65
|
-
test(
|
|
64
|
+
test('Exception on execution', async () => {
|
|
66
65
|
const event = new GenericHandlerEvent(<Request>(<unknown>{}), async () => {
|
|
67
|
-
throw new Error(
|
|
66
|
+
throw new Error('Failed!')
|
|
68
67
|
})
|
|
69
68
|
let err: any = null,
|
|
70
69
|
resp: any = null
|
|
@@ -75,28 +74,28 @@ describe("GenericHandlerEvent invocation paths", () => {
|
|
|
75
74
|
}
|
|
76
75
|
expect(resp).to.be.null
|
|
77
76
|
expect(err).to.not.be.null
|
|
78
|
-
expect(err).to.be.an(
|
|
79
|
-
expect(err.message).to.be.equals(
|
|
77
|
+
expect(err).to.be.an('Error')
|
|
78
|
+
expect(err.message).to.be.equals('Failed!')
|
|
80
79
|
})
|
|
81
80
|
})
|
|
82
81
|
|
|
83
|
-
describe(
|
|
84
|
-
test(
|
|
82
|
+
describe('GenericHandlerEvent event test', () => {
|
|
83
|
+
test('Simple event test', async () => {
|
|
85
84
|
const event = new GenericHandlerEvent(
|
|
86
85
|
<Request>(<unknown>{
|
|
87
|
-
headers: { Authorization:
|
|
88
|
-
method:
|
|
89
|
-
query:
|
|
86
|
+
headers: { Authorization: '123', 'x-forwarded-for': '127.0.0.1' },
|
|
87
|
+
method: 'get',
|
|
88
|
+
query: '/status?name=ryan',
|
|
90
89
|
}),
|
|
91
90
|
async (event: APIGatewayProxyEvent, context: Context) => {
|
|
92
91
|
expect(context.getRemainingTimeInMillis()).to.not.be.null
|
|
93
|
-
context.succeed(
|
|
94
|
-
}
|
|
92
|
+
context.succeed('Success')
|
|
93
|
+
}
|
|
95
94
|
)
|
|
96
95
|
const resp = await event.invoke()
|
|
97
96
|
expect(resp).to.not.be.null
|
|
98
97
|
expect(resp.err).to.be.null
|
|
99
|
-
expect(resp.data).to.be.equals(
|
|
98
|
+
expect(resp.data).to.be.equals('Success')
|
|
100
99
|
})
|
|
101
100
|
})
|
|
102
101
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { expect as j_expect } from
|
|
2
|
-
import { expect } from
|
|
3
|
-
import { Request, Response } from
|
|
1
|
+
import { expect as j_expect } from '@jest/globals'
|
|
2
|
+
import { expect } from 'chai'
|
|
3
|
+
import { Request, Response } from 'express'
|
|
4
4
|
|
|
5
|
-
import HealthHandler from
|
|
5
|
+
import HealthHandler from '../../../../src/Server/lib/container/HealthHandler'
|
|
6
6
|
|
|
7
7
|
function observableResponse(): Response {
|
|
8
8
|
const resp = <Response>(<unknown>{
|
|
@@ -14,13 +14,13 @@ function observableResponse(): Response {
|
|
|
14
14
|
return resp
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
describe(
|
|
18
|
-
test(
|
|
17
|
+
describe('HealthHandler invocation path', () => {
|
|
18
|
+
test('Simple', async () => {
|
|
19
19
|
const resp = observableResponse()
|
|
20
20
|
const handlerResp = await HealthHandler(<Request>(<unknown>{}), resp)
|
|
21
21
|
//
|
|
22
22
|
expect(handlerResp).to.be.undefined
|
|
23
|
-
j_expect(resp.send).toBeCalledWith(
|
|
23
|
+
j_expect(resp.send).toBeCalledWith('Healthy!')
|
|
24
24
|
j_expect(resp.json).not.toBeCalled()
|
|
25
25
|
j_expect(resp.status).not.toBeCalled()
|
|
26
26
|
j_expect(resp.header).not.toBeCalled()
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { expect as j_expect } from
|
|
2
|
-
import { APIGatewayProxyEvent, Context } from
|
|
3
|
-
import { expect } from
|
|
4
|
-
import * as request from
|
|
1
|
+
import { expect as j_expect } from '@jest/globals'
|
|
2
|
+
import { APIGatewayProxyEvent, Context } from 'aws-lambda'
|
|
3
|
+
import { expect } from 'chai'
|
|
4
|
+
import * as request from 'supertest'
|
|
5
5
|
|
|
6
|
-
import Globals from
|
|
7
|
-
import Proxy from
|
|
8
|
-
import { defaultUrl } from
|
|
6
|
+
import Globals from '../../../../src/Globals'
|
|
7
|
+
import Proxy from '../../../../src/Server/lib/container/Proxy'
|
|
8
|
+
import { defaultUrl } from '../../../Test.utils'
|
|
9
9
|
|
|
10
|
-
describe(
|
|
10
|
+
describe('Proxy configs', () => {
|
|
11
11
|
// @ts-ignore
|
|
12
|
-
let mockExit = jest.spyOn(process,
|
|
12
|
+
let mockExit = jest.spyOn(process, 'exit').mockImplementation(() => {})
|
|
13
13
|
beforeAll(() => {
|
|
14
14
|
// @ts-ignore
|
|
15
|
-
mockExit = jest.spyOn(process,
|
|
15
|
+
mockExit = jest.spyOn(process, 'exit').mockImplementation(() => {})
|
|
16
16
|
})
|
|
17
17
|
afterAll(() => {
|
|
18
18
|
mockExit.mockRestore()
|
|
@@ -21,51 +21,51 @@ describe("Proxy configs", () => {
|
|
|
21
21
|
mockExit.mockReset()
|
|
22
22
|
})
|
|
23
23
|
|
|
24
|
-
test(
|
|
24
|
+
test('Empty config url & unload with error', async () => {
|
|
25
25
|
const proxy = new Proxy({ routes: [] }, async () => {})
|
|
26
26
|
await proxy.load()
|
|
27
|
-
await proxy.unload(
|
|
27
|
+
await proxy.unload('Error')
|
|
28
28
|
j_expect(mockExit).toBeCalledWith(1)
|
|
29
29
|
})
|
|
30
30
|
|
|
31
|
-
test(
|
|
31
|
+
test('Simple port config', async () => {
|
|
32
32
|
const proxy = new Proxy({ routes: [], port: 56562 }, async () => {})
|
|
33
33
|
await proxy.load()
|
|
34
34
|
await proxy.unload()
|
|
35
35
|
j_expect(mockExit).toBeCalledWith(0)
|
|
36
36
|
})
|
|
37
37
|
|
|
38
|
-
test(
|
|
38
|
+
test('Simple timeout config', async () => {
|
|
39
39
|
const proxy = new Proxy({ routes: [], timeout: 1000 }, async () => {})
|
|
40
40
|
await proxy.load()
|
|
41
41
|
await proxy.unload()
|
|
42
42
|
j_expect(mockExit).toBeCalledWith(0)
|
|
43
43
|
})
|
|
44
44
|
|
|
45
|
-
test(
|
|
45
|
+
test('Simple cors config', async () => {
|
|
46
46
|
const proxy = new Proxy(
|
|
47
47
|
{
|
|
48
48
|
routes: [],
|
|
49
49
|
cors: {
|
|
50
|
-
origin:
|
|
51
|
-
headers: [
|
|
50
|
+
origin: '*',
|
|
51
|
+
headers: ['Authorization'],
|
|
52
52
|
allowCredentials: true,
|
|
53
53
|
},
|
|
54
54
|
},
|
|
55
|
-
async () => {}
|
|
55
|
+
async () => {}
|
|
56
56
|
)
|
|
57
57
|
await proxy.load()
|
|
58
58
|
await proxy.unload()
|
|
59
59
|
j_expect(mockExit).toBeCalledWith(0)
|
|
60
60
|
})
|
|
61
61
|
|
|
62
|
-
test(
|
|
62
|
+
test('Empty cors config', async () => {
|
|
63
63
|
const proxy = new Proxy(
|
|
64
64
|
{
|
|
65
65
|
routes: [],
|
|
66
66
|
cors: {},
|
|
67
67
|
},
|
|
68
|
-
async () => {}
|
|
68
|
+
async () => {}
|
|
69
69
|
)
|
|
70
70
|
await proxy.load()
|
|
71
71
|
await proxy.unload()
|
|
@@ -73,12 +73,12 @@ describe("Proxy configs", () => {
|
|
|
73
73
|
})
|
|
74
74
|
})
|
|
75
75
|
|
|
76
|
-
describe(
|
|
76
|
+
describe('Proxy behaviour', () => {
|
|
77
77
|
// @ts-ignore
|
|
78
|
-
let mockExit = jest.spyOn(process,
|
|
78
|
+
let mockExit = jest.spyOn(process, 'exit').mockImplementation(() => {})
|
|
79
79
|
beforeAll(() => {
|
|
80
80
|
// @ts-ignore
|
|
81
|
-
mockExit = jest.spyOn(process,
|
|
81
|
+
mockExit = jest.spyOn(process, 'exit').mockImplementation(() => {})
|
|
82
82
|
})
|
|
83
83
|
afterAll(() => {
|
|
84
84
|
mockExit.mockRestore()
|
|
@@ -87,21 +87,21 @@ describe("Proxy behaviour", () => {
|
|
|
87
87
|
mockExit.mockReset()
|
|
88
88
|
})
|
|
89
89
|
|
|
90
|
-
test(
|
|
90
|
+
test('Stop twice', async () => {
|
|
91
91
|
const proxy = new Proxy({ routes: [] }, async () => {})
|
|
92
92
|
await proxy.load()
|
|
93
|
-
await Promise.all([proxy.unload(
|
|
93
|
+
await Promise.all([proxy.unload('Error'), proxy.unload('Error')])
|
|
94
94
|
j_expect(mockExit).toHaveBeenCalledTimes(1)
|
|
95
95
|
j_expect(mockExit).toBeCalledWith(1)
|
|
96
96
|
})
|
|
97
97
|
})
|
|
98
98
|
|
|
99
|
-
describe(
|
|
99
|
+
describe('Proxy routing', () => {
|
|
100
100
|
// @ts-ignore
|
|
101
|
-
let mockExit = jest.spyOn(process,
|
|
101
|
+
let mockExit = jest.spyOn(process, 'exit').mockImplementation(() => {})
|
|
102
102
|
beforeAll(() => {
|
|
103
103
|
// @ts-ignore
|
|
104
|
-
mockExit = jest.spyOn(process,
|
|
104
|
+
mockExit = jest.spyOn(process, 'exit').mockImplementation(() => {})
|
|
105
105
|
})
|
|
106
106
|
afterAll(() => {
|
|
107
107
|
mockExit.mockRestore()
|
|
@@ -110,69 +110,66 @@ describe("Proxy routing", () => {
|
|
|
110
110
|
mockExit.mockReset()
|
|
111
111
|
})
|
|
112
112
|
|
|
113
|
-
test(
|
|
113
|
+
test('Health & Default handler', async () => {
|
|
114
114
|
let count = 0
|
|
115
115
|
const proxy = new Proxy(
|
|
116
116
|
{ routes: [] },
|
|
117
117
|
async (event: APIGatewayProxyEvent, context: Context) => {
|
|
118
118
|
count++
|
|
119
119
|
context.succeed({
|
|
120
|
-
body: JSON.stringify({ name:
|
|
120
|
+
body: JSON.stringify({ name: '123' }),
|
|
121
121
|
statusCode: 200,
|
|
122
122
|
})
|
|
123
|
-
}
|
|
123
|
+
}
|
|
124
124
|
)
|
|
125
125
|
await proxy.load()
|
|
126
126
|
// Health check
|
|
127
127
|
const res = await request(defaultUrl)
|
|
128
128
|
.get(Globals.Listener_HTTP_DefaultHealthCheckRoute)
|
|
129
|
-
.expect(
|
|
129
|
+
.expect('Content-Type', 'text/html; charset=utf-8')
|
|
130
130
|
.expect(200)
|
|
131
|
-
expect(res.text).to.be.equals(
|
|
131
|
+
expect(res.text).to.be.equals('Healthy!')
|
|
132
132
|
// Generic handler
|
|
133
133
|
const resG = await request(defaultUrl)
|
|
134
134
|
.get(`/abc`)
|
|
135
|
-
.expect(
|
|
135
|
+
.expect('Content-Type', 'application/json; charset=utf-8')
|
|
136
136
|
.expect(200)
|
|
137
|
-
expect(resG.body).to.be.deep.equals({ name:
|
|
137
|
+
expect(resG.body).to.be.deep.equals({ name: '123' })
|
|
138
138
|
// Expected count
|
|
139
139
|
expect(count).to.be.equals(1)
|
|
140
140
|
// Unload
|
|
141
|
-
await proxy.unload(
|
|
141
|
+
await proxy.unload('Error')
|
|
142
142
|
j_expect(mockExit).toHaveBeenCalledTimes(1)
|
|
143
143
|
j_expect(mockExit).toBeCalledWith(1)
|
|
144
144
|
})
|
|
145
145
|
|
|
146
|
-
test(
|
|
146
|
+
test('Proxy on custom port', async () => {
|
|
147
147
|
let count = 0
|
|
148
148
|
const port = 56542
|
|
149
|
-
const url = defaultUrl.replace(
|
|
150
|
-
String(Globals.Listener_HTTP_DefaultPort),
|
|
151
|
-
String(port),
|
|
152
|
-
)
|
|
149
|
+
const url = defaultUrl.replace(String(Globals.Listener_HTTP_DefaultPort), String(port))
|
|
153
150
|
const proxy = new Proxy(
|
|
154
151
|
{ routes: [], port },
|
|
155
152
|
async (event: APIGatewayProxyEvent, context: Context) => {
|
|
156
153
|
count++
|
|
157
154
|
context.succeed({
|
|
158
|
-
body: JSON.stringify({ name:
|
|
155
|
+
body: JSON.stringify({ name: '123' }),
|
|
159
156
|
statusCode: 200,
|
|
160
157
|
})
|
|
161
|
-
}
|
|
158
|
+
}
|
|
162
159
|
)
|
|
163
160
|
await proxy.load()
|
|
164
161
|
// Health check
|
|
165
162
|
const res = await request(url)
|
|
166
163
|
.get(Globals.Listener_HTTP_DefaultHealthCheckRoute)
|
|
167
|
-
.expect(
|
|
164
|
+
.expect('Content-Type', 'text/html; charset=utf-8')
|
|
168
165
|
.expect(200)
|
|
169
|
-
expect(res.text).to.be.equals(
|
|
166
|
+
expect(res.text).to.be.equals('Healthy!')
|
|
170
167
|
// Generic handler
|
|
171
168
|
const resG = await request(url)
|
|
172
169
|
.get(`/abc`)
|
|
173
|
-
.expect(
|
|
170
|
+
.expect('Content-Type', 'application/json; charset=utf-8')
|
|
174
171
|
.expect(200)
|
|
175
|
-
expect(resG.body).to.be.deep.equals({ name:
|
|
172
|
+
expect(resG.body).to.be.deep.equals({ name: '123' })
|
|
176
173
|
// Expected count
|
|
177
174
|
expect(count).to.be.equals(1)
|
|
178
175
|
// Unload
|
|
@@ -181,7 +178,7 @@ describe("Proxy routing", () => {
|
|
|
181
178
|
j_expect(mockExit).toBeCalledWith(0)
|
|
182
179
|
})
|
|
183
180
|
|
|
184
|
-
test(
|
|
181
|
+
test('Proxy does timeout', async () => {
|
|
185
182
|
let count = 0
|
|
186
183
|
const timeout = 1000
|
|
187
184
|
const proxy = new Proxy(
|
|
@@ -190,82 +187,72 @@ describe("Proxy routing", () => {
|
|
|
190
187
|
count++
|
|
191
188
|
setTimeout(() => {
|
|
192
189
|
context.succeed({
|
|
193
|
-
body: JSON.stringify({ name:
|
|
190
|
+
body: JSON.stringify({ name: '123' }),
|
|
194
191
|
statusCode: 200,
|
|
195
192
|
})
|
|
196
193
|
}, timeout * 2)
|
|
197
|
-
}
|
|
194
|
+
}
|
|
198
195
|
)
|
|
199
196
|
await proxy.load()
|
|
200
197
|
// Health check
|
|
201
198
|
const res = await request(defaultUrl)
|
|
202
199
|
.get(Globals.Listener_HTTP_DefaultHealthCheckRoute)
|
|
203
|
-
.expect(
|
|
200
|
+
.expect('Content-Type', 'text/html; charset=utf-8')
|
|
204
201
|
.expect(200)
|
|
205
|
-
expect(res.text).to.be.equals(
|
|
202
|
+
expect(res.text).to.be.equals('Healthy!')
|
|
206
203
|
// Generic handler
|
|
207
204
|
let err: any = null
|
|
208
205
|
try {
|
|
209
206
|
await request(defaultUrl)
|
|
210
207
|
.get(`/abc`)
|
|
211
|
-
.expect(
|
|
208
|
+
.expect('Content-Type', 'application/json; charset=utf-8')
|
|
212
209
|
.expect(200)
|
|
213
210
|
} catch (e) {
|
|
214
211
|
err = e
|
|
215
212
|
}
|
|
216
|
-
expect(err?.message).to.be.equals(
|
|
213
|
+
expect(err?.message).to.be.equals('socket hang up')
|
|
217
214
|
// Expected count
|
|
218
215
|
expect(count).to.be.equals(1)
|
|
219
216
|
// Unload
|
|
220
|
-
await proxy.unload(
|
|
217
|
+
await proxy.unload('Error')
|
|
221
218
|
j_expect(mockExit).toHaveBeenCalledTimes(1)
|
|
222
219
|
j_expect(mockExit).toBeCalledWith(1)
|
|
223
220
|
//
|
|
224
|
-
return new Promise(
|
|
221
|
+
return new Promise(resolve => {
|
|
225
222
|
setTimeout(resolve, timeout * 2)
|
|
226
223
|
})
|
|
227
224
|
})
|
|
228
225
|
|
|
229
|
-
test(
|
|
226
|
+
test('Proxy respects cors', async () => {
|
|
230
227
|
let count = 0
|
|
231
228
|
const proxy = new Proxy(
|
|
232
229
|
{
|
|
233
230
|
routes: [],
|
|
234
231
|
cors: {
|
|
235
|
-
origin:
|
|
236
|
-
headers: [
|
|
232
|
+
origin: '*',
|
|
233
|
+
headers: ['Authorization'],
|
|
237
234
|
allowCredentials: true,
|
|
238
235
|
},
|
|
239
236
|
},
|
|
240
237
|
async (event: APIGatewayProxyEvent, context: Context) => {
|
|
241
238
|
count++
|
|
242
239
|
context.succeed({
|
|
243
|
-
body: JSON.stringify({ name:
|
|
240
|
+
body: JSON.stringify({ name: '123' }),
|
|
244
241
|
statusCode: 200,
|
|
245
242
|
})
|
|
246
|
-
}
|
|
243
|
+
}
|
|
247
244
|
)
|
|
248
245
|
await proxy.load()
|
|
249
246
|
// White-listed header is allowed
|
|
250
|
-
const resWH = await request(defaultUrl)
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
expect(resWH.header["access-control-allow-origin"]).to.equal("*")
|
|
255
|
-
expect(resWH.header["access-control-allow-credentials"]).to.equal("true")
|
|
256
|
-
expect(resWH.header["access-control-allow-headers"]).to.equal(
|
|
257
|
-
"Authorization",
|
|
258
|
-
)
|
|
247
|
+
const resWH = await request(defaultUrl).options(`/abc`).set('Authorization', 123).expect(204)
|
|
248
|
+
expect(resWH.header['access-control-allow-origin']).to.equal('*')
|
|
249
|
+
expect(resWH.header['access-control-allow-credentials']).to.equal('true')
|
|
250
|
+
expect(resWH.header['access-control-allow-headers']).to.equal('Authorization')
|
|
259
251
|
// Non white-listed header is allowed
|
|
260
|
-
const resNWH = await request(defaultUrl)
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
expect(resNWH.header["access-control-allow-origin"]).to.equal("*")
|
|
265
|
-
expect(resNWH.header["access-control-allow-credentials"]).to.equal("true")
|
|
266
|
-
expect(resNWH.header["access-control-allow-headers"]).to.equal(
|
|
267
|
-
"Authorization",
|
|
268
|
-
)
|
|
252
|
+
const resNWH = await request(defaultUrl).options(`/abc`).set('2Authorization2', 123).expect(204)
|
|
253
|
+
expect(resNWH.header['access-control-allow-origin']).to.equal('*')
|
|
254
|
+
expect(resNWH.header['access-control-allow-credentials']).to.equal('true')
|
|
255
|
+
expect(resNWH.header['access-control-allow-headers']).to.equal('Authorization')
|
|
269
256
|
// Expected count
|
|
270
257
|
expect(count).to.be.equals(0)
|
|
271
258
|
// Unload
|
|
@@ -1,46 +1,45 @@
|
|
|
1
|
-
import { expect } from
|
|
1
|
+
import { expect } from 'chai'
|
|
2
2
|
|
|
3
|
-
import * as Utils from
|
|
3
|
+
import * as Utils from '../../../../src/Server/lib/container/Utils'
|
|
4
4
|
|
|
5
|
-
describe(
|
|
6
|
-
test(
|
|
5
|
+
describe('parseQueryStringParameters', () => {
|
|
6
|
+
test('Null url', () => {
|
|
7
7
|
// @ts-ignore
|
|
8
8
|
const validationResult = Utils.parseQueryStringParameters(null)
|
|
9
9
|
expect(validationResult).to.be.deep.equals(null)
|
|
10
10
|
})
|
|
11
11
|
|
|
12
|
-
test(
|
|
13
|
-
const validationResult = Utils.parseQueryStringParameters(
|
|
12
|
+
test('Empty url', () => {
|
|
13
|
+
const validationResult = Utils.parseQueryStringParameters('')
|
|
14
14
|
expect(validationResult).to.be.deep.equals(null)
|
|
15
15
|
})
|
|
16
16
|
|
|
17
|
-
test(
|
|
18
|
-
const validationResult =
|
|
19
|
-
Utils.parseQueryStringParameters("/status?name=ryan")
|
|
17
|
+
test('Simple param', () => {
|
|
18
|
+
const validationResult = Utils.parseQueryStringParameters('/status?name=ryan')
|
|
20
19
|
expect(validationResult).to.be.deep.equals({
|
|
21
|
-
name:
|
|
20
|
+
name: 'ryan',
|
|
22
21
|
})
|
|
23
22
|
})
|
|
24
23
|
})
|
|
25
24
|
|
|
26
|
-
describe(
|
|
27
|
-
test(
|
|
25
|
+
describe('parseMultiValueQueryStringParameters', () => {
|
|
26
|
+
test('Null url', () => {
|
|
28
27
|
// @ts-ignore
|
|
29
28
|
const validationResult = Utils.parseMultiValueQueryStringParameters()
|
|
30
29
|
expect(validationResult).to.be.deep.equals({})
|
|
31
30
|
})
|
|
32
31
|
|
|
33
|
-
test(
|
|
34
|
-
const validationResult = Utils.parseMultiValueQueryStringParameters(
|
|
32
|
+
test('Empty url', () => {
|
|
33
|
+
const validationResult = Utils.parseMultiValueQueryStringParameters('')
|
|
35
34
|
expect(validationResult).to.be.deep.equals({})
|
|
36
35
|
})
|
|
37
36
|
|
|
38
|
-
test(
|
|
37
|
+
test('Simple multivalue param', () => {
|
|
39
38
|
const validationResult = Utils.parseMultiValueQueryStringParameters(
|
|
40
|
-
|
|
39
|
+
'/status?name=ryan&name=ryan2'
|
|
41
40
|
)
|
|
42
41
|
expect(validationResult).to.be.deep.equals({
|
|
43
|
-
name: [
|
|
42
|
+
name: ['ryan', 'ryan2'],
|
|
44
43
|
})
|
|
45
44
|
})
|
|
46
45
|
})
|
package/tests/Test.utils.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { APIGatewayEvent, Context, SQSEvent } from
|
|
2
|
-
import { z } from
|
|
1
|
+
import { APIGatewayEvent, Context, SQSEvent } from 'aws-lambda'
|
|
2
|
+
import { z } from 'zod'
|
|
3
3
|
|
|
4
|
-
import Transaction from
|
|
5
|
-
import Globals from
|
|
4
|
+
import Transaction from '../src/BaseEvent/Transaction'
|
|
5
|
+
import Globals from '../src/Globals'
|
|
6
6
|
|
|
7
7
|
export const defaultHeaders = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
'Access-Control-Allow-Credentials': true,
|
|
9
|
+
'Access-Control-Allow-Origin': '*',
|
|
10
|
+
'Content-Type': 'application/json',
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export const defaultUrl = `localhost:${Globals.Listener_HTTP_DefaultPort}`
|
|
@@ -66,10 +66,10 @@ export function observableContext(data?: any) {
|
|
|
66
66
|
})
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
export const privateKey =
|
|
69
|
+
export const privateKey = 'tMHOuszBQmF6XtwgrUpvqpk07rh3RATX'
|
|
70
70
|
|
|
71
71
|
export const foreignToken =
|
|
72
|
-
|
|
72
|
+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c'
|
|
73
73
|
|
|
74
74
|
export const ViewSchema = z.object({
|
|
75
75
|
id: z.string(),
|