@queue-it/fastly 3.6.0 → 4.4.3-beta.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 +156 -58
- package/package.json +23 -16
- package/src/contextProvider.ts +175 -0
- package/src/fastlyCryptoProvider.ts +8 -0
- package/src/helper.ts +11 -0
- package/{assembly/sdk → src}/helpers/crypto.ts +338 -340
- package/src/index.ts +3 -0
- package/src/integrationConfigProvider.ts +199 -0
- package/src/requestResponseHandler.ts +200 -0
- package/README-INTERNAL.md +0 -21
- package/asconfig.json +0 -17
- package/assembly/__tests__/CustomerIntegrationDecodingHandler.spec.ts +0 -1086
- package/assembly/__tests__/IntegrationConfigHelpersTest.spec.ts +0 -574
- package/assembly/__tests__/KnownUserTest.spec.ts +0 -1894
- package/assembly/__tests__/Mocks.ts +0 -321
- package/assembly/__tests__/QueueParameterHelper.spec.ts +0 -59
- package/assembly/__tests__/UserInQueueService.spec.ts +0 -418
- package/assembly/__tests__/UserInQueueStateCookieRepository.spec.ts +0 -337
- package/assembly/__tests__/as-pect.config.js +0 -57
- package/assembly/__tests__/as-pect.d.ts +0 -1
- package/assembly/contextProvider.ts +0 -123
- package/assembly/helper.ts +0 -23
- package/assembly/index.ts +0 -10
- package/assembly/integrationConfigProvider.ts +0 -32
- package/assembly/requestResponseHandler.ts +0 -92
- package/assembly/sdk/HttpContextProvider.ts +0 -24
- package/assembly/sdk/IntegrationConfig/CustomerIntegrationDecodingHandler.ts +0 -198
- package/assembly/sdk/IntegrationConfig/IntegrationConfigHelpers.ts +0 -232
- package/assembly/sdk/IntegrationConfig/IntegrationConfigModel.ts +0 -93
- package/assembly/sdk/KnownUser.ts +0 -396
- package/assembly/sdk/Models.ts +0 -105
- package/assembly/sdk/QueueITHelpers.ts +0 -263
- package/assembly/sdk/UserInQueueService.ts +0 -245
- package/assembly/sdk/UserInQueueStateCookieRepository.ts +0 -189
- package/assembly/sdk/helpers/Date.ts +0 -194
- package/assembly/sdk/helpers/Uri.ts +0 -308
- package/assembly/tsconfig.json +0 -6
- package/index.js +0 -5
- package/pipelines/ci.yaml +0 -28
|
@@ -1,574 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ComparisonOperatorHelper,
|
|
3
|
-
CookieValidatorHelper, HttpHeaderValidatorHelper, IntegrationEvaluator,
|
|
4
|
-
UrlValidatorHelper, UserAgentValidatorHelper
|
|
5
|
-
} from "../sdk/IntegrationConfig/IntegrationConfigHelpers";
|
|
6
|
-
import {ComparisonOperatorType, TriggerPart, UrlPartType} from "../sdk/IntegrationConfig/IntegrationConfigModel";
|
|
7
|
-
import {CustomerIntegrationDecodingHandler} from "../sdk/IntegrationConfig/CustomerIntegrationDecodingHandler";
|
|
8
|
-
import {MockHttpContextProvider, MockHttpRequest, MockHttpResponse} from "./Mocks";
|
|
9
|
-
|
|
10
|
-
const httpContextMock = new MockHttpContextProvider(new MockHttpRequest(), new MockHttpResponse());
|
|
11
|
-
|
|
12
|
-
function resetMocks(): void {
|
|
13
|
-
httpContextMock.reset();
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
describe('ComparisonOperatorHelper', () => {
|
|
17
|
-
it('should evaluate_equals', () => {
|
|
18
|
-
expect(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.EqualS, false, false, "test1", "test1", null)).toBeTruthy();
|
|
19
|
-
expect(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.EqualS, false, false, "test1", "Test1", null)).toBeFalsy();
|
|
20
|
-
expect(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.EqualS, false, true, "test1", "Test1", null)).toBeTruthy();
|
|
21
|
-
expect(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.EqualS, true, false, "test1", "Test1", null)).toBeTruthy();
|
|
22
|
-
expect(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.EqualS, true, false, "test1", "test1", null)).toBeFalsy();
|
|
23
|
-
expect(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.EqualS, true, true, "test1", "Test1", null)).toBeFalsy();
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('should evaluate_contains', () => {
|
|
27
|
-
expect(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.Contains, false, false, "test_test1_test", "test1", null)).toBeTruthy();
|
|
28
|
-
expect(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.Contains, false, false, "test_test1_test", "Test1", null)).toBeFalsy();
|
|
29
|
-
expect(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.Contains, false, true, "test_test1_test", "Test1", null)).toBeTruthy();
|
|
30
|
-
expect(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.Contains, true, false, "test_test1_test", "Test1", null)).toBeTruthy();
|
|
31
|
-
expect(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.Contains, true, true, "test_test1", "Test1", null)).toBeFalsy();
|
|
32
|
-
expect(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.Contains, true, false, "test_test1", "test1", null)).toBeFalsy();
|
|
33
|
-
expect(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.Contains, false, false, "test_dsdsdsdtest1", "*", null)).toBeTruthy();
|
|
34
|
-
expect(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.Contains, false, false, "", "*", null)).toBeFalsy();
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('should evaluate_equals_any', () => {
|
|
38
|
-
expect(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.EqualsAny, false, false, "test1", '', ["test1"])).toBeTruthy();
|
|
39
|
-
expect(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.EqualsAny, false, false, "test1", '', ["Test1"])).toBeFalsy();
|
|
40
|
-
expect(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.EqualsAny, false, true, "test1", '', ["Test1"])).toBeTruthy();
|
|
41
|
-
expect(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.EqualsAny, true, false, "test1", '', ["Test1"])).toBeTruthy();
|
|
42
|
-
expect(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.EqualsAny, true, false, "test1", '', ["test1"])).toBeFalsy();
|
|
43
|
-
expect(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.EqualsAny, true, true, "test1", '', ["Test1"])).toBeFalsy();
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('should evaluate_contains_any', () => {
|
|
47
|
-
expect(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.ContainsAny, false, false, "test_test1_test", '', ["test1"])).toBeTruthy();
|
|
48
|
-
expect(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.ContainsAny, false, false, "test_test1_test", '', ["Test1"])).toBeFalsy();
|
|
49
|
-
expect(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.ContainsAny, false, true, "test_test1_test", '', ["Test1"])).toBeTruthy();
|
|
50
|
-
expect(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.ContainsAny, true, false, "test_test1_test", '', ["Test1"])).toBeTruthy();
|
|
51
|
-
expect(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.ContainsAny, true, true, "test_test1", '', ["Test1"])).toBeFalsy();
|
|
52
|
-
expect(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.ContainsAny, true, false, "test_test1", '', ["test1"])).toBeFalsy();
|
|
53
|
-
expect(ComparisonOperatorHelper.evaluate(ComparisonOperatorType.ContainsAny, false, false, "test_dsdsdsdtest1", '', ["*"])).toBeTruthy();
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
describe('ValidatorHelpers', () => {
|
|
58
|
-
it('should cookie_evaluate', () => {
|
|
59
|
-
resetMocks();
|
|
60
|
-
|
|
61
|
-
const triggerPart = new TriggerPart();
|
|
62
|
-
triggerPart.CookieName = "c1";
|
|
63
|
-
triggerPart.Operator = ComparisonOperatorType.Contains;
|
|
64
|
-
triggerPart.ValueToCompare = "1";
|
|
65
|
-
|
|
66
|
-
expect(CookieValidatorHelper.evaluate(triggerPart, httpContextMock.req)).toBeFalsy();
|
|
67
|
-
|
|
68
|
-
httpContextMock.req.setCookieValue("c5", "5")
|
|
69
|
-
.setCookieValue("c1", "1")
|
|
70
|
-
.setCookieValue("c2", "test");
|
|
71
|
-
expect(CookieValidatorHelper.evaluate(triggerPart, httpContextMock.req)).toBeTruthy();
|
|
72
|
-
|
|
73
|
-
triggerPart.ValueToCompare = "5";
|
|
74
|
-
expect(CookieValidatorHelper.evaluate(triggerPart, httpContextMock.req)).toBeFalsy();
|
|
75
|
-
|
|
76
|
-
triggerPart.ValueToCompare = "Test";
|
|
77
|
-
triggerPart.IsIgnoreCase = true;
|
|
78
|
-
triggerPart.CookieName = "c2";
|
|
79
|
-
expect(CookieValidatorHelper.evaluate(triggerPart, httpContextMock.req)).toBeTruthy();
|
|
80
|
-
|
|
81
|
-
triggerPart.ValueToCompare = "Test";
|
|
82
|
-
triggerPart.IsIgnoreCase = true;
|
|
83
|
-
triggerPart.IsNegative = true;
|
|
84
|
-
triggerPart.CookieName = "c2";
|
|
85
|
-
expect(CookieValidatorHelper.evaluate(triggerPart, httpContextMock.req)).toBeFalsy();
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('should url_evaluate', () => {
|
|
89
|
-
resetMocks();
|
|
90
|
-
|
|
91
|
-
const triggerPart = new TriggerPart();
|
|
92
|
-
triggerPart.UrlPart = UrlPartType.PageUrl;
|
|
93
|
-
triggerPart.Operator = ComparisonOperatorType.Contains;
|
|
94
|
-
triggerPart.ValueToCompare = "http://test.tesdomain.com:8080/test?q=1";
|
|
95
|
-
|
|
96
|
-
expect(UrlValidatorHelper.evaluate(triggerPart, "http://test.tesdomain.com:8080/test?q=2")).toBeFalsy();
|
|
97
|
-
|
|
98
|
-
triggerPart.ValueToCompare = "/Test/t1";
|
|
99
|
-
triggerPart.UrlPart = UrlPartType.PagePath;
|
|
100
|
-
triggerPart.Operator = ComparisonOperatorType.EqualS;
|
|
101
|
-
triggerPart.IsIgnoreCase = true;
|
|
102
|
-
expect(UrlValidatorHelper.evaluate(triggerPart, "http://test.tesdomain.com:8080/test/t1?q=2&y02")).toBeTruthy();
|
|
103
|
-
|
|
104
|
-
triggerPart.UrlPart = UrlPartType.HostName;
|
|
105
|
-
triggerPart.ValueToCompare = "test.tesdomain.com";
|
|
106
|
-
triggerPart.Operator = ComparisonOperatorType.Contains;
|
|
107
|
-
expect(UrlValidatorHelper.evaluate(triggerPart, "http://m.test.tesdomain.com:8080/test?q=2")).toBeTruthy();
|
|
108
|
-
|
|
109
|
-
triggerPart.UrlPart = UrlPartType.HostName;
|
|
110
|
-
triggerPart.ValueToCompare = "test.tesdomain.com";
|
|
111
|
-
triggerPart.IsNegative = true;
|
|
112
|
-
triggerPart.Operator = ComparisonOperatorType.Contains;
|
|
113
|
-
expect(UrlValidatorHelper.evaluate(triggerPart, "http://m.test.tesdomain.com:8080/test?q=2")).toBeFalsy();
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('should userAgent_evaluate', () => {
|
|
117
|
-
resetMocks();
|
|
118
|
-
|
|
119
|
-
const triggerPart = new TriggerPart();
|
|
120
|
-
triggerPart.Operator = ComparisonOperatorType.Contains;
|
|
121
|
-
triggerPart.ValueToCompare = "googlebot";
|
|
122
|
-
|
|
123
|
-
expect(UserAgentValidatorHelper.evaluate(triggerPart, "Googlebot sample useraagent")).toBeFalsy();
|
|
124
|
-
|
|
125
|
-
triggerPart.ValueToCompare = "googlebot";
|
|
126
|
-
triggerPart.Operator = ComparisonOperatorType.EqualS;
|
|
127
|
-
triggerPart.IsIgnoreCase = true;
|
|
128
|
-
triggerPart.IsNegative = true;
|
|
129
|
-
expect(UserAgentValidatorHelper.evaluate(triggerPart, "oglebot sample useraagent")).toBeTruthy();
|
|
130
|
-
|
|
131
|
-
triggerPart.ValueToCompare = "googlebot";
|
|
132
|
-
triggerPart.Operator = ComparisonOperatorType.Contains;
|
|
133
|
-
triggerPart.IsIgnoreCase = false;
|
|
134
|
-
triggerPart.IsNegative = true;
|
|
135
|
-
expect(UserAgentValidatorHelper.evaluate(triggerPart, "googlebot")).toBeFalsy();
|
|
136
|
-
|
|
137
|
-
triggerPart.ValueToCompare = "googlebot";
|
|
138
|
-
triggerPart.IsIgnoreCase = true;
|
|
139
|
-
triggerPart.IsNegative = false;
|
|
140
|
-
triggerPart.Operator = ComparisonOperatorType.Contains;
|
|
141
|
-
expect(UserAgentValidatorHelper.evaluate(triggerPart, "Googlebot")).toBeTruthy();
|
|
142
|
-
|
|
143
|
-
triggerPart.ValueToCompare = '';
|
|
144
|
-
triggerPart.ValuesToCompare = ["googlebot"];
|
|
145
|
-
triggerPart.IsIgnoreCase = true;
|
|
146
|
-
triggerPart.IsNegative = false;
|
|
147
|
-
triggerPart.Operator = ComparisonOperatorType.ContainsAny;
|
|
148
|
-
expect(UserAgentValidatorHelper.evaluate(triggerPart, "Googlebot")).toBeTruthy();
|
|
149
|
-
|
|
150
|
-
triggerPart.ValuesToCompare = ["googlebot"];
|
|
151
|
-
triggerPart.IsIgnoreCase = true;
|
|
152
|
-
triggerPart.IsNegative = true;
|
|
153
|
-
triggerPart.Operator = ComparisonOperatorType.EqualsAny;
|
|
154
|
-
expect(UserAgentValidatorHelper.evaluate(triggerPart, "oglebot sample useraagent")).toBeTruthy();
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
it('should httpHeader_evaluate', () => {
|
|
158
|
-
resetMocks();
|
|
159
|
-
|
|
160
|
-
const triggerPart = new TriggerPart();
|
|
161
|
-
triggerPart.Operator = ComparisonOperatorType.Contains;
|
|
162
|
-
triggerPart.ValueToCompare = "1";
|
|
163
|
-
|
|
164
|
-
expect(HttpHeaderValidatorHelper.evaluate(triggerPart, "")).toBeFalsy();
|
|
165
|
-
|
|
166
|
-
expect(HttpHeaderValidatorHelper.evaluate(triggerPart, "1")).toBeTruthy();
|
|
167
|
-
|
|
168
|
-
triggerPart.ValueToCompare = "5";
|
|
169
|
-
expect(HttpHeaderValidatorHelper.evaluate(triggerPart, "1")).toBeFalsy();
|
|
170
|
-
|
|
171
|
-
triggerPart.ValueToCompare = "Test";
|
|
172
|
-
triggerPart.IsIgnoreCase = true;
|
|
173
|
-
expect(HttpHeaderValidatorHelper.evaluate(triggerPart, "test")).toBeTruthy();
|
|
174
|
-
|
|
175
|
-
triggerPart.ValueToCompare = "Test";
|
|
176
|
-
triggerPart.IsIgnoreCase = true;
|
|
177
|
-
triggerPart.IsNegative = true;
|
|
178
|
-
expect(HttpHeaderValidatorHelper.evaluate(triggerPart, "test")).toBeFalsy();
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
describe('IntegrationConfigHelpers', () => {
|
|
183
|
-
it('should getMatchedIntegrationConfig_OneTrigger_And_NotMatched', () => {
|
|
184
|
-
resetMocks();
|
|
185
|
-
|
|
186
|
-
const integrationsConfigString = `{
|
|
187
|
-
"Integrations": [{
|
|
188
|
-
"Triggers": [{
|
|
189
|
-
"LogicalOperator":
|
|
190
|
-
"Or",
|
|
191
|
-
"TriggerParts": [{
|
|
192
|
-
"CookieName": "c1",
|
|
193
|
-
"Operator": "Equals",
|
|
194
|
-
"ValueToCompare": "value1",
|
|
195
|
-
"ValidatorType": "CookieValidator"
|
|
196
|
-
},{
|
|
197
|
-
"ValidatorType": "UserAgentValidator",
|
|
198
|
-
"ValueToCompare": "test",
|
|
199
|
-
"Operator": "Contains"
|
|
200
|
-
}]
|
|
201
|
-
}]
|
|
202
|
-
}]
|
|
203
|
-
}`;
|
|
204
|
-
|
|
205
|
-
const integrationConfig = CustomerIntegrationDecodingHandler.deserialize(integrationsConfigString);
|
|
206
|
-
const url = "http://test.tesdomain.com:8080/test?q=2";
|
|
207
|
-
|
|
208
|
-
const testObj = new IntegrationEvaluator();
|
|
209
|
-
const result = testObj.getMatchedIntegrationConfig(integrationConfig, url, httpContextMock.req);
|
|
210
|
-
expect(result).toBeNull();
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
it('should getMatchedIntegrationConfig_OneTrigger_And_Matched', () => {
|
|
214
|
-
resetMocks();
|
|
215
|
-
|
|
216
|
-
httpContextMock.req.setCookieValue("c1", "Value1");
|
|
217
|
-
const integrationsConfigString = `{
|
|
218
|
-
"Integrations": [{
|
|
219
|
-
"Name": "integration1",
|
|
220
|
-
"Triggers": [{
|
|
221
|
-
"LogicalOperator": "And",
|
|
222
|
-
"TriggerParts": [{
|
|
223
|
-
"CookieName": "c1",
|
|
224
|
-
"Operator": "Equals",
|
|
225
|
-
"IsIgnoreCase" : true,
|
|
226
|
-
"ValueToCompare": "value1",
|
|
227
|
-
"ValidatorType": "CookieValidator"
|
|
228
|
-
},{
|
|
229
|
-
"UrlPart": "PageUrl",
|
|
230
|
-
"ValidatorType": "UrlValidator",
|
|
231
|
-
"ValueToCompare": "test",
|
|
232
|
-
"Operator": "Contains"
|
|
233
|
-
}]
|
|
234
|
-
}]
|
|
235
|
-
}]
|
|
236
|
-
}`;
|
|
237
|
-
|
|
238
|
-
const integrationConfig = CustomerIntegrationDecodingHandler.deserialize(integrationsConfigString);
|
|
239
|
-
const url = "http://test.tesdomain.com:8080/test?q=2";
|
|
240
|
-
const result = (new IntegrationEvaluator()).getMatchedIntegrationConfig(integrationConfig, url, httpContextMock.req);
|
|
241
|
-
|
|
242
|
-
expect(result).not.toBeNull();
|
|
243
|
-
expect(result!.first).not.toBeNull();
|
|
244
|
-
expect(result!.first!.Name).toBe('integration1');
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
it('should getMatchedIntegrationConfig_OneTrigger_And_NotMatched_UserAgent', () => {
|
|
248
|
-
resetMocks();
|
|
249
|
-
|
|
250
|
-
httpContextMock.req.setCookieValue("c1", "Value1");
|
|
251
|
-
httpContextMock.req.setUserAgent("bot.html google.com googlebot test")
|
|
252
|
-
|
|
253
|
-
const integrationsConfigString = `{
|
|
254
|
-
"Integrations": [{
|
|
255
|
-
"Name": "integration1",
|
|
256
|
-
"Triggers": [{
|
|
257
|
-
"LogicalOperator": "And",
|
|
258
|
-
"TriggerParts": [{
|
|
259
|
-
"CookieName": "c1",
|
|
260
|
-
"Operator": "Equals",
|
|
261
|
-
"IsIgnoreCase" : true,
|
|
262
|
-
"IsNegative": false,
|
|
263
|
-
"ValueToCompare": "value1",
|
|
264
|
-
"ValidatorType": "CookieValidator"
|
|
265
|
-
},{
|
|
266
|
-
"UrlPart": "PageUrl",
|
|
267
|
-
"ValidatorType": "UrlValidator",
|
|
268
|
-
"ValueToCompare": "test",
|
|
269
|
-
"IsIgnoreCase": false,
|
|
270
|
-
"IsNegative": false,
|
|
271
|
-
"Operator": "Contains"
|
|
272
|
-
},{
|
|
273
|
-
"ValidatorType": "UserAgentValidator",
|
|
274
|
-
"ValueToCompare": "Googlebot",
|
|
275
|
-
"Operator": "Contains",
|
|
276
|
-
"IsIgnoreCase": true,
|
|
277
|
-
"IsNegative": true
|
|
278
|
-
}]
|
|
279
|
-
}]
|
|
280
|
-
}]
|
|
281
|
-
}`;
|
|
282
|
-
|
|
283
|
-
const integrationConfig = CustomerIntegrationDecodingHandler.deserialize(integrationsConfigString);
|
|
284
|
-
const url = "http://test.tesdomain.com:8080/test?q=2";
|
|
285
|
-
const result = (new IntegrationEvaluator()).getMatchedIntegrationConfig(integrationConfig, url, httpContextMock.req);
|
|
286
|
-
|
|
287
|
-
expect(result).toBeNull();
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
it('should getMatchedIntegrationConfig_OneTrigger_And_NotMatched_HttpHeader', () => {
|
|
291
|
-
resetMocks();
|
|
292
|
-
|
|
293
|
-
httpContextMock.req.setCookieValue("c2", "ddd")
|
|
294
|
-
.setCookieValue("c1", "Value1")
|
|
295
|
-
.setHeader("c1", "t1")
|
|
296
|
-
.setHeader("headertest", "abcd efg test gklm");
|
|
297
|
-
const integrationsConfigString = `{
|
|
298
|
-
"Integrations": [{
|
|
299
|
-
"Name":
|
|
300
|
-
"integration1",
|
|
301
|
-
"Triggers": [{
|
|
302
|
-
"LogicalOperator":
|
|
303
|
-
"And",
|
|
304
|
-
"TriggerParts": [{
|
|
305
|
-
"CookieName": "c1",
|
|
306
|
-
"Operator": "Equals",
|
|
307
|
-
"ValueToCompare": "value1",
|
|
308
|
-
"ValidatorType": "CookieValidator",
|
|
309
|
-
"IsIgnoreCase": true,
|
|
310
|
-
"IsNegative": false
|
|
311
|
-
},{
|
|
312
|
-
"UrlPart": "PageUrl",
|
|
313
|
-
"ValidatorType": "UrlValidator",
|
|
314
|
-
"ValueToCompare": "test",
|
|
315
|
-
"Operator": "Contains",
|
|
316
|
-
"IsIgnoreCase": false,
|
|
317
|
-
"IsNegative": false
|
|
318
|
-
},{
|
|
319
|
-
"ValidatorType": "HttpHeaderValidator",
|
|
320
|
-
"ValueToCompare": "test",
|
|
321
|
-
"HttpHeaderName": "HeaderTest",
|
|
322
|
-
"Operator": "Contains",
|
|
323
|
-
"IsIgnoreCase": true,
|
|
324
|
-
"IsNegative": true
|
|
325
|
-
}]
|
|
326
|
-
}]
|
|
327
|
-
}]
|
|
328
|
-
}`;
|
|
329
|
-
|
|
330
|
-
const integrationConfig = CustomerIntegrationDecodingHandler.deserialize(integrationsConfigString);
|
|
331
|
-
const url = "http://www.tesdomain.com:8080/test?q=2";
|
|
332
|
-
|
|
333
|
-
expect((new IntegrationEvaluator()).getMatchedIntegrationConfig(integrationConfig, url, httpContextMock.req) == null).toBeTruthy();
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
it('should getMatchedIntegrationConfig_OneTrigger_And_Matched_RequestBody', () => {
|
|
337
|
-
resetMocks();
|
|
338
|
-
|
|
339
|
-
httpContextMock.req.setCookieValue("c2", "ddd")
|
|
340
|
-
.setCookieValue("c1", "Value1")
|
|
341
|
-
.setHeader("c1", "t1")
|
|
342
|
-
.setHeader("headertest", "abcd efg test gklm")
|
|
343
|
-
.setBody("test body test request");
|
|
344
|
-
|
|
345
|
-
const integrationsConfigString = `{
|
|
346
|
-
"Integrations": [{
|
|
347
|
-
"Name":
|
|
348
|
-
"integration1",
|
|
349
|
-
"Triggers": [{
|
|
350
|
-
"LogicalOperator":
|
|
351
|
-
"And",
|
|
352
|
-
"TriggerParts": [{
|
|
353
|
-
"CookieName": "c1",
|
|
354
|
-
"Operator": "Equals",
|
|
355
|
-
"ValueToCompare": "value1",
|
|
356
|
-
"ValidatorType": "CookieValidator",
|
|
357
|
-
"IsIgnoreCase": true,
|
|
358
|
-
"IsNegative": false
|
|
359
|
-
},{
|
|
360
|
-
"UrlPart": "PageUrl",
|
|
361
|
-
"ValidatorType": "UrlValidator",
|
|
362
|
-
"ValueToCompare": "test",
|
|
363
|
-
"Operator": "Contains",
|
|
364
|
-
"IsIgnoreCase": false,
|
|
365
|
-
"IsNegative": false
|
|
366
|
-
},{
|
|
367
|
-
"ValidatorType": "RequestBodyValidator",
|
|
368
|
-
"ValueToCompare": "test body",
|
|
369
|
-
"Operator": "Contains",
|
|
370
|
-
"IsIgnoreCase": true,
|
|
371
|
-
"IsNegative": false
|
|
372
|
-
}]
|
|
373
|
-
}]
|
|
374
|
-
}]
|
|
375
|
-
}`;
|
|
376
|
-
|
|
377
|
-
const integrationConfig = CustomerIntegrationDecodingHandler.deserialize(integrationsConfigString);
|
|
378
|
-
const url = "http://www.tesdomain.com:8080/test?q=2";
|
|
379
|
-
|
|
380
|
-
const result = (new IntegrationEvaluator()).getMatchedIntegrationConfig(integrationConfig, url, httpContextMock.req);
|
|
381
|
-
expect(result).not.toBeNull();
|
|
382
|
-
expect(result!.first).not.toBeNull();
|
|
383
|
-
expect(result!.first!.Name).toBe('integration1');
|
|
384
|
-
});
|
|
385
|
-
|
|
386
|
-
it('should getMatchedIntegrationConfig_OneTrigger_Or_NotMatched', () => {
|
|
387
|
-
resetMocks();
|
|
388
|
-
|
|
389
|
-
httpContextMock.req.setCookieValue("c2", "Value1");
|
|
390
|
-
const integrationsConfigString = `{
|
|
391
|
-
"Integrations": [{
|
|
392
|
-
"Name":
|
|
393
|
-
"integration1",
|
|
394
|
-
"Triggers": [{
|
|
395
|
-
"LogicalOperator":
|
|
396
|
-
"Or",
|
|
397
|
-
"TriggerParts": [{
|
|
398
|
-
"CookieName": "c1",
|
|
399
|
-
"Operator": "Equals",
|
|
400
|
-
"ValueToCompare": "value1",
|
|
401
|
-
"ValidatorType": "CookieValidator"
|
|
402
|
-
},{
|
|
403
|
-
"UrlPart": "PageUrl",
|
|
404
|
-
"ValidatorType": "UrlValidator",
|
|
405
|
-
"IsIgnoreCase": true,
|
|
406
|
-
"IsNegative": true,
|
|
407
|
-
"ValueToCompare": "test",
|
|
408
|
-
"Operator": "Contains"
|
|
409
|
-
}]
|
|
410
|
-
}]
|
|
411
|
-
}]
|
|
412
|
-
}`;
|
|
413
|
-
|
|
414
|
-
const integrationConfig = CustomerIntegrationDecodingHandler.deserialize(integrationsConfigString);
|
|
415
|
-
const url = "http://test.tesdomain.com:8080/test?q=2";
|
|
416
|
-
const result = (new IntegrationEvaluator()).getMatchedIntegrationConfig(integrationConfig, url, httpContextMock.req);
|
|
417
|
-
|
|
418
|
-
expect(result).toBeNull();
|
|
419
|
-
});
|
|
420
|
-
|
|
421
|
-
it('should getMatchedIntegrationConfig_OneTrigger_Or_Matched', () => {
|
|
422
|
-
resetMocks();
|
|
423
|
-
|
|
424
|
-
httpContextMock.req.setCookieValue("c1", "Value1");
|
|
425
|
-
const integrationsConfigString = `{
|
|
426
|
-
"Integrations": [{
|
|
427
|
-
"Name":
|
|
428
|
-
"integration1",
|
|
429
|
-
"Triggers": [{
|
|
430
|
-
"LogicalOperator":
|
|
431
|
-
"Or",
|
|
432
|
-
"TriggerParts": [{
|
|
433
|
-
"CookieName": "c1",
|
|
434
|
-
"Operator": "Equals",
|
|
435
|
-
"ValueToCompare": "value1",
|
|
436
|
-
"ValidatorType": "CookieValidator"
|
|
437
|
-
},{
|
|
438
|
-
"UrlPart": "PageUrl",
|
|
439
|
-
"ValidatorType": "UrlValidator",
|
|
440
|
-
"ValueToCompare": "test",
|
|
441
|
-
"Operator": "Contains"
|
|
442
|
-
}]
|
|
443
|
-
}]
|
|
444
|
-
}]
|
|
445
|
-
}`;
|
|
446
|
-
|
|
447
|
-
const integrationConfig = CustomerIntegrationDecodingHandler.deserialize(integrationsConfigString);
|
|
448
|
-
const url = "http://test.tesdomain.com:8080/test?q=2";
|
|
449
|
-
const result = (new IntegrationEvaluator()).getMatchedIntegrationConfig(integrationConfig, url, httpContextMock.req);
|
|
450
|
-
|
|
451
|
-
expect(result).not.toBeNull();
|
|
452
|
-
expect(result!.first).not.toBeNull();
|
|
453
|
-
expect(result!.first!.Name == "integration1").toBeTruthy();
|
|
454
|
-
});
|
|
455
|
-
|
|
456
|
-
it('should getMatchedIntegrationConfig_TwoTriggers_Matched', () => {
|
|
457
|
-
resetMocks();
|
|
458
|
-
|
|
459
|
-
httpContextMock.req.setCookieValue("c1", "Value1");
|
|
460
|
-
const integrationsConfigString = `{
|
|
461
|
-
"Integrations": [{
|
|
462
|
-
"Name": "integration1",
|
|
463
|
-
"Triggers": [{
|
|
464
|
-
"LogicalOperator": "And",
|
|
465
|
-
"TriggerParts": [{
|
|
466
|
-
"CookieName": "c1",
|
|
467
|
-
"Operator": "Equals",
|
|
468
|
-
"ValueToCompare": "value1",
|
|
469
|
-
"ValidatorType": "CookieValidator",
|
|
470
|
-
"IsIgnoreCase": true,
|
|
471
|
-
"IsNegative": false
|
|
472
|
-
},{
|
|
473
|
-
"UrlPart": "PageUrl",
|
|
474
|
-
"ValidatorType": "UrlValidator",
|
|
475
|
-
"ValueToCompare": "*",
|
|
476
|
-
"Operator": "Contains"
|
|
477
|
-
}]
|
|
478
|
-
}]
|
|
479
|
-
}]
|
|
480
|
-
}`;
|
|
481
|
-
|
|
482
|
-
const integrationConfig = CustomerIntegrationDecodingHandler.deserialize(integrationsConfigString);
|
|
483
|
-
const url = "http://test.tesdomain.com:8080/test?q=2";
|
|
484
|
-
const result = (new IntegrationEvaluator()).getMatchedIntegrationConfig(integrationConfig, url, httpContextMock.req);
|
|
485
|
-
|
|
486
|
-
expect(result).not.toBeNull();
|
|
487
|
-
expect(result!.first).not.toBeNull();
|
|
488
|
-
expect(result!.first!.Name).toBe('integration1');
|
|
489
|
-
});
|
|
490
|
-
|
|
491
|
-
it('should getMatchedIntegrationConfig_TwoTriggers_NotMatched', () => {
|
|
492
|
-
resetMocks();
|
|
493
|
-
|
|
494
|
-
const integrationsConfigString = `{
|
|
495
|
-
"Integrations": [{
|
|
496
|
-
"Name":
|
|
497
|
-
"integration1",
|
|
498
|
-
"Triggers": [{
|
|
499
|
-
"LogicalOperator":
|
|
500
|
-
"And",
|
|
501
|
-
"TriggerParts": [{
|
|
502
|
-
"CookieName": "c1",
|
|
503
|
-
"Operator": "Equals",
|
|
504
|
-
"ValueToCompare": "value1",
|
|
505
|
-
"ValidatorType": "CookieValidator"
|
|
506
|
-
},{
|
|
507
|
-
"UrlPart": "PageUrl",
|
|
508
|
-
"ValidatorType": "UrlValidator",
|
|
509
|
-
"ValueToCompare": "tesT",
|
|
510
|
-
"Operator": "Contains"
|
|
511
|
-
}]
|
|
512
|
-
}]
|
|
513
|
-
}]
|
|
514
|
-
}`;
|
|
515
|
-
|
|
516
|
-
const integrationConfig = CustomerIntegrationDecodingHandler.deserialize(integrationsConfigString);
|
|
517
|
-
const url = "http://test.tesdomain.com:8080/test?q=2";
|
|
518
|
-
const result = (new IntegrationEvaluator()).getMatchedIntegrationConfig(integrationConfig, url, httpContextMock.req);
|
|
519
|
-
|
|
520
|
-
expect(result).toBeNull();
|
|
521
|
-
});
|
|
522
|
-
|
|
523
|
-
it('should getMatchedIntegrationConfig_ThreeIntegrationsInOrder_SecondMatched', () => {
|
|
524
|
-
resetMocks();
|
|
525
|
-
|
|
526
|
-
httpContextMock.req.setCookieValue("c1", "Value1");
|
|
527
|
-
const integrationsConfigString = `{
|
|
528
|
-
"Integrations": [{
|
|
529
|
-
"Name": "integration0",
|
|
530
|
-
"Triggers": [{
|
|
531
|
-
"LogicalOperator": "And",
|
|
532
|
-
"TriggerParts": [{
|
|
533
|
-
"CookieName": "c1",
|
|
534
|
-
"Operator": "Equals",
|
|
535
|
-
"ValueToCompare": "value1",
|
|
536
|
-
"ValidatorType": "CookieValidator"
|
|
537
|
-
}]
|
|
538
|
-
}]
|
|
539
|
-
}],
|
|
540
|
-
"Integrations": [{
|
|
541
|
-
"Name": "integration1",
|
|
542
|
-
"Triggers": [{
|
|
543
|
-
"LogicalOperator": "And",
|
|
544
|
-
"TriggerParts": [{
|
|
545
|
-
"CookieName": "c1",
|
|
546
|
-
"Operator": "Equals",
|
|
547
|
-
"ValueToCompare": "value1",
|
|
548
|
-
"ValidatorType": "CookieValidator"
|
|
549
|
-
}]
|
|
550
|
-
}]
|
|
551
|
-
}],
|
|
552
|
-
"Integrations": [{
|
|
553
|
-
"Name": "integration2",
|
|
554
|
-
"Triggers": [{
|
|
555
|
-
"LogicalOperator": "And",
|
|
556
|
-
"TriggerParts": [{
|
|
557
|
-
"UrlPart": "PageUrl",
|
|
558
|
-
"Operator": "Contains",
|
|
559
|
-
"ValueToCompare": "test",
|
|
560
|
-
"ValidatorType": "UrlValidator"
|
|
561
|
-
}]
|
|
562
|
-
}]
|
|
563
|
-
}]
|
|
564
|
-
}`;
|
|
565
|
-
|
|
566
|
-
const integrationConfig = CustomerIntegrationDecodingHandler.deserialize(integrationsConfigString);
|
|
567
|
-
const url = "http://test.tesdomain.com:8080/test?q=2";
|
|
568
|
-
const result = (new IntegrationEvaluator()).getMatchedIntegrationConfig(integrationConfig, url, httpContextMock.req)
|
|
569
|
-
|
|
570
|
-
expect(result).not.toBeNull();
|
|
571
|
-
expect(result!.first).not.toBeNull();
|
|
572
|
-
expect(result!.first!.Name == "integration2").toBeTruthy();
|
|
573
|
-
});
|
|
574
|
-
});
|