@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,321 +0,0 @@
|
|
|
1
|
-
import {IDateTimeProvider, IHttpContextProvider, IHttpRequest, IHttpResponse} from "../sdk/HttpContextProvider";
|
|
2
|
-
import {StateInfo, UserInQueueStateCookieRepository} from "../sdk/UserInQueueStateCookieRepository";
|
|
3
|
-
import {UserInQueueService} from "../sdk/UserInQueueService";
|
|
4
|
-
import {
|
|
5
|
-
CancelEventConfig,
|
|
6
|
-
KnownUserException,
|
|
7
|
-
QueueEventConfig,
|
|
8
|
-
RequestValidationResult,
|
|
9
|
-
ValidationResult
|
|
10
|
-
} from "../sdk/Models";
|
|
11
|
-
import { Headers } from "@fastly/as-compute";
|
|
12
|
-
import {encodeURIComponent} from "../sdk/helpers/Uri";
|
|
13
|
-
import {toUTCString} from "../sdk/helpers/Date";
|
|
14
|
-
|
|
15
|
-
export class MockHttpRequest implements IHttpRequest {
|
|
16
|
-
headers: Map<string, string> = new Map<string, string>();
|
|
17
|
-
cookies: Map<string, MockCookie> = new Map<string, MockCookie>();
|
|
18
|
-
private userHostAddress: string = "";
|
|
19
|
-
private absoluteUri: string = "";
|
|
20
|
-
private body: string = "";
|
|
21
|
-
|
|
22
|
-
getAbsoluteUri(): string {
|
|
23
|
-
return this.absoluteUri;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
setAbsoluteUri(value: string): void {
|
|
27
|
-
this.absoluteUri = value;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
getCookieValue(cookieKey: string): string {
|
|
31
|
-
if(!this.cookies.has(cookieKey)){
|
|
32
|
-
return ''
|
|
33
|
-
}
|
|
34
|
-
return this.cookies.get(cookieKey).value;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
setCookieValue(name: string, value: string): MockHttpRequest {
|
|
38
|
-
this.cookies.set(name, new MockCookie(value, '', 0));
|
|
39
|
-
return this;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
setCookie(name: string, cookie: MockCookie): MockHttpRequest {
|
|
43
|
-
this.cookies.set(name, cookie);
|
|
44
|
-
return this;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
setHeader(name: string, value: string): MockHttpRequest {
|
|
48
|
-
this.headers.set(name, value);
|
|
49
|
-
return this;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
getHeader(name: string): string {
|
|
53
|
-
return this.headers.has(name.toLowerCase()) ? this.headers.get(name.toLowerCase()) : '';
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
setBody(body: string): void {
|
|
57
|
-
this.body = body;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
getRequestBodyAsString(): string {
|
|
61
|
-
return this.body;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
getUserAgent(): string {
|
|
65
|
-
return this.headers.has('user-agent') ? this.headers.get('user-agent') : 'mocked-user-agent';
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
setUserAgent(value: string): MockHttpRequest {
|
|
69
|
-
this.headers.set("user-agent", value);
|
|
70
|
-
return this;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
getUserHostAddress(): string {
|
|
74
|
-
return this.userHostAddress;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
setUserHostAddress(value: string): void {
|
|
78
|
-
this.userHostAddress = value;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
reset(): void {
|
|
82
|
-
this.userHostAddress = "";
|
|
83
|
-
this.absoluteUri = "";
|
|
84
|
-
this.body = "";
|
|
85
|
-
this.headers.clear();
|
|
86
|
-
this.cookies.clear();
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export class MockCookie {
|
|
91
|
-
constructor(public value: string, public domain: string, public expiration: i64) {
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export class MockHttpResponse implements IHttpResponse {
|
|
97
|
-
cookies: Map<string, MockCookie> = new Map();
|
|
98
|
-
private cookieHeader: string = '';
|
|
99
|
-
|
|
100
|
-
setCookie(cookieName: string, cookieValue: string, domain: string, expiration: i64): void {
|
|
101
|
-
const expirationDate = new Date(expiration * 1000);
|
|
102
|
-
let setCookieString = cookieName + "=" + encodeURIComponent(cookieValue) + "; expires=" + toUTCString(expirationDate) + ";";
|
|
103
|
-
if (domain != "") {
|
|
104
|
-
setCookieString += " domain=" + domain + ";";
|
|
105
|
-
}
|
|
106
|
-
setCookieString += " path=/;";
|
|
107
|
-
this.cookieHeader = setCookieString;
|
|
108
|
-
this.cookies.set(cookieName, new MockCookie(cookieValue, domain, expiration))
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
reset(): void {
|
|
112
|
-
this.cookies.clear();
|
|
113
|
-
this.cookieHeader = '';
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
getHeaders(): Headers {
|
|
117
|
-
let h = new Headers();
|
|
118
|
-
h.set('set-cookie', this.cookieHeader);
|
|
119
|
-
return h;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export class MockDateTimeProvider implements IDateTimeProvider {
|
|
124
|
-
public constructor(public date: Date = new Date(Date.now())) {
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
getCurrentTime(): Date {
|
|
128
|
-
return this.date;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
export class MockHttpContextProvider implements IHttpContextProvider {
|
|
133
|
-
constructor(public req: MockHttpRequest, public res: MockHttpResponse) {
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
getHttpRequest(): IHttpRequest {
|
|
137
|
-
return this.req != null ? this.req : new MockHttpRequest();
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
getHttpResponse(): IHttpResponse {
|
|
141
|
-
return this.res != null ? this.res : new MockHttpResponse();
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
reset(): void {
|
|
145
|
-
this.req.reset();
|
|
146
|
-
this.res.reset();
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export class ValidateQueueRequestCall {
|
|
151
|
-
public constructor(
|
|
152
|
-
public method: string,
|
|
153
|
-
public targetUrl: string,
|
|
154
|
-
public queueitToken: string,
|
|
155
|
-
public queueConfig: QueueEventConfig,
|
|
156
|
-
public customerId: string,
|
|
157
|
-
public secretKey: string
|
|
158
|
-
) {
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export class ValidateCancelRequestCall {
|
|
163
|
-
public constructor(
|
|
164
|
-
public method: string,
|
|
165
|
-
public targetUrl: string,
|
|
166
|
-
public cancelConfig: CancelEventConfig,
|
|
167
|
-
public customerId: string,
|
|
168
|
-
public secretKey: string
|
|
169
|
-
) {
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
export class RequestValidationResultRecording {
|
|
174
|
-
public constructor(
|
|
175
|
-
public method: string,
|
|
176
|
-
public eventId: string,
|
|
177
|
-
public queueId: string,
|
|
178
|
-
public redirectUrl: string,
|
|
179
|
-
public redirectType: string,
|
|
180
|
-
public actionType: string,
|
|
181
|
-
public actionName: string
|
|
182
|
-
) {
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
export class ExtendQueueCookieCall {
|
|
187
|
-
public constructor(
|
|
188
|
-
public method: string,
|
|
189
|
-
public eventId: string,
|
|
190
|
-
public cookieValidityMinute: i64,
|
|
191
|
-
public cookieDomain: string,
|
|
192
|
-
public secretKey: string
|
|
193
|
-
) {
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
export class UserInQueueServiceMock extends UserInQueueService {
|
|
198
|
-
validateQueueRequestResult: RequestValidationResult;
|
|
199
|
-
cancelRequestCalls: Map<string, string>;
|
|
200
|
-
extendQueueCookieCalls: Map<string, string>;
|
|
201
|
-
validateQueueRequestCall: ValidateQueueRequestCall | null;
|
|
202
|
-
validateCancelRequestCall: ValidateCancelRequestCall | null;
|
|
203
|
-
extendQueueCookieCall: ExtendQueueCookieCall | null;
|
|
204
|
-
getIgnoreResultIsCalled: bool;
|
|
205
|
-
validateCancelRequestrRaiseException: bool;
|
|
206
|
-
validateQueueRequestResultRaiseException: bool;
|
|
207
|
-
requestValidationResult: RequestValidationResultRecording | null;
|
|
208
|
-
|
|
209
|
-
constructor(private repo: UserInQueueStateCookieRepository) {
|
|
210
|
-
super(repo);
|
|
211
|
-
this.validateQueueRequestResult = new RequestValidationResult("", "", "", "", "");
|
|
212
|
-
this.cancelRequestCalls = new Map<string, string>();
|
|
213
|
-
this.extendQueueCookieCalls = new Map<string, string>();
|
|
214
|
-
this.getIgnoreResultIsCalled = false;
|
|
215
|
-
this.validateCancelRequestrRaiseException = false;
|
|
216
|
-
this.validateQueueRequestResultRaiseException = false;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
getIgnoreResult(actionName: string): RequestValidationResult {
|
|
220
|
-
this.getIgnoreResultIsCalled = true;
|
|
221
|
-
|
|
222
|
-
const r = new RequestValidationResultRecording("getIgnoreResult", '', '', '', '', 'Ignore', actionName);
|
|
223
|
-
this.requestValidationResult = r;
|
|
224
|
-
const result = new RequestValidationResult(r.actionType, r.eventId, r.queueId, r.redirectUrl, r.redirectType, r.actionName);
|
|
225
|
-
return result;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
validateQueueRequest(targetUrl: string, queueitToken: string, queueConfig: QueueEventConfig,
|
|
229
|
-
customerId: string, secretKey: string): ValidationResult {
|
|
230
|
-
this.validateQueueRequestCall = new ValidateQueueRequestCall(
|
|
231
|
-
"validateQueueRequest",
|
|
232
|
-
targetUrl,
|
|
233
|
-
queueitToken,
|
|
234
|
-
queueConfig,
|
|
235
|
-
customerId,
|
|
236
|
-
secretKey);
|
|
237
|
-
|
|
238
|
-
if (this.validateQueueRequestResultRaiseException) {
|
|
239
|
-
return new ValidationResult(null, new KnownUserException("mocked exception"))
|
|
240
|
-
} else {
|
|
241
|
-
return new ValidationResult(this.validateQueueRequestResult, null);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
validateCancelRequest(targetUrl: string,
|
|
246
|
-
cancelConfig: CancelEventConfig,
|
|
247
|
-
customerId: string,
|
|
248
|
-
secretKey: string): ValidationResult {
|
|
249
|
-
this.validateCancelRequestCall = new ValidateCancelRequestCall('validateCancelRequest', targetUrl, cancelConfig, customerId, secretKey);
|
|
250
|
-
|
|
251
|
-
if (this.validateCancelRequestrRaiseException) {
|
|
252
|
-
return new ValidationResult(null, new KnownUserException("mocked exception"));
|
|
253
|
-
} else {
|
|
254
|
-
return new ValidationResult(new RequestValidationResult('Cancel', '', '', '', ''), null);
|
|
255
|
-
}
|
|
256
|
-
};
|
|
257
|
-
|
|
258
|
-
extendQueueCookie(
|
|
259
|
-
eventId: string,
|
|
260
|
-
cookieValidityMinutes: i64,
|
|
261
|
-
cookieDomain: string,
|
|
262
|
-
secretKey: string): void {
|
|
263
|
-
this.extendQueueCookieCall = new ExtendQueueCookieCall('extendQueueCookie', eventId, cookieValidityMinutes, cookieDomain, secretKey);
|
|
264
|
-
//return this.extendQueueCookieCalls;
|
|
265
|
-
};
|
|
266
|
-
|
|
267
|
-
reset(): void {
|
|
268
|
-
//this.validateQueueRequestResult = null;
|
|
269
|
-
this.validateQueueRequestResult = new RequestValidationResult("", "", "", "", "");
|
|
270
|
-
this.cancelRequestCalls.clear();
|
|
271
|
-
this.extendQueueCookieCalls.clear();
|
|
272
|
-
this.validateQueueRequestCall = null;
|
|
273
|
-
this.validateCancelRequestCall = null;
|
|
274
|
-
this.extendQueueCookieCall = null;
|
|
275
|
-
this.validateCancelRequestrRaiseException = false;
|
|
276
|
-
this.validateQueueRequestResultRaiseException = false;
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
export class UserInQueueStateCookieRepositoryMock extends UserInQueueStateCookieRepository {
|
|
281
|
-
returnThisState: StateInfo
|
|
282
|
-
storeCall: Map<string, string>
|
|
283
|
-
getStateCall: Map<string, string>
|
|
284
|
-
cancelQueueCookieCall: Map<string, string>
|
|
285
|
-
|
|
286
|
-
constructor() {
|
|
287
|
-
super(new MockHttpContextProvider(new MockHttpRequest(), new MockHttpResponse()));
|
|
288
|
-
this.returnThisState = new StateInfo(false, false, "", 0, "")
|
|
289
|
-
this.storeCall = new Map<string, string>();
|
|
290
|
-
this.getStateCall = new Map<string, string>();
|
|
291
|
-
this.cancelQueueCookieCall = new Map<string, string>();
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
getState(eventId: string, cookieValidityMinutes: i64, secretKey: string, validateTime: bool): StateInfo {
|
|
295
|
-
this.getStateCall.set("eventId", eventId);
|
|
296
|
-
this.getStateCall.set("cookieValidityMinutes", cookieValidityMinutes.toString());
|
|
297
|
-
this.getStateCall.set("secretKey", secretKey);
|
|
298
|
-
this.getStateCall.set("validateTime", validateTime.toString());
|
|
299
|
-
return this.returnThisState;
|
|
300
|
-
};
|
|
301
|
-
|
|
302
|
-
store(eventId: string, queueId: string, fixedCookieValidityMinutes: i64, cookieDomain: string, redirectType: string, secretKey: string): void {
|
|
303
|
-
this.storeCall.set("eventId", eventId);
|
|
304
|
-
this.storeCall.set("queueId", queueId);
|
|
305
|
-
this.storeCall.set("fixedCookieValidityMinutes", fixedCookieValidityMinutes.toString());
|
|
306
|
-
this.storeCall.set("cookieDomain", cookieDomain);
|
|
307
|
-
this.storeCall.set("redirectType", redirectType);
|
|
308
|
-
this.storeCall.set("secretKey", secretKey);
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
cancelQueueCookie(eventId: string, cookieDomain: string): void {
|
|
312
|
-
this.cancelQueueCookieCall.set("eventId", eventId);
|
|
313
|
-
this.cancelQueueCookieCall.set("cookieDomain", cookieDomain);
|
|
314
|
-
};
|
|
315
|
-
|
|
316
|
-
reset(): void {
|
|
317
|
-
this.getStateCall.clear();
|
|
318
|
-
this.storeCall.clear();
|
|
319
|
-
this.cancelQueueCookieCall.clear();
|
|
320
|
-
}
|
|
321
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import {QueueParameterHelper, Utils} from "../sdk/QueueITHelpers";
|
|
2
|
-
|
|
3
|
-
describe('utils', ()=>{
|
|
4
|
-
it('should be able to encode WR IDs', ()=>{
|
|
5
|
-
const encodedURL = Utils.encodeUrl('e1');
|
|
6
|
-
|
|
7
|
-
expect(encodedURL).toBe('e1');
|
|
8
|
-
})
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
describe("parameter helper", () => {
|
|
12
|
-
it('can extract queue params', () => {
|
|
13
|
-
const queueitToken = 'ts_1480593661~cv_10~ce_false~q_944c1f44-60dd-4e37-aabc-f3e4bb1c8895~c_customerid~e_eventid~rt_disabled~h_218b734e-d5be-4b60-ad66-9b1b326266e2';
|
|
14
|
-
let result = QueueParameterHelper.extractQueueParams(queueitToken);
|
|
15
|
-
|
|
16
|
-
expect(result).not.toBeNull('result should be parsed');
|
|
17
|
-
expect<i64>(result!.timeStamp).toBe(1480593661)
|
|
18
|
-
expect(result!.eventId).toBe("eventid");
|
|
19
|
-
expect(result!.cookieValidityMinutes).toBe(10);
|
|
20
|
-
expect(result!.extendableCookie).toBeFalsy();
|
|
21
|
-
expect(result!.hashCode).toBe('218b734e-d5be-4b60-ad66-9b1b326266e2', 'hash should be extracted');
|
|
22
|
-
expect(result!.queueITToken).toBe(queueitToken);
|
|
23
|
-
expect(result!.queueITTokenWithoutHash).toBe('ts_1480593661~cv_10~ce_false~q_944c1f44-60dd-4e37-aabc-f3e4bb1c8895~c_customerid~e_eventid~rt_disabled');
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('can handle non-valid formats', () => {
|
|
27
|
-
const queueITToken = 'ts_sasa~cv_adsasa~ce_falwwwse~q_944c1f44-60dd-4e37-aabc-f3e4bb1c8895~h_218b734e-d5be-4b60-ad66-9b1b326266e2';
|
|
28
|
-
const queueitTokenWithoutHash = 'ts_sasa~cv_adsasa~ce_falwwwse~q_944c1f44-60dd-4e37-aabc-f3e4bb1c8895';
|
|
29
|
-
const result = QueueParameterHelper.extractQueueParams(queueITToken);
|
|
30
|
-
|
|
31
|
-
expect(result!.timeStamp).toBe(0);
|
|
32
|
-
expect(result!.eventId).toBeFalsy();
|
|
33
|
-
expect(result!.cookieValidityMinutes).toBe(0);
|
|
34
|
-
expect(result!.extendableCookie).toBeFalsy();
|
|
35
|
-
expect(result!.hashCode).toBe('218b734e-d5be-4b60-ad66-9b1b326266e2');
|
|
36
|
-
expect(result!.queueITToken).toBe(queueITToken);
|
|
37
|
-
expect(result!.queueITTokenWithoutHash).toBe(queueitTokenWithoutHash);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('can use queueittoken with no values', ()=>{
|
|
41
|
-
const queueITToken = "e~q~ts~ce~rt~h";
|
|
42
|
-
const result = QueueParameterHelper.extractQueueParams(queueITToken);
|
|
43
|
-
|
|
44
|
-
expect(result!.timeStamp).toBe(0);
|
|
45
|
-
expect(result!.eventId).toBeFalsy();
|
|
46
|
-
expect(result!.cookieValidityMinutes).toBe(0);
|
|
47
|
-
expect(result!.extendableCookie).toBeFalsy();
|
|
48
|
-
expect(result!.hashCode).toBeFalsy();
|
|
49
|
-
expect(result!.queueITToken).toBe(queueITToken);
|
|
50
|
-
expect(result!.queueITTokenWithoutHash).toBe(queueITToken);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('returns null when no queueittoken is given', ()=>{
|
|
54
|
-
const queueITToken = "";
|
|
55
|
-
const result = QueueParameterHelper.extractQueueParams(queueITToken);
|
|
56
|
-
|
|
57
|
-
expect(result).toBeNull();
|
|
58
|
-
});
|
|
59
|
-
});
|