@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,1894 +0,0 @@
|
|
|
1
|
-
import {QueueParameterHelper, Utils} from "../sdk/QueueITHelpers";
|
|
2
|
-
import {UserInQueueService} from "../sdk/UserInQueueService";
|
|
3
|
-
import {CancelEventConfig, QueueEventConfig, RequestValidationResult} from "../sdk/Models";
|
|
4
|
-
import {
|
|
5
|
-
MockDateTimeProvider,
|
|
6
|
-
MockHttpContextProvider,
|
|
7
|
-
MockHttpRequest, MockHttpResponse,
|
|
8
|
-
UserInQueueServiceMock,
|
|
9
|
-
UserInQueueStateCookieRepositoryMock, ValidateQueueRequestCall
|
|
10
|
-
} from "./Mocks";
|
|
11
|
-
import {hmacString} from '../sdk/helpers/crypto'
|
|
12
|
-
import {KnownUser} from '../sdk/KnownUser';
|
|
13
|
-
import { toISOString } from "../sdk/helpers/Date";
|
|
14
|
-
|
|
15
|
-
Utils.generateSHA256Hash = hmacString;
|
|
16
|
-
|
|
17
|
-
const SDK_VERSION = UserInQueueService.SDK_VERSION;
|
|
18
|
-
const userInQueueServiceMock = new UserInQueueServiceMock(new UserInQueueStateCookieRepositoryMock());
|
|
19
|
-
const httpContextMock = new MockHttpContextProvider(new MockHttpRequest(), new MockHttpResponse());
|
|
20
|
-
|
|
21
|
-
function resetMocks(): void {
|
|
22
|
-
userInQueueServiceMock.reset();
|
|
23
|
-
httpContextMock.reset();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function generateDebugToken(eventId: string, secretKey: string, expiredToken: bool = false): string {
|
|
27
|
-
let timeStamp = Utils.getCurrentTime() + 3 * 60;
|
|
28
|
-
|
|
29
|
-
if (expiredToken) {
|
|
30
|
-
timeStamp = timeStamp - 1000;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const tokenWithoutHash: string =
|
|
34
|
-
QueueParameterHelper.EventIdKey +
|
|
35
|
-
QueueParameterHelper.KeyValueSeparatorChar +
|
|
36
|
-
eventId +
|
|
37
|
-
QueueParameterHelper.KeyValueSeparatorGroupChar +
|
|
38
|
-
QueueParameterHelper.RedirectTypeKey +
|
|
39
|
-
QueueParameterHelper.KeyValueSeparatorChar +
|
|
40
|
-
"debug" +
|
|
41
|
-
QueueParameterHelper.KeyValueSeparatorGroupChar +
|
|
42
|
-
QueueParameterHelper.TimeStampKey +
|
|
43
|
-
QueueParameterHelper.KeyValueSeparatorChar +
|
|
44
|
-
timeStamp.toString();
|
|
45
|
-
|
|
46
|
-
const hashValue = Utils.generateSHA256Hash(secretKey, tokenWithoutHash);
|
|
47
|
-
|
|
48
|
-
return tokenWithoutHash +
|
|
49
|
-
QueueParameterHelper.KeyValueSeparatorGroupChar +
|
|
50
|
-
QueueParameterHelper.HashKey +
|
|
51
|
-
QueueParameterHelper.KeyValueSeparatorChar +
|
|
52
|
-
hashValue;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function mockGoogleHeaders(): void {
|
|
56
|
-
httpContextMock.req.headers.set('user-agent', 'googlebot');
|
|
57
|
-
httpContextMock.req.headers.set('via', 'v');
|
|
58
|
-
httpContextMock.req.headers.set('forwarded', 'f');
|
|
59
|
-
httpContextMock.req.headers.set('x-forwarded-for', 'xff');
|
|
60
|
-
httpContextMock.req.headers.set('x-forwarded-host', 'xfh');
|
|
61
|
-
httpContextMock.req.headers.set('x-forwarded-proto', 'xfp');
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
describe('extendQueueCookie', () => {
|
|
65
|
-
it('should handle NullEventId', () => {
|
|
66
|
-
//Arrange
|
|
67
|
-
resetMocks();
|
|
68
|
-
|
|
69
|
-
//Act
|
|
70
|
-
const err = KnownUser.extendQueueCookie("", 0, "", "", httpContextMock);
|
|
71
|
-
const exceptionWasThrown = err != null && err.message == "eventId can not be null or empty.";
|
|
72
|
-
|
|
73
|
-
//Assert
|
|
74
|
-
expect(userInQueueServiceMock.extendQueueCookieCall).toBeNull();
|
|
75
|
-
expect(exceptionWasThrown).toBeTruthy('error should be returned');
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('should handle InvalidCookieValidityMinutes', () => {
|
|
79
|
-
//Arrange
|
|
80
|
-
resetMocks();
|
|
81
|
-
|
|
82
|
-
//Act
|
|
83
|
-
const err = KnownUser.extendQueueCookie("eventId", -1, "cookiedomain", "secretkey", httpContextMock);
|
|
84
|
-
const exceptionWasThrown = err != null && err.message == "cookieValidityMinute should be integer greater than 0.";
|
|
85
|
-
|
|
86
|
-
//Assert
|
|
87
|
-
expect(userInQueueServiceMock.extendQueueCookieCall).toBeNull();
|
|
88
|
-
expect(exceptionWasThrown).toBeTruthy('error should be returned');
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('should handle NullSecretKey', () => {
|
|
92
|
-
//Arrange
|
|
93
|
-
resetMocks();
|
|
94
|
-
|
|
95
|
-
//Act
|
|
96
|
-
const err = KnownUser.extendQueueCookie("eventId", 20, "cookiedomain", '', httpContextMock);
|
|
97
|
-
const exceptionWasThrown = err != null && err.message == "secretKey can not be null or empty.";
|
|
98
|
-
|
|
99
|
-
//Assert
|
|
100
|
-
expect(userInQueueServiceMock.extendQueueCookieCall).toBeNull();
|
|
101
|
-
expect(exceptionWasThrown).toBeTruthy('error should be returned');
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('Should extend', () => {
|
|
105
|
-
//Arrange
|
|
106
|
-
resetMocks();
|
|
107
|
-
|
|
108
|
-
//Act
|
|
109
|
-
KnownUser.UserInQueueService = userInQueueServiceMock;
|
|
110
|
-
const result = KnownUser.extendQueueCookie("eventId", 20, "cookiedomain", "secretKey", httpContextMock);
|
|
111
|
-
|
|
112
|
-
//Assert
|
|
113
|
-
expect(result).toBeNull();
|
|
114
|
-
expect(userInQueueServiceMock.extendQueueCookieCall).not.toBeNull();
|
|
115
|
-
expect(userInQueueServiceMock.extendQueueCookieCall!.method).toBe('extendQueueCookie');
|
|
116
|
-
expect(userInQueueServiceMock.extendQueueCookieCall!.eventId).toBe('eventId');
|
|
117
|
-
expect(userInQueueServiceMock.extendQueueCookieCall!.cookieValidityMinute).toBe(20);
|
|
118
|
-
expect(userInQueueServiceMock.extendQueueCookieCall!.secretKey).toBe('secretKey');
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
function getGoogleBotExampleIntegrationConfig(): string {
|
|
123
|
-
const integrationConfigString = `{
|
|
124
|
-
"Description": "test",
|
|
125
|
-
"Integrations": [
|
|
126
|
-
{
|
|
127
|
-
"Name": "event1action",
|
|
128
|
-
"ActionType": "Queue",
|
|
129
|
-
"EventId": "event1",
|
|
130
|
-
"CookieDomain": ".test.com",
|
|
131
|
-
"LayoutName": "Christmas Layout by Queue-it",
|
|
132
|
-
"Culture": "",
|
|
133
|
-
"ExtendCookieValidity": true,
|
|
134
|
-
"CookieValidityMinute": 20,
|
|
135
|
-
"Triggers": [
|
|
136
|
-
{
|
|
137
|
-
"TriggerParts": [
|
|
138
|
-
{
|
|
139
|
-
"Operator": "Contains",
|
|
140
|
-
"ValueToCompare": "event1",
|
|
141
|
-
"UrlPart": "PageUrl",
|
|
142
|
-
"ValidatorType": "UrlValidator",
|
|
143
|
-
"IsNegative": false,
|
|
144
|
-
"IsIgnoreCase": true
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
"Operator": "Contains",
|
|
148
|
-
"ValueToCompare": "googlebot",
|
|
149
|
-
"ValidatorType": "UserAgentValidator",
|
|
150
|
-
"IsNegative": false,
|
|
151
|
-
"IsIgnoreCase": false
|
|
152
|
-
}
|
|
153
|
-
],
|
|
154
|
-
"LogicalOperator": "And"
|
|
155
|
-
}
|
|
156
|
-
],
|
|
157
|
-
"QueueDomain": "knownusertest.queue-it.net",
|
|
158
|
-
"RedirectLogic": "AllowTParameter",
|
|
159
|
-
"ForcedTargetUrl": ""
|
|
160
|
-
}
|
|
161
|
-
],
|
|
162
|
-
"CustomerId": "knownusertest",
|
|
163
|
-
"AccountId": "knownusertest",
|
|
164
|
-
"Version": 3,
|
|
165
|
-
"PublishDate": "2017-05-15T21:39:12.0076806Z",
|
|
166
|
-
"ConfigDataVersion": "1.0.0.1"
|
|
167
|
-
}`;
|
|
168
|
-
return integrationConfigString;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
describe('validateRequestByIntegrationConfig', () => {
|
|
172
|
-
|
|
173
|
-
it('should handle googlebot', () => {
|
|
174
|
-
resetMocks();
|
|
175
|
-
userInQueueServiceMock.validateQueueRequestResult = new RequestValidationResult("Queue", "eventidX", "", "http://q.qeuue-it.com", "");
|
|
176
|
-
|
|
177
|
-
httpContextMock.req.headers.set('user-agent', 'googlebot');
|
|
178
|
-
|
|
179
|
-
const result = KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true",
|
|
180
|
-
"queueIttoken",
|
|
181
|
-
getGoogleBotExampleIntegrationConfig(),
|
|
182
|
-
"customerid",
|
|
183
|
-
"secretkey",
|
|
184
|
-
httpContextMock);
|
|
185
|
-
|
|
186
|
-
expect(result.first).not.toBeNull();
|
|
187
|
-
expect(result.first!.isAjaxResult).toBeFalsy('isAjaxResult should be false');
|
|
188
|
-
expect(result.second).toBeNull();
|
|
189
|
-
expect(result.first!.eventId).toBe("eventidX");
|
|
190
|
-
expect(userInQueueServiceMock.validateQueueRequestCall).not.toBeNull()
|
|
191
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.method).toBe("validateQueueRequest");
|
|
192
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.targetUrl).toBe("http://test.com?event1=true");
|
|
193
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.queueitToken).toBe("queueIttoken");
|
|
194
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.queueConfig.queueDomain).toBe("knownusertest.queue-it.net");
|
|
195
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.queueConfig.eventId).toBe("event1");
|
|
196
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.queueConfig.culture).toBe("");
|
|
197
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.queueConfig.layoutName).toBe("Christmas Layout by Queue-it");
|
|
198
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.queueConfig.extendCookieValidity).toBeTruthy('cookie should be extended');
|
|
199
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.queueConfig.cookieValidityMinute).toBe(20);
|
|
200
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.queueConfig.cookieDomain).toBe(".test.com");
|
|
201
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.queueConfig.version).toBe(3);
|
|
202
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.customerId).toBe('customerid');
|
|
203
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.secretKey).toBe('secretkey');
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
it('should handle AjaxCall', () => {
|
|
207
|
-
resetMocks();
|
|
208
|
-
userInQueueServiceMock.validateQueueRequestResult = new RequestValidationResult("Queue", "eventid", "", "http://q.qeuue-it.com", "");
|
|
209
|
-
|
|
210
|
-
httpContextMock.req.headers.set('x-queueit-ajaxpageurl', 'http%3a%2f%2ftest.com%3fevent1%3dtrue');
|
|
211
|
-
httpContextMock.req.headers.set('user-agent', 'googlebot');
|
|
212
|
-
httpContextMock.req.headers.set('a', 'b');
|
|
213
|
-
httpContextMock.req.headers.set('e', 'f');
|
|
214
|
-
|
|
215
|
-
const integrationConfigString = `{
|
|
216
|
-
"Description": "test",
|
|
217
|
-
"Integrations": [
|
|
218
|
-
{
|
|
219
|
-
"Name": "event1action",
|
|
220
|
-
"ActionType": "Queue",
|
|
221
|
-
"EventId": "event1",
|
|
222
|
-
"CookieDomain": ".test.com",
|
|
223
|
-
"LayoutName": "Christmas Layout by Queue-it",
|
|
224
|
-
"Culture": "",
|
|
225
|
-
"ExtendCookieValidity": true,
|
|
226
|
-
"CookieValidityMinute": 20,
|
|
227
|
-
"Triggers": [
|
|
228
|
-
{
|
|
229
|
-
"TriggerParts": [
|
|
230
|
-
{
|
|
231
|
-
"Operator": "Contains",
|
|
232
|
-
"ValueToCompare": "event1",
|
|
233
|
-
"UrlPart": "PageUrl",
|
|
234
|
-
"ValidatorType": "UrlValidator",
|
|
235
|
-
"IsNegative": false,
|
|
236
|
-
"IsIgnoreCase": true
|
|
237
|
-
},
|
|
238
|
-
{
|
|
239
|
-
"Operator": "Contains",
|
|
240
|
-
"ValueToCompare": "googlebot",
|
|
241
|
-
"ValidatorType": "UserAgentValidator",
|
|
242
|
-
"IsNegative": false,
|
|
243
|
-
"IsIgnoreCase": false
|
|
244
|
-
}
|
|
245
|
-
],
|
|
246
|
-
"LogicalOperator": "And"
|
|
247
|
-
}
|
|
248
|
-
],
|
|
249
|
-
"QueueDomain": "knownusertest.queue-it.net",
|
|
250
|
-
"RedirectLogic": "AllowTParameter",
|
|
251
|
-
"ForcedTargetUrl": ""
|
|
252
|
-
}
|
|
253
|
-
],
|
|
254
|
-
"CustomerId": "knownusertest",
|
|
255
|
-
"AccountId": "knownusertest",
|
|
256
|
-
"Version": 3,
|
|
257
|
-
"PublishDate": "2017-05-15T21:39:12.0076806Z",
|
|
258
|
-
"ConfigDataVersion": "1.0.0.1"
|
|
259
|
-
}`;
|
|
260
|
-
|
|
261
|
-
const result = KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true", "queueIttoken", integrationConfigString, "customerid", "secretkey", httpContextMock);
|
|
262
|
-
|
|
263
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.method).toBe('validateQueueRequest');
|
|
264
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.targetUrl).toBe('http://test.com?event1=true');
|
|
265
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.queueitToken).toBe('queueIttoken');
|
|
266
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.queueConfig.queueDomain).toBe('knownusertest.queue-it.net');
|
|
267
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.queueConfig.eventId).toBe('event1');
|
|
268
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.queueConfig.culture).toBe('');
|
|
269
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.queueConfig.layoutName).toBe('Christmas Layout by Queue-it');
|
|
270
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.queueConfig.extendCookieValidity).toBeTruthy('cookie should be extended');
|
|
271
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.queueConfig.cookieValidityMinute).toBe(20);
|
|
272
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.queueConfig.cookieDomain).toBe('.test.com');
|
|
273
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.queueConfig.version).toBe(3);
|
|
274
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.customerId).toBe('customerid');
|
|
275
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.secretKey).toBe('secretkey');
|
|
276
|
-
expect(result.first!.isAjaxResult).toBeTruthy();
|
|
277
|
-
expect(result.first!.getAjaxRedirectUrl().toLowerCase()).toBe("http%3a%2f%2fq.qeuue-it.com");
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
it('should handle NotMatch', () => {
|
|
281
|
-
resetMocks();
|
|
282
|
-
|
|
283
|
-
const integrationConfigString = `{
|
|
284
|
-
"Description": "test",
|
|
285
|
-
"Integrations": [
|
|
286
|
-
],
|
|
287
|
-
"CustomerId": "knownusertest",
|
|
288
|
-
"AccountId": "knownusertest",
|
|
289
|
-
"Version": 3,
|
|
290
|
-
"PublishDate": "2017-05-15T21:39:12.0076806Z",
|
|
291
|
-
"ConfigDataVersion": "1.0.0.1"
|
|
292
|
-
}`;
|
|
293
|
-
|
|
294
|
-
const result = KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true", "queueIttoken", integrationConfigString, "customerid", "secretkey", httpContextMock);
|
|
295
|
-
|
|
296
|
-
expect(userInQueueServiceMock.validateQueueRequestCall).toBeNull();
|
|
297
|
-
expect(result.first!.doRedirect()).toBeFalsy('should not redirect');
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
it('should EmptyCurrentUrl', () => {
|
|
301
|
-
//Arrange
|
|
302
|
-
resetMocks();
|
|
303
|
-
|
|
304
|
-
const integrationConfigString = `{
|
|
305
|
-
"Description": "test",
|
|
306
|
-
"Integrations": [
|
|
307
|
-
{
|
|
308
|
-
"Name": "event1action",
|
|
309
|
-
"ActionType": "Queue",
|
|
310
|
-
"EventId": "event1",
|
|
311
|
-
"CookieDomain": ".test.com",
|
|
312
|
-
"LayoutName": "Christmas Layout by Queue-it",
|
|
313
|
-
"Culture": "",
|
|
314
|
-
"ExtendCookieValidity": true,
|
|
315
|
-
"CookieValidityMinute": 20,
|
|
316
|
-
"Triggers": [
|
|
317
|
-
{
|
|
318
|
-
"TriggerParts": [
|
|
319
|
-
{
|
|
320
|
-
"Operator": "Contains",
|
|
321
|
-
"ValueToCompare": "event1",
|
|
322
|
-
"UrlPart": "PageUrl",
|
|
323
|
-
"ValidatorType": "UrlValidator",
|
|
324
|
-
"IsNegative": false,
|
|
325
|
-
"IsIgnoreCase": true
|
|
326
|
-
},
|
|
327
|
-
{
|
|
328
|
-
"Operator": "Contains",
|
|
329
|
-
"ValueToCompare": "googlebot",
|
|
330
|
-
"ValidatorType": "UserAgentValidator",
|
|
331
|
-
"IsNegative": false,
|
|
332
|
-
"IsIgnoreCase": false
|
|
333
|
-
}
|
|
334
|
-
],
|
|
335
|
-
"LogicalOperator": "And"
|
|
336
|
-
}
|
|
337
|
-
],
|
|
338
|
-
"QueueDomain": "knownusertest.queue-it.net",
|
|
339
|
-
"RedirectLogic": "AllowTParameter",
|
|
340
|
-
"ForcedTargetUrl": ""
|
|
341
|
-
}
|
|
342
|
-
],
|
|
343
|
-
"CustomerId": "knownusertest",
|
|
344
|
-
"AccountId": "knownusertest",
|
|
345
|
-
"Version": 3,
|
|
346
|
-
"PublishDate": "2017-05-15T21:39:12.0076806Z",
|
|
347
|
-
"ConfigDataVersion": "1.0.0.1"
|
|
348
|
-
}`;
|
|
349
|
-
|
|
350
|
-
//Act
|
|
351
|
-
const result = KnownUser.validateRequestByIntegrationConfig('', "queueIttoken", integrationConfigString, "customerId", "secretKey", httpContextMock);
|
|
352
|
-
const exceptionWasThrown = result.second != null && result.second!.message == "currentUrlWithoutQueueITToken can not be null or empty.";
|
|
353
|
-
|
|
354
|
-
//Assert
|
|
355
|
-
expect(userInQueueServiceMock.validateQueueRequestCall).toBeNull('validate queue request should not be called');
|
|
356
|
-
expect(exceptionWasThrown).toBeTruthy('exception should be returned');
|
|
357
|
-
});
|
|
358
|
-
|
|
359
|
-
it('should not be called if integration config is empty', () => {
|
|
360
|
-
//Arrange
|
|
361
|
-
resetMocks();
|
|
362
|
-
|
|
363
|
-
//Act
|
|
364
|
-
let result = KnownUser.validateRequestByIntegrationConfig("currentUrl", "queueitToken", '', "customerId", "secretKey", httpContextMock);
|
|
365
|
-
const exceptionWasThrown = result.second != null && result.second!.message == "integrationsConfigString can not be null or empty.";
|
|
366
|
-
|
|
367
|
-
//Assert
|
|
368
|
-
expect(userInQueueServiceMock.validateQueueRequestCall).toBeNull('validate queue request should not be called');
|
|
369
|
-
expect(exceptionWasThrown).toBeTruthy('exception should be returned');
|
|
370
|
-
});
|
|
371
|
-
|
|
372
|
-
it('should ForcedTargetUrl', () => {
|
|
373
|
-
resetMocks();
|
|
374
|
-
userInQueueServiceMock.validateQueueRequestResult = new RequestValidationResult("Queue", "eventid", "", "http://q.qeuue-it.com", "");
|
|
375
|
-
|
|
376
|
-
const integrationConfigString = `{
|
|
377
|
-
"Description": "test",
|
|
378
|
-
"Integrations": [
|
|
379
|
-
{
|
|
380
|
-
"Name": "event1action",
|
|
381
|
-
"ActionType": "Queue",
|
|
382
|
-
"EventId": "event1",
|
|
383
|
-
"CookieDomain": ".test.com",
|
|
384
|
-
"LayoutName": "Christmas Layout by Queue-it",
|
|
385
|
-
"Culture": "",
|
|
386
|
-
"ExtendCookieValidity": true,
|
|
387
|
-
"CookieValidityMinute": 20,
|
|
388
|
-
"Triggers": [
|
|
389
|
-
{
|
|
390
|
-
"TriggerParts": [
|
|
391
|
-
{
|
|
392
|
-
"Operator": "Contains",
|
|
393
|
-
"ValueToCompare": "event1",
|
|
394
|
-
"UrlPart": "PageUrl",
|
|
395
|
-
"ValidatorType": "UrlValidator",
|
|
396
|
-
"IsNegative": false,
|
|
397
|
-
"IsIgnoreCase": true
|
|
398
|
-
}
|
|
399
|
-
],
|
|
400
|
-
"LogicalOperator": "And"
|
|
401
|
-
}
|
|
402
|
-
],
|
|
403
|
-
"QueueDomain": "knownusertest.queue-it.net",
|
|
404
|
-
"RedirectLogic": "ForcedTargetUrl",
|
|
405
|
-
"ForcedTargetUrl": "http://test.com"
|
|
406
|
-
}
|
|
407
|
-
],
|
|
408
|
-
"CustomerId": "knownusertest",
|
|
409
|
-
"AccountId": "knownusertest",
|
|
410
|
-
"Version": 3,
|
|
411
|
-
"PublishDate": "2017-05-15T21:39:12.0076806Z",
|
|
412
|
-
"ConfigDataVersion": "1.0.0.1"
|
|
413
|
-
}`;
|
|
414
|
-
|
|
415
|
-
KnownUser.UserInQueueService = userInQueueServiceMock;
|
|
416
|
-
const result = KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true", "queueIttoken", integrationConfigString, "customerid", "secretkey", httpContextMock);
|
|
417
|
-
|
|
418
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.method == "validateQueueRequest");
|
|
419
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.targetUrl == "http://test.com");
|
|
420
|
-
});
|
|
421
|
-
|
|
422
|
-
it('should ForcedTargetUrl_AjaxCall', () => {
|
|
423
|
-
resetMocks();
|
|
424
|
-
userInQueueServiceMock.validateQueueRequestResult = new RequestValidationResult("Queue", "eventid", "", "http://q.qeuue-it.com", "");
|
|
425
|
-
|
|
426
|
-
httpContextMock.req.headers.set('x-queueit-ajaxpageurl', 'http%3a%2f%2ftest.com%3fevent1%3dtrue');
|
|
427
|
-
httpContextMock.req.headers.set('a', 'b');
|
|
428
|
-
httpContextMock.req.headers.set('e', 'f');
|
|
429
|
-
|
|
430
|
-
const integrationConfigString = `{
|
|
431
|
-
"Description": "test",
|
|
432
|
-
"Integrations": [
|
|
433
|
-
{
|
|
434
|
-
"Name": "event1action",
|
|
435
|
-
"ActionType": "Queue",
|
|
436
|
-
"EventId": "event1",
|
|
437
|
-
"CookieDomain": ".test.com",
|
|
438
|
-
"LayoutName": "Christmas Layout by Queue-it",
|
|
439
|
-
"Culture": "",
|
|
440
|
-
"ExtendCookieValidity": true,
|
|
441
|
-
"CookieValidityMinute": 20,
|
|
442
|
-
"Triggers": [
|
|
443
|
-
{
|
|
444
|
-
"TriggerParts": [
|
|
445
|
-
{
|
|
446
|
-
"Operator": "Contains",
|
|
447
|
-
"ValueToCompare": "event1",
|
|
448
|
-
"UrlPart": "PageUrl",
|
|
449
|
-
"ValidatorType": "UrlValidator",
|
|
450
|
-
"IsNegative": false,
|
|
451
|
-
"IsIgnoreCase": true
|
|
452
|
-
}
|
|
453
|
-
],
|
|
454
|
-
"LogicalOperator": "And"
|
|
455
|
-
}
|
|
456
|
-
],
|
|
457
|
-
"QueueDomain": "knownusertest.queue-it.net",
|
|
458
|
-
"RedirectLogic": "ForcedTargetUrl",
|
|
459
|
-
"ForcedTargetUrl": "http://test.com"
|
|
460
|
-
}
|
|
461
|
-
],
|
|
462
|
-
"CustomerId": "knownusertest",
|
|
463
|
-
"AccountId": "knownusertest",
|
|
464
|
-
"Version": 3,
|
|
465
|
-
"PublishDate": "2017-05-15T21:39:12.0076806Z",
|
|
466
|
-
"ConfigDataVersion": "1.0.0.1"
|
|
467
|
-
}`;
|
|
468
|
-
|
|
469
|
-
KnownUser.UserInQueueService = userInQueueServiceMock;
|
|
470
|
-
const result = KnownUser.validateRequestByIntegrationConfig("http://test.com?event1", "queueIttoken", integrationConfigString, "customerid", "secretkey", httpContextMock);
|
|
471
|
-
|
|
472
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.method).toBe('validateQueueRequest');
|
|
473
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.targetUrl).toBe('http://test.com');
|
|
474
|
-
expect(result.first!.isAjaxResult).toBeTruthy();
|
|
475
|
-
});
|
|
476
|
-
|
|
477
|
-
it('should EventTargetUrl', () => {
|
|
478
|
-
resetMocks();
|
|
479
|
-
userInQueueServiceMock.validateQueueRequestResult = new RequestValidationResult("Queue", "eventid", "", "http://q.qeuue-it.com", "");
|
|
480
|
-
|
|
481
|
-
const integrationConfigString = `{
|
|
482
|
-
"Description": "test",
|
|
483
|
-
"Integrations": [
|
|
484
|
-
{
|
|
485
|
-
"Name": "event1action",
|
|
486
|
-
"ActionType": "Queue",
|
|
487
|
-
"EventId": "event1",
|
|
488
|
-
"CookieDomain": ".test.com",
|
|
489
|
-
"LayoutName": "Christmas Layout by Queue-it",
|
|
490
|
-
"Culture": "",
|
|
491
|
-
"ExtendCookieValidity": true,
|
|
492
|
-
"CookieValidityMinute": 20,
|
|
493
|
-
"Triggers": [
|
|
494
|
-
{
|
|
495
|
-
"TriggerParts": [
|
|
496
|
-
{
|
|
497
|
-
"Operator": "Contains",
|
|
498
|
-
"ValueToCompare": "event1",
|
|
499
|
-
"UrlPart": "PageUrl",
|
|
500
|
-
"ValidatorType": "UrlValidator",
|
|
501
|
-
"IsNegative": false,
|
|
502
|
-
"IsIgnoreCase": true
|
|
503
|
-
}
|
|
504
|
-
],
|
|
505
|
-
"LogicalOperator": "And"
|
|
506
|
-
}
|
|
507
|
-
],
|
|
508
|
-
"QueueDomain": "knownusertest.queue-it.net",
|
|
509
|
-
"RedirectLogic": "EventTargetUrl"
|
|
510
|
-
}
|
|
511
|
-
],
|
|
512
|
-
"CustomerId": "knownusertest",
|
|
513
|
-
"AccountId": "knownusertest",
|
|
514
|
-
"Version": 3,
|
|
515
|
-
"PublishDate": "2017-05-15T21:39:12.0076806Z",
|
|
516
|
-
"ConfigDataVersion": "1.0.0.1"
|
|
517
|
-
}`;
|
|
518
|
-
|
|
519
|
-
KnownUser.UserInQueueService = userInQueueServiceMock;
|
|
520
|
-
const result = KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true", "queueIttoken", integrationConfigString, "customerid", "secretkey", httpContextMock);
|
|
521
|
-
|
|
522
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.method).toBe('validateQueueRequest');
|
|
523
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.targetUrl).toBe('');
|
|
524
|
-
});
|
|
525
|
-
|
|
526
|
-
it('should EventTargetUrl_AjaxCall', () => {
|
|
527
|
-
resetMocks();
|
|
528
|
-
userInQueueServiceMock.validateQueueRequestResult = new RequestValidationResult("Queue", "eventid", "", "http://q.qeuue-it.com", "");
|
|
529
|
-
|
|
530
|
-
httpContextMock.req.headers.set('a', 'b');
|
|
531
|
-
httpContextMock.req.headers.set('x-queueit-ajaxpageurl', 'http%3a%2f%2ftest.com%3fevent1%3dtrue');
|
|
532
|
-
httpContextMock.req.headers.set('e', 'f');
|
|
533
|
-
|
|
534
|
-
const integrationConfigString = `{
|
|
535
|
-
"Description": "test",
|
|
536
|
-
"Integrations": [
|
|
537
|
-
{
|
|
538
|
-
"Name": "event1action",
|
|
539
|
-
"ActionType": "Queue",
|
|
540
|
-
"EventId": "event1",
|
|
541
|
-
"CookieDomain": ".test.com",
|
|
542
|
-
"LayoutName": "Christmas Layout by Queue-it",
|
|
543
|
-
"Culture": "",
|
|
544
|
-
"ExtendCookieValidity": true,
|
|
545
|
-
"CookieValidityMinute": 20,
|
|
546
|
-
"Triggers": [
|
|
547
|
-
{
|
|
548
|
-
"TriggerParts": [
|
|
549
|
-
{
|
|
550
|
-
"Operator": "Contains",
|
|
551
|
-
"ValueToCompare": "event1",
|
|
552
|
-
"UrlPart": "PageUrl",
|
|
553
|
-
"ValidatorType": "UrlValidator",
|
|
554
|
-
"IsNegative": false,
|
|
555
|
-
"IsIgnoreCase": true
|
|
556
|
-
}
|
|
557
|
-
],
|
|
558
|
-
"LogicalOperator": "And"
|
|
559
|
-
}
|
|
560
|
-
],
|
|
561
|
-
"QueueDomain": "knownusertest.queue-it.net",
|
|
562
|
-
"RedirectLogic": "EventTargetUrl"
|
|
563
|
-
}
|
|
564
|
-
],
|
|
565
|
-
"CustomerId": "knownusertest",
|
|
566
|
-
"AccountId": "knownusertest",
|
|
567
|
-
"Version": 3,
|
|
568
|
-
"PublishDate": "2017-05-15T21:39:12.0076806Z",
|
|
569
|
-
"ConfigDataVersion": "1.0.0.1"
|
|
570
|
-
}`;
|
|
571
|
-
|
|
572
|
-
KnownUser.UserInQueueService = userInQueueServiceMock;
|
|
573
|
-
const result = KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true", "queueIttoken", integrationConfigString, "customerid", "secretkey", httpContextMock);
|
|
574
|
-
|
|
575
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.method).toBe('validateQueueRequest');
|
|
576
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.targetUrl).toBe('');
|
|
577
|
-
expect(result.first!.isAjaxResult).toBeTruthy();
|
|
578
|
-
});
|
|
579
|
-
|
|
580
|
-
it('should Exception_NoDebugToken', () => {
|
|
581
|
-
resetMocks();
|
|
582
|
-
userInQueueServiceMock.validateQueueRequestResultRaiseException = true;
|
|
583
|
-
|
|
584
|
-
httpContextMock.req.headers.set('user-agent', 'googlebot');
|
|
585
|
-
|
|
586
|
-
const integrationConfigString = `{
|
|
587
|
-
"Description": "test",
|
|
588
|
-
"Integrations": [
|
|
589
|
-
{
|
|
590
|
-
"Name": "event1action",
|
|
591
|
-
"ActionType": "Queue",
|
|
592
|
-
"EventId": "event1",
|
|
593
|
-
"CookieDomain": ".test.com",
|
|
594
|
-
"LayoutName": "Christmas Layout by Queue-it",
|
|
595
|
-
"Culture": "",
|
|
596
|
-
"ExtendCookieValidity": true,
|
|
597
|
-
"CookieValidityMinute": 20,
|
|
598
|
-
"Triggers": [
|
|
599
|
-
{
|
|
600
|
-
"TriggerParts": [
|
|
601
|
-
{
|
|
602
|
-
"Operator": "Contains",
|
|
603
|
-
"ValueToCompare": "event1",
|
|
604
|
-
"UrlPart": "PageUrl",
|
|
605
|
-
"ValidatorType": "UrlValidator",
|
|
606
|
-
"IsNegative": false,
|
|
607
|
-
"IsIgnoreCase": true
|
|
608
|
-
},
|
|
609
|
-
{
|
|
610
|
-
"Operator": "Contains",
|
|
611
|
-
"ValueToCompare": "googlebot",
|
|
612
|
-
"ValidatorType": "UserAgentValidator",
|
|
613
|
-
"IsNegative": false,
|
|
614
|
-
"IsIgnoreCase": false
|
|
615
|
-
}
|
|
616
|
-
],
|
|
617
|
-
"LogicalOperator": "And"
|
|
618
|
-
}
|
|
619
|
-
],
|
|
620
|
-
"QueueDomain": "knownusertest.queue-it.net",
|
|
621
|
-
"RedirectLogic": "AllowTParameter",
|
|
622
|
-
"ForcedTargetUrl": ""
|
|
623
|
-
}
|
|
624
|
-
],
|
|
625
|
-
"CustomerId": "knownusertest",
|
|
626
|
-
"AccountId": "knownusertest",
|
|
627
|
-
"Version": 3,
|
|
628
|
-
"PublishDate": "2017-05-15T21:39:12.0076806Z",
|
|
629
|
-
"ConfigDataVersion": "1.0.0.1"
|
|
630
|
-
}`;
|
|
631
|
-
|
|
632
|
-
const result = KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true", "queueIttoken", integrationConfigString, "customerid", "secretkey", httpContextMock);
|
|
633
|
-
|
|
634
|
-
expect(result.second).not.toBeNull()
|
|
635
|
-
expect(httpContextMock.res.cookies.has(KnownUser.QueueITDebugKey)).toBeFalsy('debug header shouldn`t be added');
|
|
636
|
-
});
|
|
637
|
-
|
|
638
|
-
it('should CancelAction', () => {
|
|
639
|
-
resetMocks();
|
|
640
|
-
userInQueueServiceMock.validateQueueRequestResult = new RequestValidationResult("Cancel", "eventid", "queueid", "redirectUrl", "");
|
|
641
|
-
|
|
642
|
-
httpContextMock.req.headers.set('user-agent', 'googlebot');
|
|
643
|
-
|
|
644
|
-
const integrationConfigString = `{
|
|
645
|
-
"Integrations":[
|
|
646
|
-
{
|
|
647
|
-
"Name":"event1action",
|
|
648
|
-
"EventId":"eventid",
|
|
649
|
-
"CookieDomain":"cookiedomain",
|
|
650
|
-
"LayoutName":null,
|
|
651
|
-
"Culture":null,
|
|
652
|
-
"ExtendCookieValidity":null,
|
|
653
|
-
"CookieValidityMinute":null,
|
|
654
|
-
"QueueDomain":"queuedomain",
|
|
655
|
-
"RedirectLogic":null,
|
|
656
|
-
"ForcedTargetUrl":null,
|
|
657
|
-
"ActionType":"Cancel",
|
|
658
|
-
"Triggers":[
|
|
659
|
-
{
|
|
660
|
-
"TriggerParts":[
|
|
661
|
-
{
|
|
662
|
-
"ValidatorType":"UrlValidator",
|
|
663
|
-
"Operator":"Contains",
|
|
664
|
-
"ValueToCompare":"event1",
|
|
665
|
-
"ValuesToCompare":null,
|
|
666
|
-
"IsNegative":false,
|
|
667
|
-
"IsIgnoreCase":true,
|
|
668
|
-
"UrlPart":"PageUrl",
|
|
669
|
-
"CookieName":null,
|
|
670
|
-
"HttpHeaderName":null
|
|
671
|
-
}
|
|
672
|
-
],
|
|
673
|
-
"LogicalOperator":"And"
|
|
674
|
-
}
|
|
675
|
-
]
|
|
676
|
-
}
|
|
677
|
-
],
|
|
678
|
-
"Version":3
|
|
679
|
-
}`;
|
|
680
|
-
|
|
681
|
-
KnownUser.UserInQueueService = userInQueueServiceMock;
|
|
682
|
-
const result = KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true", "queueIttoken", integrationConfigString, "customerid", "secretkey", httpContextMock);
|
|
683
|
-
|
|
684
|
-
expect(userInQueueServiceMock.validateCancelRequestCall!.method).toBe('validateCancelRequest');
|
|
685
|
-
expect(userInQueueServiceMock.validateCancelRequestCall!.targetUrl).toBe('http://test.com?event1=true');
|
|
686
|
-
expect(userInQueueServiceMock.validateCancelRequestCall!.customerId).toBe('customerid');
|
|
687
|
-
expect(userInQueueServiceMock.validateCancelRequestCall!.secretKey).toBe('secretkey');
|
|
688
|
-
|
|
689
|
-
expect(userInQueueServiceMock.validateQueueRequestResult.eventId).toBe('eventid');
|
|
690
|
-
expect(userInQueueServiceMock.validateQueueRequestResult.queueId).toBe('queueid');
|
|
691
|
-
expect(userInQueueServiceMock.validateQueueRequestResult.redirectUrl).toBe('redirectUrl');
|
|
692
|
-
|
|
693
|
-
expect(result.first!.isAjaxResult).toBeFalsy();
|
|
694
|
-
});
|
|
695
|
-
|
|
696
|
-
it('should CancelAction_AjaxCall', () => {
|
|
697
|
-
resetMocks();
|
|
698
|
-
userInQueueServiceMock.validateQueueRequestResult = new RequestValidationResult("Cancel", "eventid", "", "http://q.qeuue-it.com", '');
|
|
699
|
-
|
|
700
|
-
httpContextMock.req.headers.set('a', 'b');
|
|
701
|
-
httpContextMock.req.headers.set('e', 'f');
|
|
702
|
-
httpContextMock.req.headers.set('x-queueit-ajaxpageurl', 'http%3a%2f%2furl');
|
|
703
|
-
|
|
704
|
-
const integrationConfigString = `{
|
|
705
|
-
"Integrations":[
|
|
706
|
-
{
|
|
707
|
-
"Name":"event1action",
|
|
708
|
-
"EventId":"eventid",
|
|
709
|
-
"CookieDomain":"cookiedomain",
|
|
710
|
-
"LayoutName":null,
|
|
711
|
-
"Culture":null,
|
|
712
|
-
"ExtendCookieValidity":null,
|
|
713
|
-
"CookieValidityMinute":null,
|
|
714
|
-
"QueueDomain":"queuedomain",
|
|
715
|
-
"RedirectLogic":null,
|
|
716
|
-
"ForcedTargetUrl":null,
|
|
717
|
-
"ActionType":"Cancel",
|
|
718
|
-
"Triggers":[
|
|
719
|
-
{
|
|
720
|
-
"TriggerParts":[
|
|
721
|
-
{
|
|
722
|
-
"ValidatorType":"UrlValidator",
|
|
723
|
-
"Operator":"Contains",
|
|
724
|
-
"ValueToCompare":"event1",
|
|
725
|
-
"ValuesToCompare":null,
|
|
726
|
-
"IsNegative":false,
|
|
727
|
-
"IsIgnoreCase":true,
|
|
728
|
-
"UrlPart":"PageUrl",
|
|
729
|
-
"CookieName":null,
|
|
730
|
-
"HttpHeaderName":null
|
|
731
|
-
}
|
|
732
|
-
],
|
|
733
|
-
"LogicalOperator":"And"
|
|
734
|
-
}
|
|
735
|
-
]
|
|
736
|
-
}
|
|
737
|
-
],
|
|
738
|
-
"Version":3
|
|
739
|
-
}`;
|
|
740
|
-
|
|
741
|
-
KnownUser.UserInQueueService = userInQueueServiceMock;
|
|
742
|
-
const result = KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true", "queueIttoken", integrationConfigString, "customerid", "secretkey", httpContextMock);
|
|
743
|
-
|
|
744
|
-
expect(userInQueueServiceMock.validateCancelRequestCall!.method).toBe('validateCancelRequest');
|
|
745
|
-
expect(userInQueueServiceMock.validateCancelRequestCall!.targetUrl).toBe('http://url');
|
|
746
|
-
expect(userInQueueServiceMock.validateCancelRequestCall!.customerId).toBe('customerid');
|
|
747
|
-
expect(userInQueueServiceMock.validateCancelRequestCall!.secretKey).toBe('secretkey');
|
|
748
|
-
|
|
749
|
-
expect(userInQueueServiceMock.validateCancelRequestCall!.cancelConfig.eventId).toBe('eventid');
|
|
750
|
-
expect(userInQueueServiceMock.validateCancelRequestCall!.cancelConfig.queueDomain).toBe('queuedomain');
|
|
751
|
-
expect(userInQueueServiceMock.validateCancelRequestCall!.cancelConfig.cookieDomain).toBe('cookiedomain');
|
|
752
|
-
expect(userInQueueServiceMock.validateCancelRequestCall!.cancelConfig.version).toBe(3);
|
|
753
|
-
|
|
754
|
-
expect(result.first!.isAjaxResult).toBeTruthy();
|
|
755
|
-
});
|
|
756
|
-
|
|
757
|
-
it('should IgnoreAction', () => {
|
|
758
|
-
resetMocks();
|
|
759
|
-
userInQueueServiceMock.validateQueueRequestResult = new RequestValidationResult("Ignore", "eventid", "queueid", "redirectUrl", "", "event1action");
|
|
760
|
-
|
|
761
|
-
httpContextMock.req.headers.set('user-agent', 'googlebot');
|
|
762
|
-
|
|
763
|
-
const integrationConfigString = `{
|
|
764
|
-
"Integrations":[
|
|
765
|
-
{
|
|
766
|
-
"Name":"event1action",
|
|
767
|
-
"EventId":"eventid",
|
|
768
|
-
"CookieDomain":"cookiedomain",
|
|
769
|
-
"LayoutName":null,
|
|
770
|
-
"Culture":null,
|
|
771
|
-
"ExtendCookieValidity":null,
|
|
772
|
-
"CookieValidityMinute":null,
|
|
773
|
-
"QueueDomain":"queuedomain",
|
|
774
|
-
"RedirectLogic":null,
|
|
775
|
-
"ForcedTargetUrl":null,
|
|
776
|
-
"ActionType":"Ignore",
|
|
777
|
-
"Triggers":[
|
|
778
|
-
{
|
|
779
|
-
"TriggerParts":[
|
|
780
|
-
{
|
|
781
|
-
"ValidatorType":"UrlValidator",
|
|
782
|
-
"Operator":"Contains",
|
|
783
|
-
"ValueToCompare":"event1",
|
|
784
|
-
"ValuesToCompare":null,
|
|
785
|
-
"IsNegative":false,
|
|
786
|
-
"IsIgnoreCase":true,
|
|
787
|
-
"UrlPart":"PageUrl",
|
|
788
|
-
"CookieName":null,
|
|
789
|
-
"HttpHeaderName":null
|
|
790
|
-
}
|
|
791
|
-
],
|
|
792
|
-
"LogicalOperator":"And"
|
|
793
|
-
}
|
|
794
|
-
]
|
|
795
|
-
}
|
|
796
|
-
],
|
|
797
|
-
"Version":3
|
|
798
|
-
}`;
|
|
799
|
-
|
|
800
|
-
KnownUser.UserInQueueService = userInQueueServiceMock;
|
|
801
|
-
|
|
802
|
-
const result = KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true", "queueIttoken", integrationConfigString, "customerid", "secretkey", httpContextMock);
|
|
803
|
-
const call = userInQueueServiceMock.requestValidationResult;
|
|
804
|
-
expect(result.first!.actionType).toBe('Ignore');
|
|
805
|
-
expect(call!.method).toBe('getIgnoreResult');
|
|
806
|
-
expect(result.first!.isAjaxResult).toBe(false);
|
|
807
|
-
expect(result.first!.actionName).toBe('event1action');
|
|
808
|
-
});
|
|
809
|
-
|
|
810
|
-
it('should IgnoreAction_AjaxCall', () => {
|
|
811
|
-
resetMocks();
|
|
812
|
-
userInQueueServiceMock.validateQueueRequestResult = new RequestValidationResult("Cancel", "eventid", "", "http://q.qeuue-it.com", '');
|
|
813
|
-
|
|
814
|
-
httpContextMock.req.headers.set('a', 'b');
|
|
815
|
-
httpContextMock.req.headers.set('c', 'd');
|
|
816
|
-
httpContextMock.req.headers.set('e', 'f');
|
|
817
|
-
httpContextMock.req.headers.set('x-queueit-ajaxpageurl', 'http%3a%2f%2furl');
|
|
818
|
-
|
|
819
|
-
const integrationConfigString = ` {
|
|
820
|
-
"Description": "test",
|
|
821
|
-
"Integrations": [
|
|
822
|
-
{
|
|
823
|
-
"Name": "event1action",
|
|
824
|
-
"EventId": "event1",
|
|
825
|
-
"CookieDomain": ".test.com",
|
|
826
|
-
"ActionType":"Ignore",
|
|
827
|
-
"Triggers": [
|
|
828
|
-
{
|
|
829
|
-
"TriggerParts": [
|
|
830
|
-
{
|
|
831
|
-
"Operator": "Contains",
|
|
832
|
-
"ValueToCompare": "event1",
|
|
833
|
-
"UrlPart": "PageUrl",
|
|
834
|
-
"ValidatorType": "UrlValidator",
|
|
835
|
-
"IsNegative": false,
|
|
836
|
-
"IsIgnoreCase": true
|
|
837
|
-
}
|
|
838
|
-
],
|
|
839
|
-
"LogicalOperator": "And"
|
|
840
|
-
}
|
|
841
|
-
],
|
|
842
|
-
"QueueDomain": "knownusertest.queue-it.net"
|
|
843
|
-
}
|
|
844
|
-
],
|
|
845
|
-
"CustomerId": "knownusertest",
|
|
846
|
-
"AccountId": "knownusertest",
|
|
847
|
-
"Version": 3,
|
|
848
|
-
"PublishDate": "2017-05-15T21:39:12.0076806Z",
|
|
849
|
-
"ConfigDataVersion": "1.0.0.1"
|
|
850
|
-
}`;
|
|
851
|
-
|
|
852
|
-
KnownUser.UserInQueueService = userInQueueServiceMock;
|
|
853
|
-
const result = KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true", "queueIttoken", integrationConfigString, "customerid", "secretkey", httpContextMock);
|
|
854
|
-
const call = userInQueueServiceMock.requestValidationResult;
|
|
855
|
-
expect(result.first!.actionType).toBe('Ignore');
|
|
856
|
-
expect(call!.method).toBe('getIgnoreResult');
|
|
857
|
-
expect(result.first!.isAjaxResult).toBeTruthy();
|
|
858
|
-
});
|
|
859
|
-
|
|
860
|
-
it('should Debug', () => {
|
|
861
|
-
resetMocks();
|
|
862
|
-
|
|
863
|
-
const integrationConfigString = `{
|
|
864
|
-
"Description":
|
|
865
|
-
"test",
|
|
866
|
-
"Integrations": [{
|
|
867
|
-
"Name":
|
|
868
|
-
"event1action",
|
|
869
|
-
"ActionType": "Queue",
|
|
870
|
-
"EventId":
|
|
871
|
-
"event1",
|
|
872
|
-
"CookieDomain":
|
|
873
|
-
".test.com",
|
|
874
|
-
"LayoutName":
|
|
875
|
-
"Christmas Layout by Queue-it",
|
|
876
|
-
"Culture":
|
|
877
|
-
"da-DK",
|
|
878
|
-
"ExtendCookieValidity":
|
|
879
|
-
true,
|
|
880
|
-
"CookieValidityMinute":
|
|
881
|
-
20,
|
|
882
|
-
"Triggers": [{
|
|
883
|
-
"TriggerParts": [{
|
|
884
|
-
"Operator": "Contains",
|
|
885
|
-
"ValueToCompare": "event1",
|
|
886
|
-
"UrlPart": "PageUrl",
|
|
887
|
-
"ValidatorType": "UrlValidator",
|
|
888
|
-
"IsNegative": false,
|
|
889
|
-
"IsIgnoreCase": true
|
|
890
|
-
}, {
|
|
891
|
-
"Operator": "Contains",
|
|
892
|
-
"ValueToCompare": "googlebot",
|
|
893
|
-
"ValidatorType": "UserAgentValidator",
|
|
894
|
-
"IsNegative": false,
|
|
895
|
-
"IsIgnoreCase": false
|
|
896
|
-
}],
|
|
897
|
-
"LogicalOperator":
|
|
898
|
-
"And"
|
|
899
|
-
}],
|
|
900
|
-
"QueueDomain":
|
|
901
|
-
"knownusertest.queue-it.net",
|
|
902
|
-
"RedirectLogic":
|
|
903
|
-
"AllowTParameter"
|
|
904
|
-
}],
|
|
905
|
-
"CustomerId":
|
|
906
|
-
"knownusertest",
|
|
907
|
-
"AccountId":
|
|
908
|
-
"knownusertest",
|
|
909
|
-
"Version":
|
|
910
|
-
3,
|
|
911
|
-
"PublishDate":
|
|
912
|
-
"2017-05-15T21:39:12.0076806Z",
|
|
913
|
-
"ConfigDataVersion":
|
|
914
|
-
"1.0.0.1"
|
|
915
|
-
}`;
|
|
916
|
-
|
|
917
|
-
httpContextMock.req.setAbsoluteUri("http://localhost/original_url");
|
|
918
|
-
httpContextMock.req.setUserHostAddress("userIP");
|
|
919
|
-
mockGoogleHeaders();
|
|
920
|
-
|
|
921
|
-
const secretKey = "secretKey";
|
|
922
|
-
const queueitToken = generateDebugToken("eventId", secretKey);
|
|
923
|
-
const dateTimeProviderMock = new MockDateTimeProvider();
|
|
924
|
-
const expectedServerTime = toISOString(dateTimeProviderMock.getCurrentTime()).split('.')[0] + "Z";
|
|
925
|
-
KnownUser.UserInQueueService = userInQueueServiceMock;
|
|
926
|
-
KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true",
|
|
927
|
-
queueitToken,
|
|
928
|
-
integrationConfigString,
|
|
929
|
-
"customerId",
|
|
930
|
-
secretKey,
|
|
931
|
-
httpContextMock,
|
|
932
|
-
dateTimeProviderMock);
|
|
933
|
-
|
|
934
|
-
const actualCookieValue = httpContextMock.res.cookies.get(KnownUser.QueueITDebugKey).value;
|
|
935
|
-
expect(actualCookieValue.indexOf("ServerUtcTime=" + expectedServerTime + "|")).not.toBe(-1);
|
|
936
|
-
expect(actualCookieValue.indexOf("ConfigVersion=3|")).not.toBe(-1);
|
|
937
|
-
expect(actualCookieValue.indexOf("PureUrl=http://test.com?event1=true|")).not.toBe(-1);
|
|
938
|
-
expect(actualCookieValue.indexOf("QueueitToken=" + queueitToken + "|")).not.toBe(-1);
|
|
939
|
-
expect(actualCookieValue.indexOf("RequestIP=userIP|")).not.toBe(-1);
|
|
940
|
-
expect(actualCookieValue.indexOf("RequestHttpHeader_Via=v|")).not.toBe(-1);
|
|
941
|
-
expect(actualCookieValue.indexOf("RequestHttpHeader_Forwarded=f|")).not.toBe(-1);
|
|
942
|
-
expect(actualCookieValue.indexOf("RequestHttpHeader_XForwardedFor=xff|")).not.toBe(-1);
|
|
943
|
-
expect(actualCookieValue.indexOf("RequestHttpHeader_XForwardedHost=xfh|")).not.toBe(-1);
|
|
944
|
-
expect(actualCookieValue.indexOf("RequestHttpHeader_XForwardedProto=xfp|")).not.toBe(-1);
|
|
945
|
-
expect(actualCookieValue.indexOf("MatchedConfig=event1action|")).not.toBe(-1);
|
|
946
|
-
expect(actualCookieValue.indexOf("TargetUrl=http://test.com?event1=true|")).not.toBe(-1);
|
|
947
|
-
expect(actualCookieValue.indexOf("|QueueConfig=EventId:event1&Version:3&ActionName:event1action&QueueDomain:knownusertest.queue-it.net&CookieDomain:.test.com&ExtendCookieValidity:true&CookieValidityMinute:20&LayoutName:Christmas Layout by Queue-it&Culture:da-DK")).not.toBe(-1);
|
|
948
|
-
expect(actualCookieValue.indexOf("SdkVersion=" + SDK_VERSION + "|")).not.toBe(-1);
|
|
949
|
-
});
|
|
950
|
-
|
|
951
|
-
it('should Debug_WithoutMatch', () => {
|
|
952
|
-
resetMocks();
|
|
953
|
-
|
|
954
|
-
const requestIP = "80.35.35.34";
|
|
955
|
-
const viaHeader = "1.1 example.com";
|
|
956
|
-
const forwardedHeader = "for=192.0.2.60;proto=http;by=203.0.113.43";
|
|
957
|
-
const xForwardedForHeader = "129.78.138.66, 129.78.64.103";
|
|
958
|
-
const xForwardedHostHeader = "en.wikipedia.org:8080";
|
|
959
|
-
const xForwardedProtoHeader = "https";
|
|
960
|
-
|
|
961
|
-
const integrationConfigString = `{
|
|
962
|
-
"Description": "test",
|
|
963
|
-
"Integrations": [
|
|
964
|
-
{
|
|
965
|
-
"Name": "event1action",
|
|
966
|
-
"EventId": "event1",
|
|
967
|
-
"CookieDomain": ".test.com",
|
|
968
|
-
"ActionType":"Cancel",
|
|
969
|
-
"Triggers": [
|
|
970
|
-
{
|
|
971
|
-
"TriggerParts": [
|
|
972
|
-
{
|
|
973
|
-
"Operator": "Contains",
|
|
974
|
-
"ValueToCompare": "notmatch",
|
|
975
|
-
"UrlPart": "PageUrl",
|
|
976
|
-
"ValidatorType": "UrlValidator",
|
|
977
|
-
"IsNegative": false,
|
|
978
|
-
"IsIgnoreCase": true
|
|
979
|
-
}
|
|
980
|
-
],
|
|
981
|
-
"LogicalOperator": "And"
|
|
982
|
-
}
|
|
983
|
-
],
|
|
984
|
-
"QueueDomain": "knownusertest.queue-it.net"
|
|
985
|
-
}
|
|
986
|
-
],
|
|
987
|
-
"CustomerId": "knownusertest",
|
|
988
|
-
"AccountId": "knownusertest",
|
|
989
|
-
"Version": 10,
|
|
990
|
-
"PublishDate": "2017-05-15T21:39:12.0076806Z",
|
|
991
|
-
"ConfigDataVersion": "1.0.0.1"
|
|
992
|
-
}`;
|
|
993
|
-
|
|
994
|
-
httpContextMock.req.setAbsoluteUri("http://test.com/?event1=true&queueittoken=queueittokenvalue");
|
|
995
|
-
httpContextMock.req.setUserHostAddress(requestIP);
|
|
996
|
-
httpContextMock.req.headers.set('via', viaHeader);
|
|
997
|
-
httpContextMock.req.headers.set('forwarded', forwardedHeader);
|
|
998
|
-
httpContextMock.req.headers.set('x-forwarded-for', xForwardedForHeader);
|
|
999
|
-
httpContextMock.req.headers.set('x-forwarded-host', xForwardedHostHeader);
|
|
1000
|
-
httpContextMock.req.headers.set('x-forwarded-proto', xForwardedProtoHeader);
|
|
1001
|
-
const secretKey = "secretKey";
|
|
1002
|
-
const queueitToken = generateDebugToken("eventId", secretKey);
|
|
1003
|
-
const dateTimeProviderMock = new MockDateTimeProvider();
|
|
1004
|
-
const expectedServerTime = toISOString(dateTimeProviderMock.getCurrentTime()).split('.')[0] + "Z";
|
|
1005
|
-
|
|
1006
|
-
const result = KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true",
|
|
1007
|
-
queueitToken,
|
|
1008
|
-
integrationConfigString,
|
|
1009
|
-
"customerId",
|
|
1010
|
-
secretKey,
|
|
1011
|
-
httpContextMock,
|
|
1012
|
-
dateTimeProviderMock);
|
|
1013
|
-
|
|
1014
|
-
expect(httpContextMock.res.cookies.has(KnownUser.QueueITDebugKey)).toBeTruthy('Debug cookie key should be set')
|
|
1015
|
-
const actualCookieValue = httpContextMock.res.cookies.get(KnownUser.QueueITDebugKey).value
|
|
1016
|
-
expect(actualCookieValue.indexOf("ConfigVersion=10")).not.toBe(-1, 'Should contain config version');
|
|
1017
|
-
expect(actualCookieValue.indexOf("PureUrl=http://test.com?event1=true")).not.toBe(-1, 'Should have pureUrl');
|
|
1018
|
-
expect(actualCookieValue.indexOf(queueitToken)).not.toBe(-1, 'Should contain QueueITToken');
|
|
1019
|
-
expect(actualCookieValue.indexOf("OriginalUrl=http://test.com/?event1=true&queueittoken=queueittokenvalue")).not.toBe(-1, 'Should contain original url');
|
|
1020
|
-
expect(actualCookieValue.indexOf("ServerUtcTime=" + expectedServerTime)).not.toBe(-1, 'Should contain serverUtcTime');
|
|
1021
|
-
expect(actualCookieValue.indexOf("MatchedConfig=NULL")).not.toBe(-1, 'Should have MatchedConfig=NULL');
|
|
1022
|
-
expect(actualCookieValue.indexOf("RequestIP=80.35.35.34")).not.toBe(-1, 'Should contain requestIp');
|
|
1023
|
-
expect(actualCookieValue.indexOf("RequestHttpHeader_Via=1.1 example.com")).not.toBe(-1, 'Should contain via header');
|
|
1024
|
-
expect(actualCookieValue.indexOf("RequestHttpHeader_Forwarded=for=192.0.2.60;proto=http;by=203.0.113.43")).not.toBe(-1, 'Should contain forwarded headers');
|
|
1025
|
-
expect(actualCookieValue.indexOf("RequestHttpHeader_XForwardedFor=129.78.138.66, 129.78.64.103")).not.toBe(-1, 'Should contain forwarded for headers');
|
|
1026
|
-
expect(actualCookieValue.indexOf("RequestHttpHeader_XForwardedHost=en.wikipedia.org:8080")).not.toBe(-1, 'Should contain forwarded host header');
|
|
1027
|
-
expect(actualCookieValue.indexOf("RequestHttpHeader_XForwardedProto=https")).not.toBe(-1, 'Should contain forwarded proto header');
|
|
1028
|
-
expect(actualCookieValue.indexOf("SdkVersion=" + SDK_VERSION + "|")).not.toBe(-1, 'Should contain sdk version');
|
|
1029
|
-
});
|
|
1030
|
-
|
|
1031
|
-
it('should NotValidHash_Debug', () => {
|
|
1032
|
-
resetMocks();
|
|
1033
|
-
userInQueueServiceMock.validateQueueRequestResult = new RequestValidationResult("Debug", "eventid", "queueid", "http://q.qeuue-it.com", '');
|
|
1034
|
-
|
|
1035
|
-
const requestIP = "80.35.35.34";
|
|
1036
|
-
|
|
1037
|
-
const integrationConfigString = `{
|
|
1038
|
-
"Description": "test",
|
|
1039
|
-
"Integrations": [
|
|
1040
|
-
{
|
|
1041
|
-
"Name": "event1action",
|
|
1042
|
-
"EventId": "event1",
|
|
1043
|
-
"CookieDomain": ".test.com",
|
|
1044
|
-
"ActionType":"Cancel",
|
|
1045
|
-
"Triggers": [
|
|
1046
|
-
{
|
|
1047
|
-
"TriggerParts": [
|
|
1048
|
-
{
|
|
1049
|
-
"Operator": "Contains",
|
|
1050
|
-
"ValueToCompare": "event1",
|
|
1051
|
-
"UrlPart": "PageUrl",
|
|
1052
|
-
"ValidatorType": "UrlValidator",
|
|
1053
|
-
"IsNegative": false,
|
|
1054
|
-
"IsIgnoreCase": true
|
|
1055
|
-
}
|
|
1056
|
-
],
|
|
1057
|
-
"LogicalOperator": "And"
|
|
1058
|
-
}
|
|
1059
|
-
],
|
|
1060
|
-
"QueueDomain": "knownusertest.queue-it.net"
|
|
1061
|
-
}
|
|
1062
|
-
],
|
|
1063
|
-
"CustomerId": "knownusertest",
|
|
1064
|
-
"AccountId": "knownusertest",
|
|
1065
|
-
"Version": 3,
|
|
1066
|
-
"PublishDate": "2017-05-15T21:39:12.0076806Z",
|
|
1067
|
-
"ConfigDataVersion": "1.0.0.1"
|
|
1068
|
-
}`;
|
|
1069
|
-
|
|
1070
|
-
httpContextMock.req.setAbsoluteUri("http://test.com/?event1=true&queueittoken=queueittokenvalue");
|
|
1071
|
-
httpContextMock.req.setUserHostAddress(requestIP);
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
const secretKey = "secretKey";
|
|
1075
|
-
const queueitToken = generateDebugToken("eventId", secretKey);
|
|
1076
|
-
const expectedServerTime = toISOString(new Date(Date.now())).split('.')[0] + "Z";
|
|
1077
|
-
|
|
1078
|
-
KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true=", queueitToken, integrationConfigString, "customerId", secretKey, httpContextMock);
|
|
1079
|
-
|
|
1080
|
-
const actualCookieValue = httpContextMock.res.cookies.get(KnownUser.QueueITDebugKey).value
|
|
1081
|
-
|
|
1082
|
-
expect(actualCookieValue.indexOf("PureUrl=http://test.com?event1=true")).not.toBe(-1);
|
|
1083
|
-
expect(actualCookieValue.indexOf("ConfigVersion=3")).not.toBe(-1);
|
|
1084
|
-
expect(actualCookieValue.indexOf("MatchedConfig=event1action")).not.toBe(-1);
|
|
1085
|
-
expect(actualCookieValue.indexOf(queueitToken)).not.toBe(-1);
|
|
1086
|
-
expect(actualCookieValue.indexOf("OriginalUrl=http://test.com/?event1=true&queueittoken=queueittokenvalue")).not.toBe(-1);
|
|
1087
|
-
expect(actualCookieValue.indexOf("TargetUrl=http://test.com?event1=true")).not.toBe(-1);
|
|
1088
|
-
expect(actualCookieValue.indexOf("CancelConfig=EventId:event1&Version:3&QueueDomain:knownusertest.queue-it.net&CookieDomain:.test.com")).not.toBe(-1);
|
|
1089
|
-
});
|
|
1090
|
-
|
|
1091
|
-
it('should Debug_NullConfig', () => {
|
|
1092
|
-
resetMocks();
|
|
1093
|
-
|
|
1094
|
-
httpContextMock.req.setAbsoluteUri("http://localhost/original_url");
|
|
1095
|
-
httpContextMock.req.setUserHostAddress("userIP");
|
|
1096
|
-
mockGoogleHeaders();
|
|
1097
|
-
|
|
1098
|
-
const secretKey = "secretKey";
|
|
1099
|
-
const queueitToken = generateDebugToken("eventId", secretKey);
|
|
1100
|
-
KnownUser.UserInQueueService = userInQueueServiceMock;
|
|
1101
|
-
|
|
1102
|
-
const result = KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true", queueitToken, "{}", "customerId", secretKey, httpContextMock);
|
|
1103
|
-
const errorReturned = result.second != null && result.second!.message == 'integrationsConfigString can not be null or empty.';
|
|
1104
|
-
assert(errorReturned);
|
|
1105
|
-
|
|
1106
|
-
//Assert
|
|
1107
|
-
expect(userInQueueServiceMock.validateQueueRequestCall).toBeNull();
|
|
1108
|
-
|
|
1109
|
-
const actualCookieValue = httpContextMock.res.cookies.get(KnownUser.QueueITDebugKey).value
|
|
1110
|
-
expect(actualCookieValue.indexOf("ConfigVersion=NULL|")).not.toBe(-1);
|
|
1111
|
-
expect(actualCookieValue.indexOf("PureUrl=http://test.com?event1=true|")).not.toBe(-1);
|
|
1112
|
-
expect(actualCookieValue.indexOf("QueueitToken=" + queueitToken + "|")).not.toBe(-1);
|
|
1113
|
-
expect(actualCookieValue.indexOf("SdkVersion=" + SDK_VERSION + "|")).not.toBe(-1);
|
|
1114
|
-
expect(actualCookieValue.indexOf("Exception=integrationsConfigString can not be null or empty.")).not.toBe(-1);
|
|
1115
|
-
});
|
|
1116
|
-
|
|
1117
|
-
it('should Debug_Missing_CustomerId', () => {
|
|
1118
|
-
resetMocks();
|
|
1119
|
-
const integrationConfigString = `{}`;
|
|
1120
|
-
httpContextMock.req.setAbsoluteUri("http://localhost/original_url");
|
|
1121
|
-
httpContextMock.req.setUserHostAddress("userIP");
|
|
1122
|
-
mockGoogleHeaders();
|
|
1123
|
-
|
|
1124
|
-
const secretKey = "secretKey";
|
|
1125
|
-
const queueitToken = generateDebugToken("eventId", secretKey);
|
|
1126
|
-
KnownUser.UserInQueueService = userInQueueServiceMock;
|
|
1127
|
-
|
|
1128
|
-
const result = KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true", queueitToken, integrationConfigString, '', secretKey, httpContextMock);
|
|
1129
|
-
|
|
1130
|
-
//Assert
|
|
1131
|
-
expect(result.second).toBeNull();
|
|
1132
|
-
expect(result.first).not.toBeNull();
|
|
1133
|
-
expect("https://api2.queue-it.net/diagnostics/connector/error/?code=setup").toBe(result.first!.redirectUrl);
|
|
1134
|
-
expect(httpContextMock.res.cookies.has(KnownUser.QueueITDebugKey)).toBeFalsy('debug cookie should not be set');
|
|
1135
|
-
});
|
|
1136
|
-
|
|
1137
|
-
it('should Debug_Missing_SecretKey', () => {
|
|
1138
|
-
resetMocks();
|
|
1139
|
-
const integrationConfigString = `{}`;
|
|
1140
|
-
httpContextMock.req.setAbsoluteUri("http://localhost/original_url");
|
|
1141
|
-
httpContextMock.req.setUserHostAddress("userIP");
|
|
1142
|
-
mockGoogleHeaders();
|
|
1143
|
-
|
|
1144
|
-
const secretKey = "secretKey";
|
|
1145
|
-
const queueitToken = generateDebugToken("eventId", secretKey);
|
|
1146
|
-
KnownUser.UserInQueueService = userInQueueServiceMock;
|
|
1147
|
-
|
|
1148
|
-
const result = KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true", queueitToken, integrationConfigString, "customerId", '', httpContextMock);
|
|
1149
|
-
//Assert
|
|
1150
|
-
expect("https://api2.queue-it.net/diagnostics/connector/error/?code=setup" == result.first!.redirectUrl);
|
|
1151
|
-
expect(httpContextMock.res.cookies.has(KnownUser.QueueITDebugKey)).toBeFalsy('debug cookie should not be set');
|
|
1152
|
-
});
|
|
1153
|
-
|
|
1154
|
-
it('should Debug_ExpiredToken', () => {
|
|
1155
|
-
resetMocks();
|
|
1156
|
-
const integrationConfigString = `{}`;
|
|
1157
|
-
httpContextMock.req.setAbsoluteUri("http://localhost/original_url");
|
|
1158
|
-
httpContextMock.req.setUserHostAddress("userIP");
|
|
1159
|
-
mockGoogleHeaders();
|
|
1160
|
-
|
|
1161
|
-
const secretKey = "secretKey";
|
|
1162
|
-
const queueitToken = generateDebugToken("eventId", secretKey, true);
|
|
1163
|
-
KnownUser.UserInQueueService = userInQueueServiceMock;
|
|
1164
|
-
|
|
1165
|
-
const result = KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true", queueitToken, integrationConfigString, "customerId", secretKey, httpContextMock);
|
|
1166
|
-
//Assert
|
|
1167
|
-
expect("https://customerId.api2.queue-it.net/customerId/diagnostics/connector/error/?code=timestamp" == result.first!.redirectUrl);
|
|
1168
|
-
expect(httpContextMock.res.cookies.has(KnownUser.QueueITDebugKey)).toBeFalsy('debug cookie should not be set');
|
|
1169
|
-
});
|
|
1170
|
-
|
|
1171
|
-
it('should Debug_ModifiedToken', () => {
|
|
1172
|
-
resetMocks();
|
|
1173
|
-
const integrationConfigString = `{}`;
|
|
1174
|
-
httpContextMock.req.setAbsoluteUri("http://localhost/original_url");
|
|
1175
|
-
httpContextMock.req.setUserHostAddress("userIP");
|
|
1176
|
-
mockGoogleHeaders();
|
|
1177
|
-
|
|
1178
|
-
const secretKey = "secretKey";
|
|
1179
|
-
const queueitToken = generateDebugToken("eventId", secretKey) + "invalid-hash";
|
|
1180
|
-
KnownUser.UserInQueueService = userInQueueServiceMock;
|
|
1181
|
-
|
|
1182
|
-
const result = KnownUser.validateRequestByIntegrationConfig("http://test.com?event1=true", queueitToken, integrationConfigString, "customerId", secretKey, httpContextMock);
|
|
1183
|
-
//Assert
|
|
1184
|
-
expect("https://customerId.api2.queue-it.net/customerId/diagnostics/connector/error/?code=hash" == result.first!.redirectUrl);
|
|
1185
|
-
expect(httpContextMock.res.cookies.has(KnownUser.QueueITDebugKey)).toBeFalsy('debug cookie should not be set');
|
|
1186
|
-
});
|
|
1187
|
-
|
|
1188
|
-
});
|
|
1189
|
-
|
|
1190
|
-
describe('resolveQueueRequestByLocalEventConfig', () => {
|
|
1191
|
-
it('should handle ajax requests', () => {
|
|
1192
|
-
resetMocks();
|
|
1193
|
-
|
|
1194
|
-
const eventconfig = new QueueEventConfig('', '', '', '', false, 0, '', 0);
|
|
1195
|
-
eventconfig.cookieDomain = "cookieDomain";
|
|
1196
|
-
eventconfig.layoutName = "layoutName";
|
|
1197
|
-
eventconfig.culture = "culture";
|
|
1198
|
-
eventconfig.eventId = "eventId";
|
|
1199
|
-
eventconfig.queueDomain = "queueDomain";
|
|
1200
|
-
eventconfig.extendCookieValidity = true;
|
|
1201
|
-
eventconfig.cookieValidityMinute = 10;
|
|
1202
|
-
eventconfig.version = 12;
|
|
1203
|
-
|
|
1204
|
-
KnownUser.UserInQueueService = userInQueueServiceMock;
|
|
1205
|
-
const result = KnownUser.resolveQueueRequestByLocalConfig("targeturl", "queueIttoken", eventconfig, "customerid", "secretkey", httpContextMock);
|
|
1206
|
-
|
|
1207
|
-
expect(userInQueueServiceMock.validateQueueRequestCall).not.toBeNull();
|
|
1208
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.method).toBe('validateQueueRequest');
|
|
1209
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.targetUrl).toBe('targeturl');
|
|
1210
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.queueitToken).toBe('queueIttoken');
|
|
1211
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.queueConfig).toBe(eventconfig);
|
|
1212
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.customerId).toBe('customerid');
|
|
1213
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.secretKey).toBe('secretkey');
|
|
1214
|
-
expect(result.first!.isAjaxResult).toBeFalsy();
|
|
1215
|
-
});
|
|
1216
|
-
|
|
1217
|
-
it('should have isAjaxResult set always', () => {
|
|
1218
|
-
resetMocks();
|
|
1219
|
-
|
|
1220
|
-
const eventconfig = new QueueEventConfig('', '', '', '', false, 0, '', 0);
|
|
1221
|
-
eventconfig.cookieDomain = "cookieDomain";
|
|
1222
|
-
eventconfig.layoutName = "layoutName";
|
|
1223
|
-
eventconfig.culture = "culture";
|
|
1224
|
-
eventconfig.eventId = "eventId";
|
|
1225
|
-
eventconfig.queueDomain = "queueDomain";
|
|
1226
|
-
eventconfig.extendCookieValidity = true;
|
|
1227
|
-
eventconfig.cookieValidityMinute = 10;
|
|
1228
|
-
eventconfig.version = 12;
|
|
1229
|
-
|
|
1230
|
-
KnownUser.UserInQueueService = userInQueueServiceMock;
|
|
1231
|
-
const result = KnownUser.resolveQueueRequestByLocalConfig("targeturl", "queueIttoken", eventconfig, "customerid", "secretkey", httpContextMock);
|
|
1232
|
-
|
|
1233
|
-
expect(userInQueueServiceMock.validateQueueRequestCall).not.toBeNull('validateQueueRequest should be called');
|
|
1234
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.method).toBe('validateQueueRequest');
|
|
1235
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.targetUrl).toBe('targeturl');
|
|
1236
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.queueitToken).toBe('queueIttoken');
|
|
1237
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.queueConfig).toBe(eventconfig);
|
|
1238
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.customerId).toBe('customerid');
|
|
1239
|
-
expect(userInQueueServiceMock.validateQueueRequestCall!.secretKey).toBe('secretkey');
|
|
1240
|
-
|
|
1241
|
-
expect(result.second).toBeNull();
|
|
1242
|
-
expect(result.first).not.toBeNull();
|
|
1243
|
-
expect(result.first!.isAjaxResult).toBeFalsy();
|
|
1244
|
-
});
|
|
1245
|
-
|
|
1246
|
-
it('should handle NullCustomerId', () => {
|
|
1247
|
-
//Arrange
|
|
1248
|
-
resetMocks();
|
|
1249
|
-
KnownUser.UserInQueueService = userInQueueServiceMock;
|
|
1250
|
-
|
|
1251
|
-
//Act
|
|
1252
|
-
const result = KnownUser.resolveQueueRequestByLocalConfig("targetUrl", "queueitToken", null, '', "secretKey", httpContextMock);
|
|
1253
|
-
const exceptionWasThrown = result.second != null && result.second!.message == "customerId can not be null or empty.";
|
|
1254
|
-
|
|
1255
|
-
//Assert
|
|
1256
|
-
expect(userInQueueServiceMock.validateQueueRequestCall).toBeNull();
|
|
1257
|
-
expect(exceptionWasThrown).toBeTruthy();
|
|
1258
|
-
});
|
|
1259
|
-
|
|
1260
|
-
it('NullSecretKey', () => {
|
|
1261
|
-
//Arrange
|
|
1262
|
-
resetMocks();
|
|
1263
|
-
KnownUser.UserInQueueService = userInQueueServiceMock;
|
|
1264
|
-
|
|
1265
|
-
//Act
|
|
1266
|
-
const result = KnownUser.resolveQueueRequestByLocalConfig("targetUrl", "queueitToken", null, "customerId", '', httpContextMock);
|
|
1267
|
-
const exceptionWasThrown = result.second != null && result.second!.message == "secretKey can not be null or empty.";
|
|
1268
|
-
|
|
1269
|
-
//Assert
|
|
1270
|
-
expect(userInQueueServiceMock.validateQueueRequestCall).toBeNull();
|
|
1271
|
-
expect(exceptionWasThrown).toBeTruthy();
|
|
1272
|
-
});
|
|
1273
|
-
|
|
1274
|
-
it('NullEventConfig', () => {
|
|
1275
|
-
//Arrange
|
|
1276
|
-
resetMocks();
|
|
1277
|
-
KnownUser.UserInQueueService = userInQueueServiceMock;
|
|
1278
|
-
|
|
1279
|
-
//Act
|
|
1280
|
-
let result = KnownUser.resolveQueueRequestByLocalConfig("targetUrl", "queueitToken", null, "customerId", "secretKey", httpContextMock);
|
|
1281
|
-
const exceptionWasThrown = result.second != null && result.second!.message == "queueConfig can not be null.";
|
|
1282
|
-
|
|
1283
|
-
//Assert
|
|
1284
|
-
expect(userInQueueServiceMock.validateQueueRequestCall).toBeNull();
|
|
1285
|
-
expect(exceptionWasThrown).toBeTruthy();
|
|
1286
|
-
});
|
|
1287
|
-
|
|
1288
|
-
it('NullEventId', () => {
|
|
1289
|
-
//Arrange
|
|
1290
|
-
resetMocks();
|
|
1291
|
-
|
|
1292
|
-
const eventconfig = new QueueEventConfig('', '', '', '', false, 0, '', 0);
|
|
1293
|
-
eventconfig.cookieDomain = "cookieDomain";
|
|
1294
|
-
eventconfig.layoutName = "layoutName";
|
|
1295
|
-
eventconfig.culture = "culture";
|
|
1296
|
-
eventconfig.queueDomain = "queueDomain";
|
|
1297
|
-
eventconfig.extendCookieValidity = true;
|
|
1298
|
-
eventconfig.cookieValidityMinute = 10;
|
|
1299
|
-
eventconfig.version = 12;
|
|
1300
|
-
KnownUser.UserInQueueService = userInQueueServiceMock;
|
|
1301
|
-
|
|
1302
|
-
//Act
|
|
1303
|
-
const result = KnownUser.resolveQueueRequestByLocalConfig("targeturl", "queueIttoken", eventconfig, "customerid", "secretkey", httpContextMock);
|
|
1304
|
-
const exceptionWasThrown = result.second != null && result.second!.message == "queueConfig.eventId can not be null or empty.";
|
|
1305
|
-
|
|
1306
|
-
//Assert
|
|
1307
|
-
expect(userInQueueServiceMock.validateQueueRequestCall).toBeNull();
|
|
1308
|
-
expect(exceptionWasThrown).toBeTruthy();
|
|
1309
|
-
});
|
|
1310
|
-
|
|
1311
|
-
it('NullQueueDomain', () => {
|
|
1312
|
-
//Arrange
|
|
1313
|
-
resetMocks();
|
|
1314
|
-
|
|
1315
|
-
const eventconfig = new QueueEventConfig('', '', '', '', false, 0, '', 0);
|
|
1316
|
-
eventconfig.cookieDomain = "cookieDomain";
|
|
1317
|
-
eventconfig.layoutName = "layoutName";
|
|
1318
|
-
eventconfig.culture = "culture";
|
|
1319
|
-
eventconfig.eventId = "eventId";
|
|
1320
|
-
eventconfig.queueDomain = '';
|
|
1321
|
-
eventconfig.extendCookieValidity = true;
|
|
1322
|
-
eventconfig.cookieValidityMinute = 10;
|
|
1323
|
-
eventconfig.version = 12;
|
|
1324
|
-
KnownUser.UserInQueueService = userInQueueServiceMock;
|
|
1325
|
-
|
|
1326
|
-
//Act
|
|
1327
|
-
const result = KnownUser.resolveQueueRequestByLocalConfig("targeturl", "queueIttoken", eventconfig, "customerid", "secretkey", httpContextMock);
|
|
1328
|
-
const exceptionWasThrown = result.second != null && result.second!.message == "queueConfig.queueDomain can not be null or empty.";
|
|
1329
|
-
|
|
1330
|
-
//Assert
|
|
1331
|
-
expect(userInQueueServiceMock.validateQueueRequestCall).toBeNull();
|
|
1332
|
-
expect(exceptionWasThrown).toBeTruthy();
|
|
1333
|
-
});
|
|
1334
|
-
|
|
1335
|
-
it('InvalidCookieValidityMinute', () => {
|
|
1336
|
-
//Arrange
|
|
1337
|
-
resetMocks();
|
|
1338
|
-
|
|
1339
|
-
const eventconfig = new QueueEventConfig('', '', '', '', false, 0, '', 0);
|
|
1340
|
-
eventconfig.cookieDomain = "cookieDomain";
|
|
1341
|
-
eventconfig.layoutName = "layoutName";
|
|
1342
|
-
eventconfig.culture = "culture";
|
|
1343
|
-
eventconfig.eventId = "eventId";
|
|
1344
|
-
eventconfig.queueDomain = "queueDomain";
|
|
1345
|
-
eventconfig.extendCookieValidity = true;
|
|
1346
|
-
eventconfig.cookieValidityMinute = 0;
|
|
1347
|
-
eventconfig.version = 12;
|
|
1348
|
-
KnownUser.UserInQueueService = userInQueueServiceMock;
|
|
1349
|
-
|
|
1350
|
-
//Act
|
|
1351
|
-
const result = KnownUser.resolveQueueRequestByLocalConfig("targeturl", "queueIttoken", eventconfig, "customerid", "secretkey", httpContextMock);
|
|
1352
|
-
const exceptionWasThrown = result.second != null && result.second!.message == "queueConfig.cookieValidityMinute should be integer greater than 0.";
|
|
1353
|
-
|
|
1354
|
-
//Assert
|
|
1355
|
-
expect(userInQueueServiceMock.validateQueueRequestCall).toBeNull();
|
|
1356
|
-
expect(exceptionWasThrown).toBeTruthy();
|
|
1357
|
-
});
|
|
1358
|
-
|
|
1359
|
-
it('should have Debug cookie if token is present', () => {
|
|
1360
|
-
resetMocks();
|
|
1361
|
-
|
|
1362
|
-
const requestIP = "80.35.35.34";
|
|
1363
|
-
const viaHeader = "v";
|
|
1364
|
-
const forwardedHeader = "f";
|
|
1365
|
-
const xForwardedForHeader = "xff";
|
|
1366
|
-
const xForwardedHostHeader = "xfh";
|
|
1367
|
-
const xForwardedProtoHeader = "xfp";
|
|
1368
|
-
|
|
1369
|
-
httpContextMock.req.headers.set('via', viaHeader);
|
|
1370
|
-
httpContextMock.req.headers.set('forwarded', forwardedHeader);
|
|
1371
|
-
httpContextMock.req.headers.set('x-forwarded-for', xForwardedForHeader);
|
|
1372
|
-
httpContextMock.req.headers.set('x-forwarded-host', xForwardedHostHeader);
|
|
1373
|
-
httpContextMock.req.headers.set('x-forwarded-proto', xForwardedProtoHeader);
|
|
1374
|
-
|
|
1375
|
-
httpContextMock.req.setAbsoluteUri("http://test.com/?event1=true&queueittoken=queueittokenvalue");
|
|
1376
|
-
httpContextMock.req.setUserHostAddress(requestIP);
|
|
1377
|
-
|
|
1378
|
-
const secretKey = "secretKey";
|
|
1379
|
-
const queueitToken = generateDebugToken("eventId", secretKey);
|
|
1380
|
-
const dateTimeProviderMock = new MockDateTimeProvider();
|
|
1381
|
-
const expectedServerTime = toISOString(dateTimeProviderMock.getCurrentTime()).split('.')[0] + "Z";
|
|
1382
|
-
|
|
1383
|
-
const eventconfig = new QueueEventConfig('', '', '', '', false, 0, '', 0);
|
|
1384
|
-
eventconfig.cookieDomain = "cookieDomain";
|
|
1385
|
-
eventconfig.layoutName = "layoutName";
|
|
1386
|
-
eventconfig.culture = "culture";
|
|
1387
|
-
eventconfig.eventId = "eventId";
|
|
1388
|
-
eventconfig.queueDomain = "queueDomain";
|
|
1389
|
-
eventconfig.extendCookieValidity = true;
|
|
1390
|
-
eventconfig.cookieValidityMinute = 10;
|
|
1391
|
-
eventconfig.version = 12;
|
|
1392
|
-
eventconfig.actionName = "event1action";
|
|
1393
|
-
|
|
1394
|
-
KnownUser.UserInQueueService = userInQueueServiceMock;
|
|
1395
|
-
|
|
1396
|
-
const result = KnownUser.resolveQueueRequestByLocalConfig("http://test.com?event1=true",
|
|
1397
|
-
queueitToken,
|
|
1398
|
-
eventconfig,
|
|
1399
|
-
"customerId",
|
|
1400
|
-
secretKey,
|
|
1401
|
-
httpContextMock,
|
|
1402
|
-
dateTimeProviderMock);
|
|
1403
|
-
const actualCookieValue = httpContextMock.res.cookies.get(KnownUser.QueueITDebugKey).value;
|
|
1404
|
-
|
|
1405
|
-
expect(actualCookieValue.indexOf("QueueitToken=" + queueitToken)).not.toBe(-1);
|
|
1406
|
-
expect(actualCookieValue.indexOf("TargetUrl=http://test.com?event1=true")).not.toBe(-1);
|
|
1407
|
-
expect(actualCookieValue.indexOf("QueueitToken=" + queueitToken)).not.toBe(-1);
|
|
1408
|
-
expect(actualCookieValue.indexOf("OriginalUrl=http://test.com/?event1=true&queueittoken=queueittokenvalue")).not.toBe(-1);
|
|
1409
|
-
expect(actualCookieValue.indexOf("ServerUtcTime=" + expectedServerTime)).not.toBe(-1, 'Should contain ' + "ServerUtcTime=" + expectedServerTime);
|
|
1410
|
-
expect(actualCookieValue.indexOf("RequestIP=80.35.35.34")).not.toBe(-1);
|
|
1411
|
-
expect(actualCookieValue.indexOf("RequestHttpHeader_Via=v")).not.toBe(-1);
|
|
1412
|
-
expect(actualCookieValue.indexOf("RequestHttpHeader_Forwarded=f")).not.toBe(-1);
|
|
1413
|
-
expect(actualCookieValue.indexOf("RequestHttpHeader_XForwardedFor=xff")).not.toBe(-1);
|
|
1414
|
-
expect(actualCookieValue.indexOf("RequestHttpHeader_XForwardedHost=xfh")).not.toBe(-1);
|
|
1415
|
-
expect(actualCookieValue.indexOf("RequestHttpHeader_XForwardedProto=xfp")).not.toBe(-1);
|
|
1416
|
-
expect(actualCookieValue.indexOf("QueueConfig=EventId:eventId&Version:12&ActionName:event1action&QueueDomain:queueDomain&CookieDomain:cookieDomain&ExtendCookieValidity:true&CookieValidityMinute:10&LayoutName:layoutName&Culture:culture")).not.toBe(-1);
|
|
1417
|
-
});
|
|
1418
|
-
|
|
1419
|
-
it('should Debug_NullConfig', () => {
|
|
1420
|
-
resetMocks();
|
|
1421
|
-
|
|
1422
|
-
httpContextMock.req.setAbsoluteUri("http://test.com?event1=true");
|
|
1423
|
-
httpContextMock.req.setUserHostAddress("userIP");
|
|
1424
|
-
mockGoogleHeaders();
|
|
1425
|
-
|
|
1426
|
-
const secretKey = "secretKey";
|
|
1427
|
-
const queueitToken = generateDebugToken("eventId", secretKey);
|
|
1428
|
-
// const expectedServerTime = (new Date(Date.now())).toISOString().split('.')[0] + "Z";
|
|
1429
|
-
KnownUser.UserInQueueService = userInQueueServiceMock;
|
|
1430
|
-
|
|
1431
|
-
const result = KnownUser.resolveQueueRequestByLocalConfig("http://test.com?event1=true", queueitToken, null, "customerId", secretKey, httpContextMock);
|
|
1432
|
-
const errorReturned = result.second != null && result.second!.message == 'queueConfig can not be null.';
|
|
1433
|
-
expect(errorReturned).toBeTruthy();
|
|
1434
|
-
|
|
1435
|
-
//Assert
|
|
1436
|
-
expect(userInQueueServiceMock.validateQueueRequestCall).toBeNull();
|
|
1437
|
-
|
|
1438
|
-
const actualCookieValue = httpContextMock.res.cookies.get(KnownUser.QueueITDebugKey).value
|
|
1439
|
-
expect(actualCookieValue.indexOf("QueueConfig=NULL|")).not.toBe(-1);
|
|
1440
|
-
expect(actualCookieValue.indexOf("OriginalUrl=http://test.com?event1=true|")).not.toBe(-1);
|
|
1441
|
-
expect(actualCookieValue.indexOf("QueueitToken=" + queueitToken + "|")).not.toBe(-1);
|
|
1442
|
-
expect(actualCookieValue.indexOf("SdkVersion=" + SDK_VERSION + "|")).not.toBe(-1);
|
|
1443
|
-
expect(actualCookieValue.indexOf("Exception=queueConfig can not be null.")).not.toBe(-1);
|
|
1444
|
-
});
|
|
1445
|
-
|
|
1446
|
-
it('should Debug_Missing_CustomerId', () => {
|
|
1447
|
-
resetMocks();
|
|
1448
|
-
const eventconfig = new QueueEventConfig('', '', '', '', false, 0, '', 0);
|
|
1449
|
-
httpContextMock.req.setAbsoluteUri("http://localhost/original_url");
|
|
1450
|
-
httpContextMock.req.setUserHostAddress("userIP");
|
|
1451
|
-
mockGoogleHeaders();
|
|
1452
|
-
|
|
1453
|
-
const secretKey = "secretKey";
|
|
1454
|
-
const queueitToken = generateDebugToken("eventId", secretKey);
|
|
1455
|
-
// const expectedServerTime = (new Date(Date.now())).toISOString().split('.')[0] + "Z";
|
|
1456
|
-
KnownUser.UserInQueueService = userInQueueServiceMock;
|
|
1457
|
-
|
|
1458
|
-
const result = KnownUser.resolveQueueRequestByLocalConfig("http://test.com?event1=true", queueitToken, eventconfig, '', secretKey, httpContextMock);
|
|
1459
|
-
//Assert
|
|
1460
|
-
expect("https://api2.queue-it.net/diagnostics/connector/error/?code=setup" == result.first!.redirectUrl);
|
|
1461
|
-
expect(httpContextMock.res.cookies.has(KnownUser.QueueITDebugKey)).toBeFalsy('debug cookie should not be set');
|
|
1462
|
-
});
|
|
1463
|
-
|
|
1464
|
-
it('should Debug_Missing_SecretKey', () => {
|
|
1465
|
-
resetMocks();
|
|
1466
|
-
const eventconfig = new QueueEventConfig('', '', '', '', false, 0, '', 0);
|
|
1467
|
-
httpContextMock.req.setAbsoluteUri("http://localhost/original_url");
|
|
1468
|
-
httpContextMock.req.setUserHostAddress("userIP");
|
|
1469
|
-
mockGoogleHeaders();
|
|
1470
|
-
|
|
1471
|
-
const secretKey = "secretKey";
|
|
1472
|
-
const queueitToken = generateDebugToken("eventId", secretKey);
|
|
1473
|
-
// const expectedServerTime = (new Date(Date.now())).toISOString().split('.')[0] + "Z";
|
|
1474
|
-
KnownUser.UserInQueueService = userInQueueServiceMock;
|
|
1475
|
-
|
|
1476
|
-
const result = KnownUser.resolveQueueRequestByLocalConfig("http://test.com?event1=true", queueitToken, eventconfig, "customerId", '', httpContextMock);
|
|
1477
|
-
|
|
1478
|
-
//Assert
|
|
1479
|
-
expect(result.first!.redirectUrl).toBe('https://api2.queue-it.net/diagnostics/connector/error/?code=setup');
|
|
1480
|
-
expect(httpContextMock.res.cookies.has(KnownUser.QueueITDebugKey)).toBeFalsy('debug cookie should not be set');
|
|
1481
|
-
});
|
|
1482
|
-
|
|
1483
|
-
it('should Debug_ExpiredToken', () => {
|
|
1484
|
-
resetMocks();
|
|
1485
|
-
|
|
1486
|
-
const eventconfig = new QueueEventConfig('', '', '', '', false, 0, '', 0);
|
|
1487
|
-
httpContextMock.req.setAbsoluteUri("http://localhost/original_url");
|
|
1488
|
-
httpContextMock.req.setUserHostAddress("userIP");
|
|
1489
|
-
mockGoogleHeaders();
|
|
1490
|
-
|
|
1491
|
-
const secretKey = "secretKey";
|
|
1492
|
-
const queueitToken = generateDebugToken("eventId", secretKey, true);
|
|
1493
|
-
// const expectedServerTime = (new Date(Date.now())).toISOString().split('.')[0] + "Z";
|
|
1494
|
-
KnownUser.UserInQueueService = userInQueueServiceMock;
|
|
1495
|
-
|
|
1496
|
-
const result = KnownUser.resolveQueueRequestByLocalConfig("http://test.com?event1=true", queueitToken, eventconfig, "customerId", secretKey, httpContextMock);
|
|
1497
|
-
|
|
1498
|
-
//Assert
|
|
1499
|
-
expect(result.first!.redirectUrl).toBe('https://customerId.api2.queue-it.net/customerId/diagnostics/connector/error/?code=timestamp');
|
|
1500
|
-
expect(httpContextMock.res.cookies.has(KnownUser.QueueITDebugKey)).toBeFalsy('debug cookie should not be set');
|
|
1501
|
-
});
|
|
1502
|
-
|
|
1503
|
-
it('should Debug_ModifiedToken', () => {
|
|
1504
|
-
resetMocks();
|
|
1505
|
-
const eventconfig = new QueueEventConfig('', '', '', '', false, 0, '', 0);
|
|
1506
|
-
httpContextMock.req.setAbsoluteUri("http://localhost/original_url");
|
|
1507
|
-
httpContextMock.req.setUserHostAddress("userIP");
|
|
1508
|
-
mockGoogleHeaders();
|
|
1509
|
-
|
|
1510
|
-
const secretKey = "secretKey";
|
|
1511
|
-
const queueitToken = generateDebugToken("eventId", secretKey) + "invalid-hash";
|
|
1512
|
-
// const expectedServerTime = (new Date(Date.now())).toISOString().split('.')[0] + "Z";
|
|
1513
|
-
KnownUser.UserInQueueService = userInQueueServiceMock;
|
|
1514
|
-
|
|
1515
|
-
const result = KnownUser.resolveQueueRequestByLocalConfig("http://test.com?event1=true", queueitToken, eventconfig, "customerId", secretKey, httpContextMock);
|
|
1516
|
-
|
|
1517
|
-
//Assert
|
|
1518
|
-
expect(result.first!.redirectUrl).toBe('https://customerId.api2.queue-it.net/customerId/diagnostics/connector/error/?code=hash');
|
|
1519
|
-
expect(httpContextMock.res.cookies.has(KnownUser.QueueITDebugKey)).toBeFalsy('debug cookie should not be set');
|
|
1520
|
-
});
|
|
1521
|
-
|
|
1522
|
-
it('should Exception_NoDebugToken', () => {
|
|
1523
|
-
resetMocks();
|
|
1524
|
-
|
|
1525
|
-
const requestIP = "80.35.35.34";
|
|
1526
|
-
const viaHeader = "v";
|
|
1527
|
-
const forwardedHeader = "f";
|
|
1528
|
-
const xForwardedForHeader = "xff";
|
|
1529
|
-
const xForwardedHostHeader = "xfh";
|
|
1530
|
-
const xForwardedProtoHeader = "xfp";
|
|
1531
|
-
|
|
1532
|
-
httpContextMock.req.headers.set('via', viaHeader);
|
|
1533
|
-
httpContextMock.req.headers.set('forwarded', forwardedHeader);
|
|
1534
|
-
httpContextMock.req.headers.set('x-forwarded-for', xForwardedForHeader);
|
|
1535
|
-
httpContextMock.req.headers.set('x-forwarded-host', xForwardedHostHeader);
|
|
1536
|
-
httpContextMock.req.headers.set('x-forwarded-proto', xForwardedProtoHeader);
|
|
1537
|
-
|
|
1538
|
-
httpContextMock.req.setAbsoluteUri("http://test.com/?event1=true&queueittoken=queueittokenvalue");
|
|
1539
|
-
httpContextMock.req.setUserHostAddress(requestIP);
|
|
1540
|
-
|
|
1541
|
-
const secretKey = "secretKey";
|
|
1542
|
-
const queueitToken = generateDebugToken("eventId", secretKey);
|
|
1543
|
-
const expectedServerTime = toISOString(new Date(Date.now())).split('.')[0] + "Z";
|
|
1544
|
-
|
|
1545
|
-
const eventconfig = new QueueEventConfig('', '', '', '', false, 0, '', 0);
|
|
1546
|
-
eventconfig.cookieDomain = "cookieDomain";
|
|
1547
|
-
eventconfig.layoutName = "layoutName";
|
|
1548
|
-
eventconfig.culture = "culture";
|
|
1549
|
-
eventconfig.eventId = "eventId";
|
|
1550
|
-
eventconfig.queueDomain = "queueDomain";
|
|
1551
|
-
eventconfig.extendCookieValidity = true;
|
|
1552
|
-
eventconfig.cookieValidityMinute = 10;
|
|
1553
|
-
eventconfig.version = 12;
|
|
1554
|
-
eventconfig.actionName = "event1action";
|
|
1555
|
-
|
|
1556
|
-
userInQueueServiceMock.validateQueueRequestResultRaiseException = true;
|
|
1557
|
-
KnownUser.UserInQueueService = userInQueueServiceMock;
|
|
1558
|
-
|
|
1559
|
-
//Act
|
|
1560
|
-
const result = KnownUser.resolveQueueRequestByLocalConfig("http://test.com?event1=true", "queueitToken", eventconfig, "customerId", secretKey, httpContextMock);
|
|
1561
|
-
|
|
1562
|
-
//Assert
|
|
1563
|
-
expect(result.first).toBeNull();
|
|
1564
|
-
expect(result.second).not.toBeNull();
|
|
1565
|
-
expect(httpContextMock.res.cookies.has(KnownUser.QueueITDebugKey)).toBeFalsy();
|
|
1566
|
-
});
|
|
1567
|
-
})
|
|
1568
|
-
|
|
1569
|
-
describe('cancelRequestByLocalConfig', () => {
|
|
1570
|
-
it('should work for non-ajax requests', () => {
|
|
1571
|
-
resetMocks();
|
|
1572
|
-
|
|
1573
|
-
const cancelEventConfig = new CancelEventConfig("", "", "", 0);
|
|
1574
|
-
cancelEventConfig.cookieDomain = "cookieDomain";
|
|
1575
|
-
cancelEventConfig.eventId = "eventId";
|
|
1576
|
-
cancelEventConfig.queueDomain = "queueDomain";
|
|
1577
|
-
cancelEventConfig.version = 1;
|
|
1578
|
-
|
|
1579
|
-
KnownUser.UserInQueueService = userInQueueServiceMock;
|
|
1580
|
-
const result = KnownUser.cancelRequestByLocalConfig("url", "queueitToken", cancelEventConfig, "customerid", "secretkey", httpContextMock);
|
|
1581
|
-
|
|
1582
|
-
expect(userInQueueServiceMock.validateCancelRequestCall!.method).toBe('validateCancelRequest');
|
|
1583
|
-
expect(userInQueueServiceMock.validateCancelRequestCall!.targetUrl).toBe('url');
|
|
1584
|
-
expect(userInQueueServiceMock.validateCancelRequestCall!.cancelConfig).toBe(cancelEventConfig);
|
|
1585
|
-
expect(userInQueueServiceMock.validateCancelRequestCall!.customerId).toBe('customerid');
|
|
1586
|
-
expect(userInQueueServiceMock.validateCancelRequestCall!.secretKey).toBe('secretkey');
|
|
1587
|
-
expect(result.first!.isAjaxResult).toBeFalsy();
|
|
1588
|
-
});
|
|
1589
|
-
|
|
1590
|
-
it('should AjaxCall', () => {
|
|
1591
|
-
resetMocks();
|
|
1592
|
-
|
|
1593
|
-
const cancelEventConfig = new CancelEventConfig('', '', '', 0);
|
|
1594
|
-
cancelEventConfig.cookieDomain = "cookieDomain";
|
|
1595
|
-
cancelEventConfig.eventId = "eventId";
|
|
1596
|
-
cancelEventConfig.queueDomain = "queueDomain";
|
|
1597
|
-
cancelEventConfig.version = 1;
|
|
1598
|
-
|
|
1599
|
-
KnownUser.UserInQueueService = userInQueueServiceMock;
|
|
1600
|
-
const result = KnownUser.cancelRequestByLocalConfig("url", "queueitToken", cancelEventConfig, "customerid", "secretkey", httpContextMock);
|
|
1601
|
-
|
|
1602
|
-
expect(userInQueueServiceMock.validateCancelRequestCall!.method).toBe('validateCancelRequest');
|
|
1603
|
-
expect(userInQueueServiceMock.validateCancelRequestCall!.targetUrl).toBe('url');
|
|
1604
|
-
expect(userInQueueServiceMock.validateCancelRequestCall!.cancelConfig).toBe(cancelEventConfig);
|
|
1605
|
-
expect(userInQueueServiceMock.validateCancelRequestCall!.customerId).toBe('customerid');
|
|
1606
|
-
expect(userInQueueServiceMock.validateCancelRequestCall!.secretKey).toBe('secretkey');
|
|
1607
|
-
expect(result.first!.isAjaxResult).toBeFalsy();
|
|
1608
|
-
});
|
|
1609
|
-
|
|
1610
|
-
it('should NullQueueDomain', () => {
|
|
1611
|
-
//Arrange
|
|
1612
|
-
resetMocks();
|
|
1613
|
-
|
|
1614
|
-
const cancelEventConfig = new CancelEventConfig('', '', '', 0);
|
|
1615
|
-
cancelEventConfig.eventId = "eventId";
|
|
1616
|
-
cancelEventConfig.cookieDomain = "cookieDomain";
|
|
1617
|
-
cancelEventConfig.version = 12;
|
|
1618
|
-
|
|
1619
|
-
//Act
|
|
1620
|
-
let result = KnownUser.cancelRequestByLocalConfig("targetUrl", "queueitToken", cancelEventConfig, "customerId", "secretKey", httpContextMock);
|
|
1621
|
-
let exceptionWasThrown = result.second != null && result.second!.message == "cancelConfig.queueDomain can not be null or empty.";
|
|
1622
|
-
|
|
1623
|
-
//Assert
|
|
1624
|
-
expect(userInQueueServiceMock.validateCancelRequestCall).toBeNull();
|
|
1625
|
-
expect(exceptionWasThrown).toBeTruthy();
|
|
1626
|
-
});
|
|
1627
|
-
|
|
1628
|
-
it('should EventIdNull', () => {
|
|
1629
|
-
//Arrange
|
|
1630
|
-
resetMocks();
|
|
1631
|
-
|
|
1632
|
-
const cancelEventConfig = new CancelEventConfig('', '', '', 0);
|
|
1633
|
-
cancelEventConfig.cookieDomain = "cookieDomain";
|
|
1634
|
-
cancelEventConfig.version = 12;
|
|
1635
|
-
|
|
1636
|
-
//Act
|
|
1637
|
-
const result = KnownUser.cancelRequestByLocalConfig("targetUrl", "queueitToken", cancelEventConfig, "customerId", "secretKey", httpContextMock);
|
|
1638
|
-
const exceptionWasThrown = result.second != null && result.second!.message == "cancelConfig.eventId can not be null or empty.";
|
|
1639
|
-
|
|
1640
|
-
//Assert
|
|
1641
|
-
expect(userInQueueServiceMock.validateCancelRequestCall).toBeNull();
|
|
1642
|
-
expect(exceptionWasThrown).toBeTruthy();
|
|
1643
|
-
});
|
|
1644
|
-
|
|
1645
|
-
it('should CancelEventConfigNull', () => {
|
|
1646
|
-
//Arrange
|
|
1647
|
-
resetMocks();
|
|
1648
|
-
|
|
1649
|
-
//Act
|
|
1650
|
-
const result = KnownUser.cancelRequestByLocalConfig("targetUrl", "queueitToken", null, "customerId", "secretKey", httpContextMock);
|
|
1651
|
-
const exceptionWasThrown = result.second != null && result.second!.message == "cancelConfig can not be null.";
|
|
1652
|
-
|
|
1653
|
-
//Assert
|
|
1654
|
-
expect(userInQueueServiceMock.validateCancelRequestCall).toBeNull();
|
|
1655
|
-
expect(exceptionWasThrown).toBeTruthy();
|
|
1656
|
-
});
|
|
1657
|
-
|
|
1658
|
-
it('should CustomerIdNull', () => {
|
|
1659
|
-
//Arrange
|
|
1660
|
-
resetMocks();
|
|
1661
|
-
|
|
1662
|
-
const eventconfig = new CancelEventConfig('', '', '', 0);
|
|
1663
|
-
|
|
1664
|
-
//Act
|
|
1665
|
-
const result = KnownUser.cancelRequestByLocalConfig("targetUrl", "queueitToken", eventconfig, '', "secretKey", httpContextMock);
|
|
1666
|
-
const exceptionWasThrown = result.second != null && result.second!.message == "customerId can not be null or empty.";
|
|
1667
|
-
|
|
1668
|
-
//Assert
|
|
1669
|
-
expect(userInQueueServiceMock.validateCancelRequestCall).toBeNull();
|
|
1670
|
-
expect(exceptionWasThrown).toBeTruthy();
|
|
1671
|
-
});
|
|
1672
|
-
|
|
1673
|
-
it('should SecretKeyNull', () => {
|
|
1674
|
-
//Arrange
|
|
1675
|
-
resetMocks();
|
|
1676
|
-
const eventconfig = new CancelEventConfig('', '', '', 0);
|
|
1677
|
-
|
|
1678
|
-
//Act
|
|
1679
|
-
const result = KnownUser.cancelRequestByLocalConfig("targetUrl", "queueitToken", eventconfig, "customerid", '', httpContextMock);
|
|
1680
|
-
const exceptionWasThrown = result.second != null && result.second!.message == "secretKey can not be null or empty.";
|
|
1681
|
-
|
|
1682
|
-
//Assert
|
|
1683
|
-
expect(userInQueueServiceMock.validateCancelRequestCall).toBeNull();
|
|
1684
|
-
expect(exceptionWasThrown).toBeTruthy();
|
|
1685
|
-
});
|
|
1686
|
-
|
|
1687
|
-
it('should TargetUrl', () => {
|
|
1688
|
-
//Arrange
|
|
1689
|
-
resetMocks();
|
|
1690
|
-
const eventconfig = new CancelEventConfig('', '', '', 0);
|
|
1691
|
-
|
|
1692
|
-
//Act
|
|
1693
|
-
const result = KnownUser.cancelRequestByLocalConfig('', "queueitToken", eventconfig, "customerid", "secretkey", httpContextMock);
|
|
1694
|
-
const exceptionWasThrown = result.second != null && result.second!.message == "targetUrl can not be null or empty.";
|
|
1695
|
-
|
|
1696
|
-
//Assert
|
|
1697
|
-
expect(userInQueueServiceMock.validateCancelRequestCall).toBeNull();
|
|
1698
|
-
expect(exceptionWasThrown).toBeTruthy();
|
|
1699
|
-
})
|
|
1700
|
-
|
|
1701
|
-
it('should Debug', () => {
|
|
1702
|
-
resetMocks();
|
|
1703
|
-
|
|
1704
|
-
const requestIP = "80.35.35.34";
|
|
1705
|
-
const viaHeader = "1.1 example.com";
|
|
1706
|
-
const forwardedHeader = "for=192.0.2.60;proto=http;by=203.0.113.43";
|
|
1707
|
-
const xForwardedForHeader = "129.78.138.66, 129.78.64.103";
|
|
1708
|
-
const xForwardedHostHeader = "en.wikipedia.org:8080";
|
|
1709
|
-
const xForwardedProtoHeader = "https";
|
|
1710
|
-
|
|
1711
|
-
httpContextMock.req.headers.set('via', viaHeader);
|
|
1712
|
-
httpContextMock.req.headers.set('forwarded', forwardedHeader);
|
|
1713
|
-
httpContextMock.req.headers.set('x-forwarded-for', xForwardedForHeader);
|
|
1714
|
-
httpContextMock.req.headers.set('x-forwarded-host', xForwardedHostHeader);
|
|
1715
|
-
httpContextMock.req.headers.set('x-forwarded-proto', xForwardedProtoHeader);
|
|
1716
|
-
httpContextMock.req.setAbsoluteUri("http://test.com/?event1=true&queueittoken=queueittokenvalue");
|
|
1717
|
-
httpContextMock.req.setUserHostAddress(requestIP);
|
|
1718
|
-
|
|
1719
|
-
const secretKey = "secretKey";
|
|
1720
|
-
const queueitToken = generateDebugToken("eventId", secretKey);
|
|
1721
|
-
const dateTimeProviderMock = new MockDateTimeProvider();
|
|
1722
|
-
const expectedServerTime = toISOString(dateTimeProviderMock.getCurrentTime()).split('.')[0] + "Z";
|
|
1723
|
-
|
|
1724
|
-
const cancelEventconfig = new CancelEventConfig('', '', '', 0);
|
|
1725
|
-
cancelEventconfig.cookieDomain = "cookieDomain";
|
|
1726
|
-
cancelEventconfig.eventId = "eventId";
|
|
1727
|
-
cancelEventconfig.queueDomain = "queueDomain";
|
|
1728
|
-
cancelEventconfig.version = 1;
|
|
1729
|
-
|
|
1730
|
-
KnownUser.UserInQueueService = userInQueueServiceMock;
|
|
1731
|
-
const result = KnownUser.cancelRequestByLocalConfig("http://test.com?event1=true",
|
|
1732
|
-
queueitToken,
|
|
1733
|
-
cancelEventconfig,
|
|
1734
|
-
"customerid",
|
|
1735
|
-
"secretKey",
|
|
1736
|
-
httpContextMock,
|
|
1737
|
-
dateTimeProviderMock);
|
|
1738
|
-
|
|
1739
|
-
const actualCookieValue = httpContextMock.res.cookies.get(KnownUser.QueueITDebugKey).value;
|
|
1740
|
-
|
|
1741
|
-
expect(userInQueueServiceMock.validateCancelRequestCall!.method).toBe('validateCancelRequest');
|
|
1742
|
-
expect(userInQueueServiceMock.validateCancelRequestCall!.targetUrl).toBe('http://test.com?event1=true');
|
|
1743
|
-
expect(userInQueueServiceMock.validateCancelRequestCall!.cancelConfig).toBe(cancelEventconfig);
|
|
1744
|
-
expect(userInQueueServiceMock.validateCancelRequestCall!.customerId).toBe('customerid');
|
|
1745
|
-
expect(userInQueueServiceMock.validateCancelRequestCall!.secretKey).toBe('secretKey');
|
|
1746
|
-
expect(result.first!.isAjaxResult).toBeFalsy();
|
|
1747
|
-
|
|
1748
|
-
expect(actualCookieValue.indexOf("QueueitToken=" + queueitToken)).not.toBe(-1)
|
|
1749
|
-
expect(actualCookieValue.indexOf("OriginalUrl=http://test.com/?event1=true&queueittoken=queueittokenvalue")).not.toBe(-1)
|
|
1750
|
-
expect(actualCookieValue.indexOf("TargetUrl=http://test.com?event1=true")).not.toBe(-1)
|
|
1751
|
-
expect(actualCookieValue.indexOf("QueueitToken=" + queueitToken)).not.toBe(-1)
|
|
1752
|
-
expect(actualCookieValue.indexOf("ServerUtcTime=" + expectedServerTime)).not.toBe(-1)
|
|
1753
|
-
expect(actualCookieValue.indexOf("RequestIP=80.35.35.34")).not.toBe(-1)
|
|
1754
|
-
expect(actualCookieValue.indexOf("RequestHttpHeader_Via=1.1 example.com")).not.toBe(-1)
|
|
1755
|
-
expect(actualCookieValue.indexOf("RequestHttpHeader_Forwarded=for=192.0.2.60;proto=http;by=203.0.113.43")).not.toBe(-1)
|
|
1756
|
-
expect(actualCookieValue.indexOf("RequestHttpHeader_XForwardedFor=129.78.138.66, 129.78.64.103")).not.toBe(-1)
|
|
1757
|
-
expect(actualCookieValue.indexOf("RequestHttpHeader_XForwardedHost=en.wikipedia.org:8080")).not.toBe(-1)
|
|
1758
|
-
expect(actualCookieValue.indexOf("RequestHttpHeader_XForwardedProto=https")).not.toBe(-1)
|
|
1759
|
-
expect(actualCookieValue.indexOf("EventId:eventId&Version:1&QueueDomain:queueDomain&CookieDomain:cookieDomain")).not.toBe(-1);
|
|
1760
|
-
});
|
|
1761
|
-
|
|
1762
|
-
it('should Debug_NullConfig', () => {
|
|
1763
|
-
resetMocks();
|
|
1764
|
-
|
|
1765
|
-
httpContextMock.req.setAbsoluteUri("http://test.com?event1=true");
|
|
1766
|
-
httpContextMock.req.setUserHostAddress("userIP");
|
|
1767
|
-
mockGoogleHeaders();
|
|
1768
|
-
|
|
1769
|
-
const secretKey = "secretKey";
|
|
1770
|
-
const queueitToken = generateDebugToken("eventId", secretKey);
|
|
1771
|
-
// const expectedServerTime = (new Date(Date.now())).toISOString().split('.')[0] + "Z";
|
|
1772
|
-
KnownUser.UserInQueueService = userInQueueServiceMock;
|
|
1773
|
-
|
|
1774
|
-
const result = KnownUser.cancelRequestByLocalConfig("http://test.com?event1=true", queueitToken, null, "customerId", secretKey, httpContextMock);
|
|
1775
|
-
const errorReturned = result.second != null && result.second!.message == "cancelConfig can not be null.";
|
|
1776
|
-
|
|
1777
|
-
//Assert
|
|
1778
|
-
expect(userInQueueServiceMock.validateQueueRequestCall).toBeNull();
|
|
1779
|
-
expect(errorReturned).toBeTruthy();
|
|
1780
|
-
const actualCookieValue = httpContextMock.res.cookies.get(KnownUser.QueueITDebugKey).value;
|
|
1781
|
-
expect(actualCookieValue.indexOf("CancelConfig=NULL|")).not.toBe(-1);
|
|
1782
|
-
expect(actualCookieValue.indexOf("OriginalUrl=http://test.com?event1=true|")).not.toBe(-1);
|
|
1783
|
-
expect(actualCookieValue.indexOf("QueueitToken=" + queueitToken + "|")).not.toBe(-1);
|
|
1784
|
-
expect(actualCookieValue.indexOf("SdkVersion=" + SDK_VERSION + "|")).not.toBe(-1);
|
|
1785
|
-
expect(actualCookieValue.indexOf("Exception=cancelConfig can not be null.")).not.toBe(-1);
|
|
1786
|
-
});
|
|
1787
|
-
|
|
1788
|
-
it('should Debug_Missing_CustomerId', () => {
|
|
1789
|
-
resetMocks();
|
|
1790
|
-
const cancelConfig = new CancelEventConfig('', '', '', 0);
|
|
1791
|
-
httpContextMock.req.setAbsoluteUri("http://localhost/original_url");
|
|
1792
|
-
httpContextMock.req.setUserHostAddress("userIP");
|
|
1793
|
-
mockGoogleHeaders();
|
|
1794
|
-
|
|
1795
|
-
const secretKey = "secretKey";
|
|
1796
|
-
const queueitToken = generateDebugToken("eventId", secretKey);
|
|
1797
|
-
// const expectedServerTime = (new Date(Date.now())).toISOString().split('.')[0] + "Z";
|
|
1798
|
-
KnownUser.UserInQueueService = userInQueueServiceMock;
|
|
1799
|
-
|
|
1800
|
-
const result = KnownUser.cancelRequestByLocalConfig("http://test.com?event1=true", queueitToken, cancelConfig, '', secretKey, httpContextMock);
|
|
1801
|
-
//Assert
|
|
1802
|
-
expect("https://api2.queue-it.net/diagnostics/connector/error/?code=setup" == result.first!.redirectUrl);
|
|
1803
|
-
expect(httpContextMock.res.cookies.has(KnownUser.QueueITDebugKey)).toBeFalsy('debug cookie should not be set');
|
|
1804
|
-
});
|
|
1805
|
-
|
|
1806
|
-
it('should Debug_Missing_SecretKey', () => {
|
|
1807
|
-
resetMocks();
|
|
1808
|
-
const cancelConfig = new CancelEventConfig('', '', '', 0);
|
|
1809
|
-
httpContextMock.req.setAbsoluteUri("http://localhost/original_url");
|
|
1810
|
-
httpContextMock.req.setUserHostAddress("userIP");
|
|
1811
|
-
mockGoogleHeaders();
|
|
1812
|
-
|
|
1813
|
-
const secretKey = "secretKey";
|
|
1814
|
-
const queueitToken = generateDebugToken("eventId", secretKey);
|
|
1815
|
-
// const expectedServerTime = (new Date(Date.now())).toISOString().split('.')[0] + "Z";
|
|
1816
|
-
KnownUser.UserInQueueService = userInQueueServiceMock;
|
|
1817
|
-
|
|
1818
|
-
const result = KnownUser.cancelRequestByLocalConfig("http://test.com?event1=true", queueitToken, cancelConfig, "customerId", '', httpContextMock);
|
|
1819
|
-
//Assert
|
|
1820
|
-
expect("https://api2.queue-it.net/diagnostics/connector/error/?code=setup" == result.first!.redirectUrl);
|
|
1821
|
-
expect(httpContextMock.res.cookies.has(KnownUser.QueueITDebugKey)).toBeFalsy('debug cookie should not be set');
|
|
1822
|
-
});
|
|
1823
|
-
|
|
1824
|
-
it('should Debug_ExpiredToken', () => {
|
|
1825
|
-
resetMocks();
|
|
1826
|
-
const cancelConfig = new CancelEventConfig('', '', '', 0);
|
|
1827
|
-
httpContextMock.req.setAbsoluteUri("http://localhost/original_url");
|
|
1828
|
-
httpContextMock.req.setUserHostAddress("userIP");
|
|
1829
|
-
mockGoogleHeaders();
|
|
1830
|
-
|
|
1831
|
-
const secretKey = "secretKey";
|
|
1832
|
-
const queueitToken = generateDebugToken("eventId", secretKey, true);
|
|
1833
|
-
// const expectedServerTime = (new Date(Date.now())).toISOString().split('.')[0] + "Z";
|
|
1834
|
-
KnownUser.UserInQueueService = userInQueueServiceMock;
|
|
1835
|
-
|
|
1836
|
-
const result = KnownUser.cancelRequestByLocalConfig("http://test.com?event1=true", queueitToken, cancelConfig, "customerId", secretKey, httpContextMock);
|
|
1837
|
-
//Assert
|
|
1838
|
-
expect("https://customerId.api2.queue-it.net/customerId/diagnostics/connector/error/?code=timestamp" == result.first!.redirectUrl);
|
|
1839
|
-
expect(httpContextMock.res.cookies.has(KnownUser.QueueITDebugKey)).toBeFalsy('debug cookie should not be set');
|
|
1840
|
-
});
|
|
1841
|
-
|
|
1842
|
-
it('should Debug_ModifiedToken', () => {
|
|
1843
|
-
resetMocks();
|
|
1844
|
-
const cancelConfig = new CancelEventConfig('', '', '', 0);
|
|
1845
|
-
httpContextMock.req.setAbsoluteUri("http://localhost/original_url");
|
|
1846
|
-
httpContextMock.req.setUserHostAddress("userIP");
|
|
1847
|
-
mockGoogleHeaders();
|
|
1848
|
-
|
|
1849
|
-
const secretKey = "secretKey";
|
|
1850
|
-
const queueitToken = generateDebugToken("eventId", secretKey) + "invalid-hash";
|
|
1851
|
-
// const expectedServerTime = (new Date(Date.now())).toISOString().split('.')[0] + "Z";
|
|
1852
|
-
KnownUser.UserInQueueService = userInQueueServiceMock;
|
|
1853
|
-
|
|
1854
|
-
const result = KnownUser.cancelRequestByLocalConfig("http://test.com?event1=true", queueitToken, cancelConfig, "customerId", secretKey, httpContextMock);
|
|
1855
|
-
//Assert
|
|
1856
|
-
expect("https://customerId.api2.queue-it.net/customerId/diagnostics/connector/error/?code=hash" == result.first!.redirectUrl);
|
|
1857
|
-
expect(httpContextMock.res.cookies.has(KnownUser.QueueITDebugKey)).toBeFalsy('debug cookie should not be set');
|
|
1858
|
-
});
|
|
1859
|
-
|
|
1860
|
-
it('should Exception_NoDebugToken', () => {
|
|
1861
|
-
resetMocks();
|
|
1862
|
-
|
|
1863
|
-
const requestIP = "80.35.35.34";
|
|
1864
|
-
const viaHeader = "1.1 example.com";
|
|
1865
|
-
const forwardedHeader = "for=192.0.2.60;proto=http;by=203.0.113.43";
|
|
1866
|
-
const xForwardedForHeader = "129.78.138.66, 129.78.64.103";
|
|
1867
|
-
const xForwardedHostHeader = "en.wikipedia.org:8080";
|
|
1868
|
-
const xForwardedProtoHeader = "https";
|
|
1869
|
-
|
|
1870
|
-
httpContextMock.req.headers.set('via', viaHeader);
|
|
1871
|
-
httpContextMock.req.headers.set('forwarded', forwardedHeader);
|
|
1872
|
-
httpContextMock.req.headers.set('x-forwarded-for', xForwardedForHeader);
|
|
1873
|
-
httpContextMock.req.headers.set('x-forwarded-host', xForwardedHostHeader);
|
|
1874
|
-
httpContextMock.req.headers.set('x-forwarded-proto', xForwardedProtoHeader);
|
|
1875
|
-
|
|
1876
|
-
httpContextMock.req.setAbsoluteUri("http://test.com/?event1=true&queueittoken=queueittokenvalue");
|
|
1877
|
-
httpContextMock.req.setUserHostAddress(requestIP);
|
|
1878
|
-
|
|
1879
|
-
const secretKey = "secretKey";
|
|
1880
|
-
|
|
1881
|
-
const cancelEventconfig = new CancelEventConfig('', '', '', 0);
|
|
1882
|
-
cancelEventconfig.cookieDomain = "cookieDomain";
|
|
1883
|
-
cancelEventconfig.eventId = "eventId";
|
|
1884
|
-
cancelEventconfig.queueDomain = "queueDomain";
|
|
1885
|
-
cancelEventconfig.version = 1;
|
|
1886
|
-
userInQueueServiceMock.validateCancelRequestrRaiseException = true;
|
|
1887
|
-
KnownUser.UserInQueueService = userInQueueServiceMock;
|
|
1888
|
-
|
|
1889
|
-
const result = KnownUser.cancelRequestByLocalConfig("http://test.com?event1=true",
|
|
1890
|
-
"queueitToken", cancelEventconfig, "customerid", "secretKey", httpContextMock);
|
|
1891
|
-
|
|
1892
|
-
expect(httpContextMock.res.cookies.has(KnownUser.QueueITDebugKey)).toBeFalsy('debug cookie should not be set');
|
|
1893
|
-
});
|
|
1894
|
-
});
|