ac-useractionlog-connector 4.0.25
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/.acsemver.js +9 -0
- package/.github/CODEOWNERS +9 -0
- package/.github/workflows/node.js.yml +33 -0
- package/.ncurc.js +8 -0
- package/CHANGELOG.md +624 -0
- package/Makefile +22 -0
- package/README.md +190 -0
- package/debug.js +43 -0
- package/eslint.config.js +34 -0
- package/index.js +167 -0
- package/package.json +35 -0
- package/test/test.js +255 -0
package/test/test.js
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
const { expect } = require('chai')
|
|
2
|
+
const _ = require('lodash')
|
|
3
|
+
const ual = require('../index')
|
|
4
|
+
const connector = new ual({})
|
|
5
|
+
|
|
6
|
+
const string1001 = new Array(600000).join('b')
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
describe('Tests', () => {
|
|
10
|
+
it('Test properties', async() => {
|
|
11
|
+
const req = {
|
|
12
|
+
method: 'post',
|
|
13
|
+
options: {
|
|
14
|
+
controller: 'search',
|
|
15
|
+
action: 'search',
|
|
16
|
+
},
|
|
17
|
+
authInfo: {
|
|
18
|
+
token: 'x-token-123',
|
|
19
|
+
clientId: 'x-client-abc',
|
|
20
|
+
deviceIdentifier: 'x-my-device',
|
|
21
|
+
clientVersion: 'app_11.04.235'
|
|
22
|
+
},
|
|
23
|
+
headers: {
|
|
24
|
+
'user-agent': 'Mozilla',
|
|
25
|
+
},
|
|
26
|
+
allParams: () => {
|
|
27
|
+
return
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const params = {
|
|
31
|
+
ip: '1.1.1.1',
|
|
32
|
+
statusCode: 200,
|
|
33
|
+
processingTime: 12,
|
|
34
|
+
userId: 123,
|
|
35
|
+
customerId: 147,
|
|
36
|
+
mediaContainerId: 46758,
|
|
37
|
+
platform: 'APIv5',
|
|
38
|
+
requestPayload: { searchTerm: 'abc' },
|
|
39
|
+
responsePayload: { hits: 0 },
|
|
40
|
+
loginuid: '1234567890abcdef',
|
|
41
|
+
}
|
|
42
|
+
const response = await connector.log(params, req)
|
|
43
|
+
_.forEach(params, (val, prop) => {
|
|
44
|
+
if (prop === 'requestPayload') {
|
|
45
|
+
expect(response).to.have.property('payload', JSON.stringify(params[prop]))
|
|
46
|
+
}
|
|
47
|
+
else if (prop === 'responsePayload') {
|
|
48
|
+
expect(response).to.have.property('response', JSON.stringify(params[prop]))
|
|
49
|
+
}
|
|
50
|
+
else if (prop === 'platform') {
|
|
51
|
+
expect(response).to.have.property('platform', 'apiv5')
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
expect(response).to.have.property(prop, val)
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
_.forEach(req.options, (val, prop) => {
|
|
59
|
+
expect(response).to.have.property(prop, val)
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
_.forEach(req.authInfo, (val, prop) => {
|
|
63
|
+
if (prop === 'token') {
|
|
64
|
+
expect(response).not.to.have.property(prop)
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
expect(response).to.have.property(prop, val)
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
expect(response).to.have.property('userAgent', _.get(req, 'headers.user-agent'))
|
|
72
|
+
expect(response).to.have.property('method', _.get(req, 'method'))
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
it('Check truncated payload > 1MB - truncated', async() => {
|
|
76
|
+
const req = {
|
|
77
|
+
method: 'post',
|
|
78
|
+
options: {
|
|
79
|
+
controller: 'metadata',
|
|
80
|
+
action: 'create',
|
|
81
|
+
},
|
|
82
|
+
authInfo: {
|
|
83
|
+
token: 'x-token-123',
|
|
84
|
+
clientId: 'x-client-abc',
|
|
85
|
+
deviceIdentifier: 'x-my-device',
|
|
86
|
+
clientVersion: 'app_11.04.235'
|
|
87
|
+
},
|
|
88
|
+
headers: {
|
|
89
|
+
'user-agent': 'Mozilla',
|
|
90
|
+
},
|
|
91
|
+
allParams: () => {
|
|
92
|
+
return
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const params = {
|
|
96
|
+
ip: '1.1.1.1',
|
|
97
|
+
statusCode: 200,
|
|
98
|
+
processingTime: 12,
|
|
99
|
+
userId: 123,
|
|
100
|
+
customerId: 147,
|
|
101
|
+
mediaContainerId: 46758,
|
|
102
|
+
platform: 'APIv5',
|
|
103
|
+
requestPayload: { content: string1001 },
|
|
104
|
+
responsePayload: { content: string1001 }
|
|
105
|
+
}
|
|
106
|
+
const response = await connector.log(params, req)
|
|
107
|
+
|
|
108
|
+
expect(response).to.have.property('truncatedResponse', true)
|
|
109
|
+
expect(response.payload).to.be.a('string')
|
|
110
|
+
expect(response.response).to.be.a('string')
|
|
111
|
+
|
|
112
|
+
// response is trimmed to valid JSON, payload preserved where possible
|
|
113
|
+
expect(() => JSON.parse(response.response)).to.not.throw()
|
|
114
|
+
expect(() => JSON.parse(response.payload)).to.not.throw()
|
|
115
|
+
|
|
116
|
+
const totalSize = Buffer.byteLength(JSON.stringify(response), 'utf8')
|
|
117
|
+
expect(totalSize).to.be.lessThan(1024000)
|
|
118
|
+
|
|
119
|
+
_.forEach(req.options, (val, prop) => {
|
|
120
|
+
expect(response).to.have.property(prop, val)
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
_.forEach(req.authInfo, (val, prop) => {
|
|
124
|
+
if (prop === 'token') {
|
|
125
|
+
expect(response).not.to.have.property(prop)
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
expect(response).to.have.property(prop, val)
|
|
129
|
+
}
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
expect(response).to.have.property('userAgent', _.get(req, 'headers.user-agent'))
|
|
133
|
+
expect(response).to.have.property('method', _.get(req, 'method'))
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
it('Check truncated payload with nested arrays - new limitJSONPayload', async() => {
|
|
137
|
+
const req = {
|
|
138
|
+
method: 'post',
|
|
139
|
+
options: {
|
|
140
|
+
controller: 'metadata',
|
|
141
|
+
action: 'create',
|
|
142
|
+
},
|
|
143
|
+
authInfo: {
|
|
144
|
+
clientId: 'x-client-abc',
|
|
145
|
+
deviceIdentifier: 'x-my-device',
|
|
146
|
+
clientVersion: 'app_11.04.235'
|
|
147
|
+
},
|
|
148
|
+
headers: {
|
|
149
|
+
'user-agent': 'Mozilla',
|
|
150
|
+
},
|
|
151
|
+
allParams: () => {
|
|
152
|
+
return
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const largeString = new Array(1100000).join('x')
|
|
157
|
+
|
|
158
|
+
const params = {
|
|
159
|
+
ip: '1.1.1.1',
|
|
160
|
+
statusCode: 200,
|
|
161
|
+
processingTime: 12,
|
|
162
|
+
userId: 123,
|
|
163
|
+
customerId: 147,
|
|
164
|
+
platform: 'APIv5',
|
|
165
|
+
requestPayload: {
|
|
166
|
+
ids: [1002],
|
|
167
|
+
metadata: [
|
|
168
|
+
{ title: 'meta_detectedContent', content: largeString },
|
|
169
|
+
{ title: 'other', content: 'small' }
|
|
170
|
+
]
|
|
171
|
+
},
|
|
172
|
+
responsePayload: { ok: true }
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const response = await connector.log(params, req)
|
|
176
|
+
|
|
177
|
+
expect(response).to.have.property('truncatedResponse', true)
|
|
178
|
+
|
|
179
|
+
// payload trimmed to valid JSON
|
|
180
|
+
expect(() => JSON.parse(response.payload)).to.not.throw()
|
|
181
|
+
const payload = JSON.parse(response.payload)
|
|
182
|
+
expect(payload.metadata[0].content.length).to.be.lessThan(largeString.length)
|
|
183
|
+
expect(payload.metadata[1].content).to.equal('small')
|
|
184
|
+
|
|
185
|
+
const totalSize = Buffer.byteLength(JSON.stringify(response), 'utf8')
|
|
186
|
+
expect(totalSize).to.be.lessThan(1024000)
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
it('Check truncated array-of-strings in response', async() => {
|
|
190
|
+
const req = {
|
|
191
|
+
method: 'post',
|
|
192
|
+
options: { controller: 'metadata', action: 'create' },
|
|
193
|
+
authInfo: { clientId: 'x-client-abc', deviceIdentifier: 'x-my-device', clientVersion: 'app_11.04.235' },
|
|
194
|
+
headers: { 'user-agent': 'Mozilla' },
|
|
195
|
+
allParams: () => null
|
|
196
|
+
}
|
|
197
|
+
const params = {
|
|
198
|
+
ip: '1.1.1.1',
|
|
199
|
+
statusCode: 200,
|
|
200
|
+
platform: 'APIv5',
|
|
201
|
+
requestPayload: { small: 'data' },
|
|
202
|
+
responsePayload: { items: new Array(2000).fill('x'.repeat(600)) }
|
|
203
|
+
}
|
|
204
|
+
const response = await connector.log(params, req)
|
|
205
|
+
|
|
206
|
+
expect(response).to.have.property('truncatedResponse', true)
|
|
207
|
+
expect(Buffer.byteLength(JSON.stringify(response), 'utf8')).to.be.lessThan(1024000)
|
|
208
|
+
// payload untouched
|
|
209
|
+
expect(response.payload).to.equal(JSON.stringify(params.requestPayload))
|
|
210
|
+
// response valid JSON with shorter array
|
|
211
|
+
expect(() => JSON.parse(response.response)).to.not.throw()
|
|
212
|
+
const parsed = JSON.parse(response.response)
|
|
213
|
+
expect(parsed.items).to.be.an('array')
|
|
214
|
+
expect(parsed.items.length).to.be.lessThan(2000)
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
it('Check obscured password', async() => {
|
|
218
|
+
const req = {
|
|
219
|
+
method: 'post',
|
|
220
|
+
options: {
|
|
221
|
+
controller: 'login',
|
|
222
|
+
action: 'login',
|
|
223
|
+
},
|
|
224
|
+
authInfo: {
|
|
225
|
+
token: 'x-token-123',
|
|
226
|
+
clientId: 'x-client-abc',
|
|
227
|
+
deviceIdentifier: 'x-my-device',
|
|
228
|
+
clientVersion: 'app_11.04.235'
|
|
229
|
+
},
|
|
230
|
+
headers: {
|
|
231
|
+
'user-agent': 'Mozilla',
|
|
232
|
+
},
|
|
233
|
+
allParams: () => {
|
|
234
|
+
return
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
const params = {
|
|
238
|
+
platform: 'AUTHv4',
|
|
239
|
+
requestPayload: { email: 'myuser@admiralcloud.com', password: 'my_good!password@admiracloud' },
|
|
240
|
+
responsePayload: { ok: true }
|
|
241
|
+
}
|
|
242
|
+
const response = await connector.log(params, req)
|
|
243
|
+
const test = {}
|
|
244
|
+
_.map(response, (val, key) => {
|
|
245
|
+
try {
|
|
246
|
+
val = JSON.parse(val)
|
|
247
|
+
}
|
|
248
|
+
catch {
|
|
249
|
+
// do nothing
|
|
250
|
+
}
|
|
251
|
+
_.set(test, key, val)
|
|
252
|
+
})
|
|
253
|
+
expect(test.payload).to.have.property('password', 'XXXX-XXXX')
|
|
254
|
+
})
|
|
255
|
+
})
|