@webda/aws 2.0.0-beta.3 → 2.0.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.
Files changed (71) hide show
  1. package/lib/deployers/cloudformation.d.ts +2 -2
  2. package/lib/deployers/cloudformation.js +672 -693
  3. package/lib/deployers/cloudformation.js.map +1 -1
  4. package/lib/deployers/cloudformation.spec.js +428 -477
  5. package/lib/deployers/cloudformation.spec.js.map +1 -1
  6. package/lib/deployers/index.js +282 -342
  7. package/lib/deployers/index.js.map +1 -1
  8. package/lib/deployers/index.spec.d.ts +1 -1
  9. package/lib/deployers/index.spec.js +445 -510
  10. package/lib/deployers/index.spec.js.map +1 -1
  11. package/lib/deployers/lambda-entrypoint.js +4 -16
  12. package/lib/deployers/lambda-entrypoint.js.map +1 -1
  13. package/lib/deployers/lambdapackager.js +13 -52
  14. package/lib/deployers/lambdapackager.js.map +1 -1
  15. package/lib/deployers/lambdapackager.spec.js +25 -61
  16. package/lib/deployers/lambdapackager.spec.js.map +1 -1
  17. package/lib/index.d.ts +1 -1
  18. package/lib/index.js +1 -17
  19. package/lib/index.js.map +1 -1
  20. package/lib/index.spec.d.ts +1 -1
  21. package/lib/index.spec.js +28 -75
  22. package/lib/index.spec.js.map +1 -1
  23. package/lib/services/aws-mixin.d.ts +2 -0
  24. package/lib/services/aws-mixin.js +2 -7
  25. package/lib/services/aws-mixin.js.map +1 -1
  26. package/lib/services/cloudwatchlogger.d.ts +3 -1
  27. package/lib/services/cloudwatchlogger.js +63 -104
  28. package/lib/services/cloudwatchlogger.js.map +1 -1
  29. package/lib/services/cloudwatchlogger.spec.js +57 -100
  30. package/lib/services/cloudwatchlogger.spec.js.map +1 -1
  31. package/lib/services/dynamodb.d.ts +4 -2
  32. package/lib/services/dynamodb.js +457 -498
  33. package/lib/services/dynamodb.js.map +1 -1
  34. package/lib/services/dynamodb.spec.d.ts +2 -2
  35. package/lib/services/dynamodb.spec.js +232 -302
  36. package/lib/services/dynamodb.spec.js.map +1 -1
  37. package/lib/services/index.d.ts +9 -9
  38. package/lib/services/index.js +8 -24
  39. package/lib/services/index.js.map +1 -1
  40. package/lib/services/lambdacaller.d.ts +2 -0
  41. package/lib/services/lambdacaller.js +15 -29
  42. package/lib/services/lambdacaller.js.map +1 -1
  43. package/lib/services/lambdacaller.spec.js +43 -81
  44. package/lib/services/lambdacaller.spec.js.map +1 -1
  45. package/lib/services/lambdaserver.js +168 -190
  46. package/lib/services/lambdaserver.js.map +1 -1
  47. package/lib/services/lambdaserver.spec.js +266 -354
  48. package/lib/services/lambdaserver.spec.js.map +1 -1
  49. package/lib/services/route53.js +112 -137
  50. package/lib/services/route53.js.map +1 -1
  51. package/lib/services/route53.spec.js +56 -92
  52. package/lib/services/route53.spec.js.map +1 -1
  53. package/lib/services/s3binary.d.ts +6 -2
  54. package/lib/services/s3binary.js +189 -251
  55. package/lib/services/s3binary.js.map +1 -1
  56. package/lib/services/s3binary.spec.js +185 -254
  57. package/lib/services/s3binary.spec.js.map +1 -1
  58. package/lib/services/secretsmanager.d.ts +2 -0
  59. package/lib/services/secretsmanager.js +32 -56
  60. package/lib/services/secretsmanager.js.map +1 -1
  61. package/lib/services/secretsmanager.spec.js +50 -93
  62. package/lib/services/secretsmanager.spec.js.map +1 -1
  63. package/lib/services/sqsqueue.d.ts +5 -7
  64. package/lib/services/sqsqueue.js +70 -99
  65. package/lib/services/sqsqueue.js.map +1 -1
  66. package/lib/services/sqsqueue.spec.js +95 -145
  67. package/lib/services/sqsqueue.spec.js.map +1 -1
  68. package/lib/shell.js +19 -38
  69. package/lib/shell.js.map +1 -1
  70. package/package.json +12 -9
  71. package/webda.module.json +48 -0
@@ -1,449 +1,361 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
1
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
2
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
3
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
4
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
23
6
  };
24
- var __importStar = (this && this.__importStar) || function (mod) {
25
- if (mod && mod.__esModule) return mod;
26
- var result = {};
27
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
- __setModuleDefault(result, mod);
29
- return result;
30
- };
31
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
32
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
33
- return new (P || (P = Promise))(function (resolve, reject) {
34
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
35
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
36
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
37
- step((generator = generator.apply(thisArg, _arguments || [])).next());
38
- });
39
- };
40
- Object.defineProperty(exports, "__esModule", { value: true });
41
- const mocha_1 = require("@testdeck/mocha");
42
- const core_1 = require("@webda/core");
43
- const test_1 = require("@webda/core/lib/test");
44
- const assert = __importStar(require("assert"));
45
- const fs = __importStar(require("fs"));
46
- const index_spec_1 = require("../index.spec");
47
- const lambdaserver_1 = require("./lambdaserver");
48
- let ExceptionExecutor = class ExceptionExecutor extends core_1.Service {
7
+ import { suite, test } from "@testdeck/mocha";
8
+ import { Bean, getCommonJS, HttpContext, Route, Service } from "@webda/core";
9
+ import { TestApplication } from "@webda/core/lib/test.js";
10
+ import * as assert from "assert";
11
+ import * as fs from "fs";
12
+ import { checkLocalStack, WebdaAwsTest } from "../index.spec.js";
13
+ import { LambdaServer } from "./lambdaserver.js";
14
+ const { __dirname } = getCommonJS(import.meta.url);
15
+ let ExceptionExecutor = class ExceptionExecutor extends Service {
49
16
  initRoutes() {
17
+ super.initRoutes();
50
18
  this.addRoute("/broken/{type}", ["GET"], this._brokenRoute);
51
19
  this.addRoute("/route/string", ["GET"], this.onString);
52
20
  }
53
- _brokenRoute(ctx) {
54
- return __awaiter(this, void 0, void 0, function* () {
55
- if (ctx.parameters.type === "401") {
56
- throw 401;
57
- }
58
- else if (ctx.parameters.type === "Error") {
59
- throw new Error();
60
- }
61
- });
21
+ async _brokenRoute(ctx) {
22
+ if (ctx.parameters.type === "401") {
23
+ throw 401;
24
+ }
25
+ else if (ctx.parameters.type === "Error") {
26
+ throw new Error();
27
+ }
62
28
  }
63
- onString(ctx) {
64
- return __awaiter(this, void 0, void 0, function* () {
65
- ctx.write(`CodeCoverage${ctx.getParameters().test || ""}`);
66
- });
29
+ async onString(ctx) {
30
+ ctx.write(`CodeCoverage${ctx.getParameters().test || ""}`);
67
31
  }
68
- onParamString(ctx) {
69
- return __awaiter(this, void 0, void 0, function* () {
70
- ctx.write(`CodeCoverage${ctx.getParameters().uuid}${ctx.getParameters().test || ""}`);
71
- });
32
+ async onParamString(ctx) {
33
+ ctx.write(`CodeCoverage${ctx.getParameters().uuid}${ctx.getParameters().test || ""}`);
72
34
  }
73
35
  };
74
36
  __decorate([
75
- (0, core_1.Route)("/route/broken/{type}")
37
+ Route("/route/broken/{type}")
76
38
  ], ExceptionExecutor.prototype, "_brokenRoute", null);
77
39
  __decorate([
78
- (0, core_1.Route)("/route/string{?test}")
40
+ Route("/route/string{?test}")
79
41
  ], ExceptionExecutor.prototype, "onString", null);
80
42
  __decorate([
81
- (0, core_1.Route)("/route/param/{uuid}{?test}")
43
+ Route("/route/param/{uuid}{?test}")
82
44
  ], ExceptionExecutor.prototype, "onParamString", null);
83
45
  ExceptionExecutor = __decorate([
84
- core_1.Bean
46
+ Bean
85
47
  ], ExceptionExecutor);
86
- let LambdaHandlerTest = class LambdaHandlerTest extends index_spec_1.WebdaAwsTest {
48
+ let LambdaHandlerTest = class LambdaHandlerTest extends WebdaAwsTest {
87
49
  constructor() {
88
50
  super(...arguments);
89
51
  this.context = {};
90
52
  this.badCheck = false;
91
53
  }
92
- before() {
93
- return __awaiter(this, void 0, void 0, function* () {
94
- yield (0, index_spec_1.checkLocalStack)();
95
- let app = new test_1.TestApplication(this.getTestConfiguration());
96
- app.addService("test/awsevents", (yield Promise.resolve().then(() => __importStar(require("../../test/moddas/awsevents.js")))).default);
97
- yield app.load();
98
- this.webda = this.handler = new lambdaserver_1.LambdaServer(app);
99
- this.webda.initStatics();
100
- this.webda.registerRequestFilter({
101
- checkRequest: () => __awaiter(this, void 0, void 0, function* () { return true; })
102
- });
103
- this.evt = {
104
- httpMethod: "GET",
105
- headers: {
106
- Cookie: "webda=plop;",
107
- "X-Forwarded-Port": "443",
108
- "X-Forwarded-Proto": "https"
109
- },
110
- requestContext: {
111
- identity: {}
112
- },
113
- path: "/prefix/route/string",
114
- resource: "/route/string",
115
- body: JSON.stringify({})
116
- };
117
- this.debugMailer = this.handler.getService("DebugMailer");
118
- });
119
- }
120
- checkRequestFalse() {
121
- return __awaiter(this, void 0, void 0, function* () {
122
- yield this.handler.init();
123
- // @ts-ignore
124
- this.handler._requestFilters = [];
125
- this.ensureGoodCSRF();
126
- this.evt.queryStringParameters = { test: "Plop" };
127
- let res = yield this.handler.handleRequest(this.evt, this.context);
128
- assert.strictEqual(res.statusCode, 403);
129
- });
130
- }
131
- handleRequestCustomLaunch() {
132
- return __awaiter(this, void 0, void 0, function* () {
133
- yield this.handler.handleRequest({
134
- command: "launch",
135
- service: "DebugMailer",
136
- method: "send",
137
- args: ["test"]
138
- }, undefined);
139
- assert.strictEqual(this.debugMailer.sent[0], "test");
140
- });
141
- }
142
- handleRequestCustomLaunchBadService() {
143
- return __awaiter(this, void 0, void 0, function* () {
144
- yield this.handler.handleRequest({
145
- command: "launch",
146
- service: "DebugMailers",
147
- method: "send",
148
- args: ["test"]
149
- }, undefined);
150
- assert.strictEqual(this.debugMailer.sent.length, 0);
151
- });
152
- }
153
- handleRequestCustomLaunchBadMethod() {
154
- return __awaiter(this, void 0, void 0, function* () {
155
- yield this.handler.handleRequest({
156
- command: "launch",
157
- service: "DebugMailer",
158
- method: "sends"
159
- }, undefined);
160
- assert.strictEqual(this.debugMailer.sent.length, 0);
161
- });
162
- }
163
- handleRequestKnownRoute() {
164
- return __awaiter(this, void 0, void 0, function* () {
165
- this.ensureGoodCSRF();
166
- let res = yield this.handler.handleRequest(this.evt, this.context);
167
- assert.strictEqual(res.body, "CodeCoverage");
168
- });
169
- }
170
- handleRequestIdHeader() {
171
- return __awaiter(this, void 0, void 0, function* () {
172
- this.ensureGoodCSRF();
173
- this.handler.getConfiguration().parameters.lambdaRequestHeader = "x-webda-request-id";
174
- let res = yield this.handler.handleRequest(this.evt, Object.assign(Object.assign({}, this.context), { awsRequestId: "toto" }));
175
- assert.strictEqual(res.body, "CodeCoverage");
176
- assert.strictEqual(res.headers["x-webda-request-id"], "toto");
177
- });
178
- }
179
- handleRequestKnownRouteWithParamAndQuery() {
180
- return __awaiter(this, void 0, void 0, function* () {
181
- this.ensureGoodCSRF();
182
- this.evt.queryStringParameters = { test: "Plop" };
183
- this.evt.path = "/prefix/route/param/myid";
184
- this.evt.resource = "/route/param/{uuid}";
185
- this.evt.pathParameters = { uuid: "myid" };
186
- let res = yield this.handler.handleRequest(this.evt, this.context);
187
- assert.strictEqual(res.body, "CodeCoveragemyidPlop");
188
- });
189
- }
190
- handleRequestKnownRouteWithParam() {
191
- return __awaiter(this, void 0, void 0, function* () {
192
- this.ensureGoodCSRF();
193
- this.evt.path = "/prefix/route/param/myid";
194
- this.evt.resource = "/route/param/{uuid}";
195
- this.evt.pathParameters = { uuid: "myid" };
196
- let res = yield this.handler.handleRequest(this.evt, this.context);
197
- assert.strictEqual(res.body, "CodeCoveragemyid");
198
- });
199
- }
200
- handleRequestKnownRouteWithQuery() {
201
- return __awaiter(this, void 0, void 0, function* () {
202
- this.ensureGoodCSRF();
203
- this.evt.queryStringParameters = { test: "Plop" };
204
- let res = yield this.handler.handleRequest(this.evt, this.context);
205
- assert.strictEqual(res.body, "CodeCoveragePlop");
206
- });
207
- }
208
- handleRequestUnknownRoute() {
209
- return __awaiter(this, void 0, void 0, function* () {
210
- this.ensureGoodCSRF();
211
- this.evt.path = "/route/unknown";
212
- this.evt.resource = "/route/unknown";
213
- delete this.evt.headers.Cookie;
214
- let res = yield this.handler.handleRequest(this.evt, this.context);
215
- assert.strictEqual(res.statusCode, 404);
216
- });
217
- }
218
- handleRequestThrow401() {
219
- return __awaiter(this, void 0, void 0, function* () {
220
- this.ensureGoodCSRF();
221
- this.evt.path = "/route/broken/401";
222
- this.evt.resource = "/route/broken/401";
223
- let res = yield this.handler.handleRequest(this.evt, this.context);
224
- assert.strictEqual(res.statusCode, 401);
225
- });
226
- }
227
- handleRequestThrowError() {
228
- return __awaiter(this, void 0, void 0, function* () {
229
- this.ensureGoodCSRF();
230
- this.evt.path = "/route/broken/Error";
231
- let res = yield this.handler.handleRequest(this.evt, this.context);
232
- assert.strictEqual(res.statusCode, 500);
233
- });
234
- }
235
- handleRequestOPTIONS() {
236
- return __awaiter(this, void 0, void 0, function* () {
237
- this.ensureGoodCSRF();
238
- this.evt.httpMethod = "OPTIONS";
239
- let res = yield this.handler.handleRequest(this.evt, this.context);
240
- assert.strictEqual(res.statusCode, 204);
241
- assert.strictEqual(res.headers["Access-Control-Allow-Methods"], "GET,OPTIONS");
242
- });
243
- }
244
- handleRequestOPTIONSWith404() {
245
- return __awaiter(this, void 0, void 0, function* () {
246
- this.ensureGoodCSRF();
247
- this.evt.path = "/route/unknown";
248
- this.evt.httpMethod = "OPTIONS";
249
- let res = yield this.handler.handleRequest(this.evt, this.context);
250
- assert.strictEqual(res.statusCode, 404);
251
- });
252
- }
253
- cov() {
254
- return __awaiter(this, void 0, void 0, function* () {
255
- this.ensureGoodCSRF();
256
- this.evt.headers["X-Forwarded-Port"] = "wew";
257
- this.evt.headers["Content-Type"] = "text/plain";
258
- this.evt.body = "{wew''";
259
- // Should fallback on port 443
260
- yield this.handler.handleRequest(this.evt, this.context);
261
- });
262
- }
263
- handleRequestQueryParams() {
264
- return __awaiter(this, void 0, void 0, function* () {
265
- // TODO Check parameter retrieval
266
- this.evt.queryStringParameters = {
267
- test: "plop"
268
- };
269
- this.evt.headers.Origin = "https://test.webda.io";
270
- this.evt.headers.Host = "test.webda.io";
271
- yield this.handler.handleRequest(this.evt, this.context);
54
+ async before() {
55
+ await checkLocalStack();
56
+ let app = new TestApplication(this.getTestConfiguration());
57
+ app.addService("test/awsevents", (await import("../../test/moddas/awsevents.js")).AWSEventsHandler);
58
+ await app.load();
59
+ this.webda = this.handler = new LambdaServer(app);
60
+ await this.webda.init();
61
+ this.webda.registerRequestFilter({
62
+ checkRequest: async () => true
272
63
  });
64
+ this.evt = {
65
+ httpMethod: "GET",
66
+ headers: {
67
+ Cookie: "webda=plop;",
68
+ "X-Forwarded-Port": "443",
69
+ "X-Forwarded-Proto": "https"
70
+ },
71
+ requestContext: {
72
+ identity: {}
73
+ },
74
+ path: "/prefix/route/string",
75
+ resource: "/route/string",
76
+ body: JSON.stringify({})
77
+ };
78
+ this.debugMailer = this.handler.getService("DebugMailer");
79
+ }
80
+ async checkRequestFalse() {
81
+ await this.handler.init();
82
+ // @ts-ignore
83
+ this.handler._requestFilters = [];
84
+ this.ensureGoodCSRF();
85
+ this.evt.queryStringParameters = { test: "Plop" };
86
+ let res = await this.handler.handleRequest(this.evt, this.context);
87
+ assert.strictEqual(res.statusCode, 403);
88
+ }
89
+ async handleRequestCustomLaunch() {
90
+ await this.handler.handleRequest({
91
+ command: "launch",
92
+ service: "DebugMailer",
93
+ method: "send",
94
+ args: ["test"]
95
+ }, undefined);
96
+ assert.strictEqual(this.debugMailer.sent[0], "test");
97
+ }
98
+ async handleRequestCustomLaunchBadService() {
99
+ await this.handler.handleRequest({
100
+ command: "launch",
101
+ service: "DebugMailers",
102
+ method: "send",
103
+ args: ["test"]
104
+ }, undefined);
105
+ assert.strictEqual(this.debugMailer.sent.length, 0);
106
+ }
107
+ async handleRequestCustomLaunchBadMethod() {
108
+ await this.handler.handleRequest({
109
+ command: "launch",
110
+ service: "DebugMailer",
111
+ method: "sends"
112
+ }, undefined);
113
+ assert.strictEqual(this.debugMailer.sent.length, 0);
114
+ }
115
+ async handleRequestKnownRoute() {
116
+ this.ensureGoodCSRF();
117
+ let res = await this.handler.handleRequest(this.evt, this.context);
118
+ assert.strictEqual(res.body, "CodeCoverage");
119
+ }
120
+ async handleRequestIdHeader() {
121
+ this.ensureGoodCSRF();
122
+ this.handler.getConfiguration().parameters.lambdaRequestHeader = "x-webda-request-id";
123
+ let res = await this.handler.handleRequest(this.evt, { ...this.context, awsRequestId: "toto" });
124
+ assert.strictEqual(res.body, "CodeCoverage");
125
+ assert.strictEqual(res.headers["x-webda-request-id"], "toto");
126
+ }
127
+ async handleRequestKnownRouteWithParamAndQuery() {
128
+ this.ensureGoodCSRF();
129
+ this.evt.queryStringParameters = { test: "Plop" };
130
+ this.evt.path = "/prefix/route/param/myid";
131
+ this.evt.resource = "/route/param/{uuid}";
132
+ this.evt.pathParameters = { uuid: "myid" };
133
+ let res = await this.handler.handleRequest(this.evt, this.context);
134
+ assert.strictEqual(res.body, "CodeCoveragemyidPlop");
135
+ }
136
+ async handleRequestKnownRouteWithParam() {
137
+ this.ensureGoodCSRF();
138
+ this.evt.path = "/prefix/route/param/myid";
139
+ this.evt.resource = "/route/param/{uuid}";
140
+ this.evt.pathParameters = { uuid: "myid" };
141
+ let res = await this.handler.handleRequest(this.evt, this.context);
142
+ assert.strictEqual(res.body, "CodeCoveragemyid");
143
+ }
144
+ async handleRequestKnownRouteWithQuery() {
145
+ this.ensureGoodCSRF();
146
+ this.evt.queryStringParameters = { test: "Plop" };
147
+ let res = await this.handler.handleRequest(this.evt, this.context);
148
+ assert.strictEqual(res.body, "CodeCoveragePlop");
149
+ }
150
+ async handleRequestUnknownRoute() {
151
+ this.ensureGoodCSRF();
152
+ this.evt.path = "/route/unknown";
153
+ this.evt.resource = "/route/unknown";
154
+ delete this.evt.headers.Cookie;
155
+ let res = await this.handler.handleRequest(this.evt, this.context);
156
+ assert.strictEqual(res.statusCode, 404);
157
+ }
158
+ async handleRequestThrow401() {
159
+ this.ensureGoodCSRF();
160
+ this.evt.path = "/route/broken/401";
161
+ this.evt.resource = "/route/broken/401";
162
+ let res = await this.handler.handleRequest(this.evt, this.context);
163
+ assert.strictEqual(res.statusCode, 401);
164
+ }
165
+ async handleRequestThrowError() {
166
+ this.ensureGoodCSRF();
167
+ this.evt.path = "/route/broken/Error";
168
+ let res = await this.handler.handleRequest(this.evt, this.context);
169
+ assert.strictEqual(res.statusCode, 500);
170
+ }
171
+ async handleRequestOPTIONS() {
172
+ this.ensureGoodCSRF();
173
+ this.evt.httpMethod = "OPTIONS";
174
+ let res = await this.handler.handleRequest(this.evt, this.context);
175
+ assert.strictEqual(res.statusCode, 204);
176
+ assert.strictEqual(res.headers["Access-Control-Allow-Methods"], "GET,OPTIONS");
177
+ }
178
+ async handleRequestOPTIONSWith404() {
179
+ this.ensureGoodCSRF();
180
+ this.evt.path = "/route/unknown";
181
+ this.evt.httpMethod = "OPTIONS";
182
+ let res = await this.handler.handleRequest(this.evt, this.context);
183
+ assert.strictEqual(res.statusCode, 404);
184
+ }
185
+ async cov() {
186
+ this.ensureGoodCSRF();
187
+ this.evt.headers["X-Forwarded-Port"] = "wew";
188
+ this.evt.headers["Content-Type"] = "text/plain";
189
+ this.evt.body = "{wew''";
190
+ // Should fallback on port 443
191
+ await this.handler.handleRequest(this.evt, this.context);
192
+ }
193
+ async handleRequestQueryParams() {
194
+ // TODO Check parameter retrieval
195
+ this.evt.queryStringParameters = {
196
+ test: "plop"
197
+ };
198
+ this.evt.headers.Origin = "https://test.webda.io";
199
+ this.evt.headers.Host = "test.webda.io";
200
+ await this.handler.handleRequest(this.evt, this.context);
273
201
  }
274
- handleRequestOrigin() {
275
- return __awaiter(this, void 0, void 0, function* () {
276
- this.evt.headers.Origin = "https://test.webda.io";
277
- this.evt.headers.Host = "test.webda.io";
278
- let wait = false;
279
- this.handler.on("Webda.Result", () => {
280
- return new Promise((resolve, reject) => {
281
- // Delay 100ms to ensure it waited
282
- setTimeout(() => {
283
- wait = true;
284
- resolve();
285
- }, 100);
286
- });
202
+ async handleRequestOrigin() {
203
+ this.evt.headers.Origin = "https://test.webda.io";
204
+ this.evt.headers.Host = "test.webda.io";
205
+ let wait = false;
206
+ this.handler.on("Webda.Result", () => {
207
+ return new Promise((resolve, reject) => {
208
+ // Delay 100ms to ensure it waited
209
+ setTimeout(() => {
210
+ wait = true;
211
+ resolve();
212
+ }, 100);
287
213
  });
288
- let res = yield this.handler.handleRequest(this.evt, this.context);
289
- assert.strictEqual(res.headers["Access-Control-Allow-Origin"], this.evt.headers.Origin);
290
- assert.strictEqual(wait, true);
291
- });
292
- }
293
- handleRequestOriginCSRF() {
294
- return __awaiter(this, void 0, void 0, function* () {
295
- this.evt.headers.Origin = "https://test3.webda.io";
296
- this.evt.headers.Host = "test3.webda.io";
297
- let res = yield this.handler.handleRequest(this.evt, this.context);
298
- assert.strictEqual(res.statusCode, 401);
299
- });
300
- }
301
- handleRequestRefererCSRF() {
302
- return __awaiter(this, void 0, void 0, function* () {
303
- this.evt.headers.Referer = "https://test3.webda.io";
304
- this.evt.headers.Host = "test3.webda.io";
305
- let res = yield this.handler.handleRequest(this.evt, this.context);
306
- assert.strictEqual(res.statusCode, 401);
307
- });
308
- }
309
- handleRequestRefererGoodCORS() {
310
- return __awaiter(this, void 0, void 0, function* () {
311
- this.evt.headers.Referer = "https://test.webda.io";
312
- this.evt.headers.Host = "test.webda.io";
313
- let res = yield this.handler.handleRequest(this.evt, this.context);
314
- assert.strictEqual(res.headers["Access-Control-Allow-Origin"], this.evt.headers.Referer);
315
- });
316
- }
317
- handleRequestHardStopCheckRequest() {
318
- return __awaiter(this, void 0, void 0, function* () {
319
- this.evt.headers.Referer = "https://test.webda.io";
320
- this.evt.headers.Host = "test.webda.io";
321
- this.handler.registerRequestFilter(this);
322
- let res = yield this.handler.handleRequest(this.evt, this.context);
323
- assert.strictEqual(res.statusCode, 410);
324
- this.badCheck = true;
325
- yield assert.rejects(() => this.handler.handleRequest(this.evt, this.context), /Unknown/);
326
214
  });
215
+ let res = await this.handler.handleRequest(this.evt, this.context);
216
+ assert.strictEqual(res.headers["Access-Control-Allow-Origin"], this.evt.headers.Origin);
217
+ assert.strictEqual(wait, true);
218
+ }
219
+ async handleRequestOriginCSRF() {
220
+ this.evt.headers.Origin = "https://test3.webda.io";
221
+ this.evt.headers.Host = "test3.webda.io";
222
+ let res = await this.handler.handleRequest(this.evt, this.context);
223
+ assert.strictEqual(res.statusCode, 401);
224
+ }
225
+ async handleRequestRefererCSRF() {
226
+ this.evt.headers.Referer = "https://test3.webda.io";
227
+ this.evt.headers.Host = "test3.webda.io";
228
+ let res = await this.handler.handleRequest(this.evt, this.context);
229
+ assert.strictEqual(res.statusCode, 401);
230
+ }
231
+ async handleRequestRefererGoodCORS() {
232
+ this.evt.headers.Referer = "https://test.webda.io";
233
+ this.evt.headers.Host = "test.webda.io";
234
+ let res = await this.handler.handleRequest(this.evt, this.context);
235
+ assert.strictEqual(res.headers["Access-Control-Allow-Origin"], this.evt.headers.Referer);
327
236
  }
328
- checkRequest() {
329
- return __awaiter(this, void 0, void 0, function* () {
330
- if (this.badCheck) {
331
- throw new Error("Unknown");
332
- }
333
- throw 410;
334
- });
237
+ async handleRequestHardStopCheckRequest() {
238
+ this.evt.headers.Referer = "https://test.webda.io";
239
+ this.evt.headers.Host = "test.webda.io";
240
+ this.handler.registerRequestFilter(this);
241
+ let res = await this.handler.handleRequest(this.evt, this.context);
242
+ assert.strictEqual(res.statusCode, 410);
243
+ this.badCheck = true;
244
+ await assert.rejects(() => this.handler.handleRequest(this.evt, this.context), /Unknown/);
245
+ }
246
+ async checkRequest() {
247
+ if (this.badCheck) {
248
+ throw new Error("Unknown");
249
+ }
250
+ throw 410;
335
251
  }
336
252
  ensureGoodCSRF() {
337
253
  this.evt.headers.Referer = "https://test.webda.io";
338
254
  this.evt.headers.Host = "test.webda.io";
339
255
  }
340
- awsEvents() {
341
- return __awaiter(this, void 0, void 0, function* () {
342
- let service = this.handler.getService("awsEvents");
343
- let files = fs.readdirSync(__dirname + "/../../test/aws-events");
344
- for (let f in files) {
345
- let file = files[f];
346
- let event = JSON.parse(fs.readFileSync(__dirname + "/../../test/aws-events/" + file).toString());
347
- yield this.handler.handleRequest(event, this.context);
348
- if (file === "api-gateway-aws-proxy.json") {
349
- assert.strictEqual(service.getEvents().length, 0, "API Gateway should go throught the normal request handling");
350
- }
351
- else {
352
- assert.notStrictEqual(service.getEvents().length, 0, "Should have get some events:" + JSON.stringify(event));
353
- }
256
+ async awsEvents() {
257
+ let service = this.handler.getService("awsEvents");
258
+ let files = fs.readdirSync(__dirname + "/../../test/aws-events");
259
+ for (let f in files) {
260
+ let file = files[f];
261
+ let event = JSON.parse(fs.readFileSync(__dirname + "/../../test/aws-events/" + file).toString());
262
+ await this.handler.handleRequest(event, this.context);
263
+ if (file === "api-gateway-aws-proxy.json") {
264
+ assert.strictEqual(service.getEvents().length, 0, "API Gateway should go through the normal request handling");
354
265
  }
355
- });
266
+ else {
267
+ assert.notStrictEqual(service.getEvents().length, 0, "Should have get some events:" + JSON.stringify(event));
268
+ }
269
+ }
356
270
  }
357
271
  /**
358
272
  * Wildcard path from API Gateway were missing the prefix
359
273
  *
360
274
  * @see https://github.com/loopingz/webda.io/issues/193
361
275
  */
362
- computePrefix() {
363
- return __awaiter(this, void 0, void 0, function* () {
364
- let httpContext = new core_1.HttpContext("test.webda.io", "GET", "/prefix/static1234/test/subfolder/index.html");
365
- this.handler.computePrefix({
366
- path: "/prefix/static1234/test/subfolder/index.html",
367
- resource: "/static1234/{path+}",
368
- pathParameters: {
369
- path: "test/subfolder/index.html"
370
- }
371
- }, httpContext);
372
- assert.strictEqual(httpContext.getRelativeUri(), "/static1234/test/subfolder/index.html");
373
- assert.strictEqual(httpContext.prefix, "/prefix");
374
- });
276
+ async computePrefix() {
277
+ let httpContext = new HttpContext("test.webda.io", "GET", "/prefix/static1234/test/subfolder/index.html");
278
+ this.handler.computePrefix({
279
+ path: "/prefix/static1234/test/subfolder/index.html",
280
+ resource: "/static1234/{path+}",
281
+ pathParameters: {
282
+ path: "test/subfolder/index.html"
283
+ }
284
+ }, httpContext);
285
+ assert.strictEqual(httpContext.getRelativeUri(), "/static1234/test/subfolder/index.html");
286
+ assert.strictEqual(httpContext.prefix, "/prefix");
375
287
  }
376
288
  };
377
289
  __decorate([
378
- mocha_1.test
290
+ test
379
291
  ], LambdaHandlerTest.prototype, "checkRequestFalse", null);
380
292
  __decorate([
381
- mocha_1.test
293
+ test
382
294
  ], LambdaHandlerTest.prototype, "handleRequestCustomLaunch", null);
383
295
  __decorate([
384
- mocha_1.test
296
+ test
385
297
  ], LambdaHandlerTest.prototype, "handleRequestCustomLaunchBadService", null);
386
298
  __decorate([
387
- mocha_1.test
299
+ test
388
300
  ], LambdaHandlerTest.prototype, "handleRequestCustomLaunchBadMethod", null);
389
301
  __decorate([
390
- mocha_1.test
302
+ test
391
303
  ], LambdaHandlerTest.prototype, "handleRequestKnownRoute", null);
392
304
  __decorate([
393
- mocha_1.test
305
+ test
394
306
  ], LambdaHandlerTest.prototype, "handleRequestIdHeader", null);
395
307
  __decorate([
396
- mocha_1.test
308
+ test
397
309
  ], LambdaHandlerTest.prototype, "handleRequestKnownRouteWithParamAndQuery", null);
398
310
  __decorate([
399
- mocha_1.test
311
+ test
400
312
  ], LambdaHandlerTest.prototype, "handleRequestKnownRouteWithParam", null);
401
313
  __decorate([
402
- mocha_1.test
314
+ test
403
315
  ], LambdaHandlerTest.prototype, "handleRequestKnownRouteWithQuery", null);
404
316
  __decorate([
405
- mocha_1.test
317
+ test
406
318
  ], LambdaHandlerTest.prototype, "handleRequestUnknownRoute", null);
407
319
  __decorate([
408
- mocha_1.test
320
+ test
409
321
  ], LambdaHandlerTest.prototype, "handleRequestThrow401", null);
410
322
  __decorate([
411
- mocha_1.test
323
+ test
412
324
  ], LambdaHandlerTest.prototype, "handleRequestThrowError", null);
413
325
  __decorate([
414
- mocha_1.test
326
+ test
415
327
  ], LambdaHandlerTest.prototype, "handleRequestOPTIONS", null);
416
328
  __decorate([
417
- mocha_1.test
329
+ test
418
330
  ], LambdaHandlerTest.prototype, "handleRequestOPTIONSWith404", null);
419
331
  __decorate([
420
- mocha_1.test
332
+ test
421
333
  ], LambdaHandlerTest.prototype, "cov", null);
422
334
  __decorate([
423
- mocha_1.test
335
+ test
424
336
  ], LambdaHandlerTest.prototype, "handleRequestQueryParams", null);
425
337
  __decorate([
426
- mocha_1.test
338
+ test
427
339
  ], LambdaHandlerTest.prototype, "handleRequestOrigin", null);
428
340
  __decorate([
429
- mocha_1.test
341
+ test
430
342
  ], LambdaHandlerTest.prototype, "handleRequestOriginCSRF", null);
431
343
  __decorate([
432
- mocha_1.test
344
+ test
433
345
  ], LambdaHandlerTest.prototype, "handleRequestRefererCSRF", null);
434
346
  __decorate([
435
- mocha_1.test
347
+ test
436
348
  ], LambdaHandlerTest.prototype, "handleRequestRefererGoodCORS", null);
437
349
  __decorate([
438
- mocha_1.test
350
+ test
439
351
  ], LambdaHandlerTest.prototype, "handleRequestHardStopCheckRequest", null);
440
352
  __decorate([
441
- mocha_1.test
353
+ test
442
354
  ], LambdaHandlerTest.prototype, "awsEvents", null);
443
355
  __decorate([
444
- mocha_1.test
356
+ test
445
357
  ], LambdaHandlerTest.prototype, "computePrefix", null);
446
358
  LambdaHandlerTest = __decorate([
447
- mocha_1.suite
359
+ suite
448
360
  ], LambdaHandlerTest);
449
361
  //# sourceMappingURL=lambdaserver.spec.js.map