@azure/web-pubsub-express 1.0.0-beta.1 → 1.0.1-alpha.20211215.2

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.
@@ -1 +1 @@
1
- {"version":3,"file":"connect.spec.js","sourceRoot":"","sources":["../../test/connect.spec.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;AAClC,oCAAoC;AACpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,SAAS,YAAY,CACnB,GAAoB,EACpB,GAAW,EACX,YAAoB,EACpB,MAAe;IAEf,GAAG,CAAC,OAAO,CAAC,wBAAwB,CAAC,GAAG,yBAAyB,CAAC;IAClE,GAAG,CAAC,OAAO,CAAC,cAAc,CAAC,GAAG,iCAAiC,CAAC;IAChE,GAAG,CAAC,OAAO,CAAC,gBAAgB,CAAC,GAAG,KAAK,CAAC;IACtC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,6BAA6B,CAAC;IACvD,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,GAAG,SAAS,GAAG,WAAW,YAAY,EAAE,CAAC;IACjE,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,GAAG,CAAC;IAC3B,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAClD,IAAI,MAAM,KAAK,SAAS,EAAE;QACxB,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,GAAG,MAAM,CAAC;KACnC;IACD,GAAG,CAAC,OAAO,CAAC,iBAAiB,CAAC,GAAG,YAAY,C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C,EAAE,CAAC,CAAC,CAAC;YAClC,IAAI,MAAM,GAAG,MAAM,OAAO,CAAC;YAC3B,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;YACvC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAC;YACrD,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,UAAU,EAAE,mBAAmB,CAAC,CAAC;QACzD,CAAC;KAAA,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n/* eslint-disable no-invalid-this */\nimport { CloudEventsDispatcher } from \"../src/cloudEventsDispatcher\";\nimport { assert } from \"chai\";\nimport { IncomingMessage, ServerResponse } from \"http\";\nimport { Socket } from \"net\";\nimport * as sinon from \"sinon\";\n\nfunction buildRequest(\n req: IncomingMessage,\n hub: string,\n connectionId: string,\n userId?: string\n): void {\n req.headers[\"webhook-request-origin\"] = \"xxx.webpubsub.azure.com\";\n req.headers[\"Content-Type\"] = \"application/json; charset=utf-8\";\n req.headers[\"ce-specversion\"] = \"1.0\";\n req.headers[\"ce-type\"] = \"azure.webpubsub.sys.connect\";\n req.headers[\"ce-source\"] = `/hubs/${hub}/client/${connectionId}`;\n req.headers[\"ce-id\"] = \"1\";\n req.headers[\"ce-time\"] = new Date().toUTCString();\n if (userId !== undefined) {\n req.headers[\"ce-userId\"] = userId;\n }\n req.headers[\"ce-connectionId\"] = connectionId;\n req.headers[\"ce-hub\"] = hub;\n req.headers[\"ce-event\"] = \"connect\";\n}\n\nfunction mockBody(req: IncomingMessage, body: string): void {\n req.emit(\"data\", Buffer.from(body, \"utf-8\"));\n req.emit(\"end\");\n}\n\ndescribe(\"Can handle connect event\", function() {\n let req: IncomingMessage;\n let res: ServerResponse;\n\n beforeEach(function() {\n req = new IncomingMessage(new Socket());\n res = new ServerResponse(req);\n });\n\n it(\"Should not handle the request if request is not cloud events\", async function() {\n const endSpy = sinon.spy(res.end);\n\n const dispatcher = new CloudEventsDispatcher(\"hub1\", [\"*\"]);\n var result = await dispatcher.processRequest(req, res);\n assert.isFalse(result);\n assert.isTrue(endSpy.notCalled);\n });\n\n it(\"Should not handle the request if hub does not match\", async function() {\n const endSpy = sinon.spy(res.end);\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub1\", [\"*\"]);\n var result = await dispatcher.processRequest(req, res);\n assert.isFalse(result);\n assert.isTrue(endSpy.notCalled);\n });\n\n it(\"Should response with 401 when option is not specified\", async function() {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", [\"*\"]);\n var result = await dispatcher.processRequest(req, res);\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(401, res.statusCode, \"should be 401\");\n });\n\n it(\"Should response with 401 when handler is not specified\", async function() {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", [\"*\"], {});\n var result = await dispatcher.processRequest(req, res);\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(401, res.statusCode, \"should be 401\");\n });\n\n it(\"Should response with error when handler returns error\", async function() {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", [\"*\"], {\n handleConnect: async (_, res) => {\n res.fail(400);\n }\n });\n var process = dispatcher.processRequest(req, res);\n mockBody(req, JSON.stringify({}));\n var result = await process;\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(400, res.statusCode, \"should be error\");\n });\n\n it(\"Should response with success when handler returns success\", async function() {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", [\"*\"], {\n handleConnect: async (_, res) => {\n res.success();\n }\n });\n var process = dispatcher.processRequest(req, res);\n mockBody(req, JSON.stringify({}));\n var result = await process;\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be success\");\n });\n\n it(\"Should response with success when handler returns success value\", async function() {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", [\"*\"], {\n handleConnect: async (_, res) => {\n res.success({ userId: \"vic\" });\n }\n });\n var process = dispatcher.processRequest(req, res);\n mockBody(req, JSON.stringify({}));\n var result = await process;\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be success\");\n });\n});\n"]}
1
+ {"version":3,"file":"connect.spec.js","sourceRoot":"","sources":["../../test/connect.spec.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,oCAAoC;AACpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAElD,SAAS,YAAY,CACnB,GAAoB,EACpB,GAAW,EACX,YAAoB,EACpB,MAAe,EACf,MAAe;IAEf,GAAG,CAAC,OAAO,CAAC,wBAAwB,CAAC,GAAG,yBAAyB,CAAC;IAClE,GAAG,CAAC,OAAO,CAAC,cAAc,CAAC,GAAG,iCAAiC,CAAC;IAChE,GAAG,CAAC,OAAO,CAAC,gBAAgB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AE,CAAC;YACrB,CAAC;SACF,CAAC,CAAC;QACH,MAAM,OAAO,GAAG,UAAU,CAAC,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACnD,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC;QAClC,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC;QAC7B,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;QACvC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAC;QACrD,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,UAAU,EAAE,mBAAmB,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n/* eslint-disable no-invalid-this */\nimport { CloudEventsDispatcher } from \"../src/cloudEventsDispatcher\";\nimport { assert } from \"chai\";\nimport { IncomingMessage, ServerResponse } from \"http\";\nimport { Socket } from \"net\";\nimport * as sinon from \"sinon\";\nimport { toBase64JsonString } from \"../src/utils\";\n\nfunction buildRequest(\n req: IncomingMessage,\n hub: string,\n connectionId: string,\n userId?: string,\n states?: string\n): void {\n req.headers[\"webhook-request-origin\"] = \"xxx.webpubsub.azure.com\";\n req.headers[\"Content-Type\"] = \"application/json; charset=utf-8\";\n req.headers[\"ce-awpsversion\"] = \"1.0\";\n req.headers[\"ce-specversion\"] = \"1.0\";\n req.headers[\"ce-type\"] = \"azure.webpubsub.sys.connect\";\n req.headers[\"ce-source\"] = `/hubs/${hub}/client/${connectionId}`;\n req.headers[\"ce-id\"] = \"1\";\n req.headers[\"ce-time\"] = new Date().toUTCString();\n if (userId !== undefined) {\n req.headers[\"ce-userId\"] = userId;\n }\n req.headers[\"ce-connectionId\"] = connectionId;\n req.headers[\"ce-hub\"] = hub;\n req.headers[\"ce-event\"] = \"connect\";\n req.headers[\"ce-connectionState\"] = states;\n}\n\nfunction mockBody(req: IncomingMessage, body: string): void {\n req.emit(\"data\", Buffer.from(body, \"utf-8\"));\n req.emit(\"end\");\n}\n\ndescribe(\"Can handle connect event\", function() {\n let req: IncomingMessage;\n let res: ServerResponse;\n\n beforeEach(function() {\n req = new IncomingMessage(new Socket());\n res = new ServerResponse(req);\n });\n\n it(\"Should not handle the request if request is not cloud events\", async function() {\n const endSpy = sinon.spy(res.end);\n\n const dispatcher = new CloudEventsDispatcher(\"hub1\");\n const result = await dispatcher.handleRequest(req, res);\n assert.isFalse(result);\n assert.isTrue(endSpy.notCalled);\n });\n\n it(\"Should not handle the request if hub does not match\", async function() {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub1\");\n const result = await dispatcher.handleRequest(req, res);\n assert.isFalse(result);\n assert.isTrue(endSpy.notCalled);\n });\n\n it(\"Should response with 200 when option is not specified\", async function() {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\");\n const result = await dispatcher.handleRequest(req, res);\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be 200\");\n });\n\n it(\"Should response with 200 when handler is not specified\", async function() {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {});\n const result = await dispatcher.handleRequest(req, res);\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be 200\");\n });\n\n it(\"Should response with error when handler returns error\", async function() {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n handleConnect: async (_, response) => {\n response.fail(400);\n }\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify({}));\n const result = await process;\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(400, res.statusCode, \"should be error\");\n });\n\n it(\"Should response with success when handler returns success\", async function() {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n handleConnect: async (_, response) => {\n response.success();\n }\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify({}));\n const result = await process;\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be success\");\n });\n\n it(\"Should response with success when handler returns success value\", async function() {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n handleConnect: async (_, response) => {\n response.success({ userId: \"vic\" });\n }\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify({}));\n const result = await process;\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be success\");\n });\n\n it(\"Should be able to set connection state\", async function() {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n handleConnect: async (_, response) => {\n response.setState(\"key1\", \"val1\");\n response.setState(\"key2\", \"val2\");\n response.setState(\"key1\", [\"val3\"]);\n response.setState(\"key3\", \"\");\n response.success({ userId: \"vic\" });\n }\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify({}));\n const result = await process;\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(\n toBase64JsonString({\n key1: [\"val3\"],\n key2: \"val2\",\n key3: \"\"\n }),\n res.getHeader(\"ce-connectionState\"),\n \"should contain multiple state headers\"\n );\n });\n\n it(\"Should be able to get the connection states if it exists in the header\", async function() {\n const endSpy = sinon.spy(res, \"end\");\n const states = toBase64JsonString({\n key1: [\"val3\"],\n key2: \"val2\",\n key3: \"\"\n });\n buildRequest(req, \"hub1\", \"conn1\", undefined, states);\n const dispatcher = new CloudEventsDispatcher(\"hub1\", {\n handleConnect: (request, response) => {\n assert.equal(\"val3\", request.context.states[\"key1\"][0]);\n assert.equal(\"val2\", request.context.states[\"key2\"]);\n assert.equal(\"\", request.context.states[\"key3\"]);\n response.success();\n }\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify({}));\n const result = await process;\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be success\");\n });\n\n it(\"Invalid state header gets ignored\", async function() {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub1\", \"conn1\", undefined, \"\");\n const dispatcher = new CloudEventsDispatcher(\"hub1\", {\n handleConnect: (request, response) => {\n assert.deepEqual({}, request.context.states);\n response.success();\n }\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify({}));\n const result = await process;\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be success\");\n });\n});\n"]}
@@ -1,4 +1,3 @@
1
- import { __awaiter } from "tslib";
2
1
  // Copyright (c) Microsoft Corporation.
3
2
  // Licensed under the MIT license.
4
3
  /* eslint-disable no-invalid-this */
@@ -10,6 +9,7 @@ import * as sinon from "sinon";
10
9
  function buildRequest(req, hub, connectionId, userId) {
11
10
  req.headers["webhook-request-origin"] = "xxx.webpubsub.azure.com";
12
11
  req.headers["Content-Type"] = "application/json; charset=utf-8";
12
+ req.headers["ce-awpsversion"] = "1.0";
13
13
  req.headers["ce-specversion"] = "1.0";
14
14
  req.headers["ce-type"] = "azure.webpubsub.user.connected";
15
15
  req.headers["ce-source"] = `/hubs/${hub}/client/${connectionId}`;
@@ -33,63 +33,53 @@ describe("Can handle connected event", function () {
33
33
  req = new IncomingMessage(new Socket());
34
34
  res = new ServerResponse(req);
35
35
  });
36
- it("Should not handle the request if request is not cloud events", function () {
37
- return __awaiter(this, void 0, void 0, function* () {
38
- const endSpy = sinon.spy(res.end);
39
- const dispatcher = new CloudEventsDispatcher("hub1", ["*"]);
40
- var result = yield dispatcher.processRequest(req, res);
41
- assert.isFalse(result);
42
- assert.isTrue(endSpy.notCalled);
43
- });
36
+ it("Should not handle the request if request is not cloud events", async function () {
37
+ const endSpy = sinon.spy(res.end);
38
+ const dispatcher = new CloudEventsDispatcher("hub1");
39
+ const result = await dispatcher.handleRequest(req, res);
40
+ assert.isFalse(result);
41
+ assert.isTrue(endSpy.notCalled);
44
42
  });
45
- it("Should not handle the request if hub does not match", function () {
46
- return __awaiter(this, void 0, void 0, function* () {
47
- const endSpy = sinon.spy(res.end);
48
- buildRequest(req, "hub", "conn1");
49
- const dispatcher = new CloudEventsDispatcher("hub1", ["*"]);
50
- var result = yield dispatcher.processRequest(req, res);
51
- assert.isFalse(result);
52
- assert.isTrue(endSpy.notCalled);
53
- });
43
+ it("Should not handle the request if hub does not match", async function () {
44
+ const endSpy = sinon.spy(res.end);
45
+ buildRequest(req, "hub", "conn1");
46
+ const dispatcher = new CloudEventsDispatcher("hub1");
47
+ const result = await dispatcher.handleRequest(req, res);
48
+ assert.isFalse(result);
49
+ assert.isTrue(endSpy.notCalled);
54
50
  });
55
- it("Should response with 200 when option is not specified", function () {
56
- return __awaiter(this, void 0, void 0, function* () {
57
- const endSpy = sinon.spy(res, "end");
58
- buildRequest(req, "hub", "conn1");
59
- const dispatcher = new CloudEventsDispatcher("hub", ["*"]);
60
- var result = yield dispatcher.processRequest(req, res);
61
- assert.isTrue(result, "should handle");
62
- assert.isTrue(endSpy.calledOnce, "should call once");
63
- assert.equal(200, res.statusCode, "should be 200");
64
- });
51
+ it("Should response with 200 when option is not specified", async function () {
52
+ const endSpy = sinon.spy(res, "end");
53
+ buildRequest(req, "hub", "conn1");
54
+ const dispatcher = new CloudEventsDispatcher("hub");
55
+ const result = await dispatcher.handleRequest(req, res);
56
+ assert.isTrue(result, "should handle");
57
+ assert.isTrue(endSpy.calledOnce, "should call once");
58
+ assert.equal(200, res.statusCode, "should be 200");
65
59
  });
66
- it("Should response with 200 when handler is not specified", function () {
67
- return __awaiter(this, void 0, void 0, function* () {
68
- const endSpy = sinon.spy(res, "end");
69
- buildRequest(req, "hub", "conn1");
70
- const dispatcher = new CloudEventsDispatcher("hub", ["*"], {});
71
- var result = yield dispatcher.processRequest(req, res);
72
- assert.isTrue(result, "should handle");
73
- assert.isTrue(endSpy.calledOnce, "should call once");
74
- assert.equal(200, res.statusCode, "should be 200");
75
- });
60
+ it("Should response with 200 when handler is not specified", async function () {
61
+ const endSpy = sinon.spy(res, "end");
62
+ buildRequest(req, "hub", "conn1");
63
+ const dispatcher = new CloudEventsDispatcher("hub", {});
64
+ const result = await dispatcher.handleRequest(req, res);
65
+ assert.isTrue(result, "should handle");
66
+ assert.isTrue(endSpy.calledOnce, "should call once");
67
+ assert.equal(200, res.statusCode, "should be 200");
76
68
  });
77
- it("Should response 200 even the event handler throws", function () {
78
- return __awaiter(this, void 0, void 0, function* () {
79
- const endSpy = sinon.spy(res, "end");
80
- buildRequest(req, "hub", "conn1");
81
- const dispatcher = new CloudEventsDispatcher("hub", ["*"], {
82
- onConnected: (_) => __awaiter(this, void 0, void 0, function* () {
83
- throw new Error();
84
- })
85
- });
86
- var process = dispatcher.processRequest(req, res);
87
- mockBody(req, JSON.stringify({}));
88
- var result = yield process;
89
- assert.isTrue(result, "should handle");
90
- assert.isTrue(endSpy.calledOnce, "should call once");
91
- assert.equal(200, res.statusCode, "should be error");
69
+ it("Should response 200 even the event handler throws", async function () {
70
+ const endSpy = sinon.spy(res, "end");
71
+ buildRequest(req, "hub", "conn1");
72
+ const dispatcher = new CloudEventsDispatcher("hub", {
73
+ onConnected: async (_) => {
74
+ throw new Error();
75
+ }
92
76
  });
77
+ const process = dispatcher.handleRequest(req, res);
78
+ mockBody(req, JSON.stringify({}));
79
+ const result = await process;
80
+ assert.isTrue(result, "should handle");
81
+ assert.isTrue(endSpy.calledOnce, "should call once");
82
+ assert.equal(200, res.statusCode, "should be error");
93
83
  });
94
84
  });
95
85
  //# sourceMappingURL=connected.spec.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"connected.spec.js","sourceRoot":"","sources":["../../test/connected.spec.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;AAClC,oCAAoC;AACpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,SAAS,YAAY,CACnB,GAAoB,EACpB,GAAW,EACX,YAAoB,EACpB,MAAe;IAEf,GAAG,CAAC,OAAO,CAAC,wBAAwB,CAAC,GAAG,yBAAyB,CAAC;IAClE,GAAG,CAAC,OAAO,CAAC,cAAc,CAAC,GAAG,iCAAiC,CAAC;IAChE,GAAG,CAAC,OAAO,CAAC,gBAAgB,CAAC,GAAG,KAAK,CAAC;IACtC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,gCAAgC,CAAC;IAC1D,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,GAAG,SAAS,GAAG,WAAW,YAAY,EAAE,CAAC;IACjE,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,GAAG,CAAC;IAC3B,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAClD,IAAI,MAAM,KAAK,SAAS,EAAE;QACxB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ventsDispatcher } from \"../src/cloudEventsDispatcher\";\nimport { assert } from \"chai\";\nimport { IncomingMessage, ServerResponse } from \"http\";\nimport { Socket } from \"net\";\nimport * as sinon from \"sinon\";\n\nfunction buildRequest(\n req: IncomingMessage,\n hub: string,\n connectionId: string,\n userId?: string\n): void {\n req.headers[\"webhook-request-origin\"] = \"xxx.webpubsub.azure.com\";\n req.headers[\"Content-Type\"] = \"application/json; charset=utf-8\";\n req.headers[\"ce-specversion\"] = \"1.0\";\n req.headers[\"ce-type\"] = \"azure.webpubsub.user.connected\";\n req.headers[\"ce-source\"] = `/hubs/${hub}/client/${connectionId}`;\n req.headers[\"ce-id\"] = \"1\";\n req.headers[\"ce-time\"] = new Date().toUTCString();\n if (userId !== undefined) {\n req.headers[\"ce-userId\"] = userId;\n }\n req.headers[\"ce-connectionId\"] = connectionId;\n req.headers[\"ce-hub\"] = hub;\n req.headers[\"ce-event\"] = \"connected\";\n}\n\nfunction mockBody(req: IncomingMessage, body: string): void {\n req.emit(\"data\", body);\n req.emit(\"end\");\n}\n\ndescribe(\"Can handle connected event\", function() {\n let req: IncomingMessage;\n let res: ServerResponse;\n\n beforeEach(function() {\n req = new IncomingMessage(new Socket());\n res = new ServerResponse(req);\n });\n\n it(\"Should not handle the request if request is not cloud events\", async function() {\n const endSpy = sinon.spy(res.end);\n\n const dispatcher = new CloudEventsDispatcher(\"hub1\", [\"*\"]);\n var result = await dispatcher.processRequest(req, res);\n assert.isFalse(result);\n assert.isTrue(endSpy.notCalled);\n });\n\n it(\"Should not handle the request if hub does not match\", async function() {\n const endSpy = sinon.spy(res.end);\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub1\", [\"*\"]);\n var result = await dispatcher.processRequest(req, res);\n assert.isFalse(result);\n assert.isTrue(endSpy.notCalled);\n });\n\n it(\"Should response with 200 when option is not specified\", async function() {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", [\"*\"]);\n var result = await dispatcher.processRequest(req, res);\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be 200\");\n });\n\n it(\"Should response with 200 when handler is not specified\", async function() {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", [\"*\"], {});\n var result = await dispatcher.processRequest(req, res);\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be 200\");\n });\n\n it(\"Should response 200 even the event handler throws\", async function() {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", [\"*\"], {\n onConnected: async (_) => {\n throw new Error();\n }\n });\n var process = dispatcher.processRequest(req, res);\n mockBody(req, JSON.stringify({}));\n var result = await process;\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be error\");\n });\n});\n"]}
1
+ {"version":3,"file":"connected.spec.js","sourceRoot":"","sources":["../../test/connected.spec.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,oCAAoC;AACpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,SAAS,YAAY,CACnB,GAAoB,EACpB,GAAW,EACX,YAAoB,EACpB,MAAe;IAEf,GAAG,CAAC,OAAO,CAAC,wBAAwB,CAAC,GAAG,yBAAyB,CAAC;IAClE,GAA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MAAM,MAAM,GAAG,MAAM,OAAO,CAAC;QAC7B,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;QACvC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAC;QACrD,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,UAAU,EAAE,iBAAiB,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n/* eslint-disable no-invalid-this */\nimport { CloudEventsDispatcher } from \"../src/cloudEventsDispatcher\";\nimport { assert } from \"chai\";\nimport { IncomingMessage, ServerResponse } from \"http\";\nimport { Socket } from \"net\";\nimport * as sinon from \"sinon\";\n\nfunction buildRequest(\n req: IncomingMessage,\n hub: string,\n connectionId: string,\n userId?: string\n): void {\n req.headers[\"webhook-request-origin\"] = \"xxx.webpubsub.azure.com\";\n req.headers[\"Content-Type\"] = \"application/json; charset=utf-8\";\n req.headers[\"ce-awpsversion\"] = \"1.0\";\n req.headers[\"ce-specversion\"] = \"1.0\";\n req.headers[\"ce-type\"] = \"azure.webpubsub.user.connected\";\n req.headers[\"ce-source\"] = `/hubs/${hub}/client/${connectionId}`;\n req.headers[\"ce-id\"] = \"1\";\n req.headers[\"ce-time\"] = new Date().toUTCString();\n if (userId !== undefined) {\n req.headers[\"ce-userId\"] = userId;\n }\n req.headers[\"ce-connectionId\"] = connectionId;\n req.headers[\"ce-hub\"] = hub;\n req.headers[\"ce-event\"] = \"connected\";\n}\n\nfunction mockBody(req: IncomingMessage, body: string): void {\n req.emit(\"data\", body);\n req.emit(\"end\");\n}\n\ndescribe(\"Can handle connected event\", function() {\n let req: IncomingMessage;\n let res: ServerResponse;\n\n beforeEach(function() {\n req = new IncomingMessage(new Socket());\n res = new ServerResponse(req);\n });\n\n it(\"Should not handle the request if request is not cloud events\", async function() {\n const endSpy = sinon.spy(res.end);\n\n const dispatcher = new CloudEventsDispatcher(\"hub1\");\n const result = await dispatcher.handleRequest(req, res);\n assert.isFalse(result);\n assert.isTrue(endSpy.notCalled);\n });\n\n it(\"Should not handle the request if hub does not match\", async function() {\n const endSpy = sinon.spy(res.end);\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub1\");\n const result = await dispatcher.handleRequest(req, res);\n assert.isFalse(result);\n assert.isTrue(endSpy.notCalled);\n });\n\n it(\"Should response with 200 when option is not specified\", async function() {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\");\n const result = await dispatcher.handleRequest(req, res);\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be 200\");\n });\n\n it(\"Should response with 200 when handler is not specified\", async function() {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {});\n const result = await dispatcher.handleRequest(req, res);\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be 200\");\n });\n\n it(\"Should response 200 even the event handler throws\", async function() {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n onConnected: async (_) => {\n throw new Error();\n }\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify({}));\n const result = await process;\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be error\");\n });\n});\n"]}
@@ -5,17 +5,23 @@ import { WebPubSubEventHandler } from "../src/webPubSubEventHandler";
5
5
  import { assert } from "chai";
6
6
  describe("Can creat event handler", function () {
7
7
  it("Can provide default path", function () {
8
- const dispatcher = new WebPubSubEventHandler("hub", ["*"]);
8
+ const dispatcher = new WebPubSubEventHandler("hub");
9
9
  assert.equal("/api/webpubsub/hubs/hub/", dispatcher.path);
10
10
  });
11
11
  it("Supports custom path", function () {
12
- const dispatcher = new WebPubSubEventHandler("hub", ["*"], {
12
+ const dispatcher = new WebPubSubEventHandler("hub", {
13
13
  path: "/custom"
14
14
  });
15
15
  assert.equal("/custom/", dispatcher.path);
16
16
  });
17
17
  it("Throw with invalid endpoints", function () {
18
- assert.throws(() => new WebPubSubEventHandler("hub", ["b.com"]), "Invalid URL: b.com");
18
+ try {
19
+ new WebPubSubEventHandler("hub", { allowedEndpoints: ["b.com"] });
20
+ assert.fail("Should have thrown ERROR_INVALID_URL");
21
+ }
22
+ catch (err) {
23
+ assert.isTrue(err.message.startsWith("Invalid URL"));
24
+ }
19
25
  });
20
26
  });
21
27
  //# sourceMappingURL=ctor.spec.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ctor.spec.js","sourceRoot":"","sources":["../../test/ctor.spec.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,oCAAoC;AACpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAE9B,QAAQ,CAAC,yBAAyB,EAAE;IAClC,EAAE,CAAC,0BAA0B,EAAE;QAC7B,MAAM,UAAU,GAAG,IAAI,qBAAqB,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;QAC3D,MAAM,CAAC,KAAK,CAAC,0BAA0B,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sBAAsB,EAAE;QACzB,MAAM,UAAU,GAAG,IAAI,qBAAqB,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE;YACzD,IAAI,EAAE,SAAS;SAChB,CAAC,CAAC;QACH,MAAM,CAAC,KAAK,CAAC,UAAU,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;IAC5C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8BAA8B,EAAE;QACjC,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,IAAI,qBAAqB,CAAC,KAAK,EAAE,CAAC,OAAO,CAAC,CAAC,EAAE,oBAAoB,CAAC,CAAC;IACzF,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n/* eslint-disable no-invalid-this */\nimport { WebPubSubEventHandler } from \"../src/webPubSubEventHandler\";\nimport { assert } from \"chai\";\n\ndescribe(\"Can creat event handler\", function() {\n it(\"Can provide default path\", function() {\n const dispatcher = new WebPubSubEventHandler(\"hub\", [\"*\"]);\n assert.equal(\"/api/webpubsub/hubs/hub/\", dispatcher.path);\n });\n\n it(\"Supports custom path\", function() {\n const dispatcher = new WebPubSubEventHandler(\"hub\", [\"*\"], {\n path: \"/custom\"\n });\n assert.equal(\"/custom/\", dispatcher.path);\n });\n\n it(\"Throw with invalid endpoints\", function() {\n assert.throws(() => new WebPubSubEventHandler(\"hub\", [\"b.com\"]), \"Invalid URL: b.com\");\n });\n});\n"]}
1
+ {"version":3,"file":"ctor.spec.js","sourceRoot":"","sources":["../../test/ctor.spec.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,oCAAoC;AACpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAE9B,QAAQ,CAAC,yBAAyB,EAAE;IAClC,EAAE,CAAC,0BAA0B,EAAE;QAC7B,MAAM,UAAU,GAAG,IAAI,qBAAqB,CAAC,KAAK,CAAC,CAAC;QACpD,MAAM,CAAC,KAAK,CAAC,0BAA0B,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sBAAsB,EAAE;QACzB,MAAM,UAAU,GAAG,IAAI,qBAAqB,CAAC,KAAK,EAAE;YAClD,IAAI,EAAE,SAAS;SAChB,CAAC,CAAC;QACH,MAAM,CAAC,KAAK,CAAC,UAAU,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;IAC5C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8BAA8B,EAAE;QACjC,IAAI;YACF,IAAI,qBAAqB,CAAC,KAAK,EAAE,EAAE,gBAAgB,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YAClE,MAAM,CAAC,IAAI,CAAC,sCAAsC,CAAC,CAAC;SACrD;QAAC,OAAO,GAAG,EAAE;YACZ,MAAM,CAAC,MAAM,CAAE,GAAW,CAAC,OAAO,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC;SAC/D;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n/* eslint-disable no-invalid-this */\nimport { WebPubSubEventHandler } from \"../src/webPubSubEventHandler\";\nimport { assert } from \"chai\";\n\ndescribe(\"Can creat event handler\", function() {\n it(\"Can provide default path\", function() {\n const dispatcher = new WebPubSubEventHandler(\"hub\");\n assert.equal(\"/api/webpubsub/hubs/hub/\", dispatcher.path);\n });\n\n it(\"Supports custom path\", function() {\n const dispatcher = new WebPubSubEventHandler(\"hub\", {\n path: \"/custom\"\n });\n assert.equal(\"/custom/\", dispatcher.path);\n });\n\n it(\"Throw with invalid endpoints\", function() {\n try {\n new WebPubSubEventHandler(\"hub\", { allowedEndpoints: [\"b.com\"] });\n assert.fail(\"Should have thrown ERROR_INVALID_URL\");\n } catch (err) {\n assert.isTrue((err as any).message.startsWith(\"Invalid URL\"));\n }\n });\n});\n"]}
@@ -1,4 +1,3 @@
1
- import { __awaiter } from "tslib";
2
1
  // Copyright (c) Microsoft Corporation.
3
2
  // Licensed under the MIT license.
4
3
  /* eslint-disable no-invalid-this */
@@ -10,6 +9,7 @@ import * as sinon from "sinon";
10
9
  function buildRequest(req, hub, connectionId, userId) {
11
10
  req.headers["webhook-request-origin"] = "xxx.webpubsub.azure.com";
12
11
  req.headers["Content-Type"] = "application/json; charset=utf-8";
12
+ req.headers["ce-awpsversion"] = "1.0";
13
13
  req.headers["ce-specversion"] = "1.0";
14
14
  req.headers["ce-type"] = "azure.webpubsub.user.disconnected";
15
15
  req.headers["ce-source"] = `/hubs/${hub}/client/${connectionId}`;
@@ -33,63 +33,53 @@ describe("Can handle disconnected event", function () {
33
33
  req = new IncomingMessage(new Socket());
34
34
  res = new ServerResponse(req);
35
35
  });
36
- it("Should not handle the request if request is not cloud events", function () {
37
- return __awaiter(this, void 0, void 0, function* () {
38
- const endSpy = sinon.spy(res.end);
39
- const dispatcher = new CloudEventsDispatcher("hub1", ["*"]);
40
- var result = yield dispatcher.processRequest(req, res);
41
- assert.isFalse(result);
42
- assert.isTrue(endSpy.notCalled);
43
- });
36
+ it("Should not handle the request if request is not cloud events", async function () {
37
+ const endSpy = sinon.spy(res.end);
38
+ const dispatcher = new CloudEventsDispatcher("hub1");
39
+ const result = await dispatcher.handleRequest(req, res);
40
+ assert.isFalse(result);
41
+ assert.isTrue(endSpy.notCalled);
44
42
  });
45
- it("Should not handle the request if hub does not match", function () {
46
- return __awaiter(this, void 0, void 0, function* () {
47
- const endSpy = sinon.spy(res.end);
48
- buildRequest(req, "hub", "conn1");
49
- const dispatcher = new CloudEventsDispatcher("hub1", ["*"]);
50
- var result = yield dispatcher.processRequest(req, res);
51
- assert.isFalse(result);
52
- assert.isTrue(endSpy.notCalled);
53
- });
43
+ it("Should not handle the request if hub does not match", async function () {
44
+ const endSpy = sinon.spy(res.end);
45
+ buildRequest(req, "hub", "conn1");
46
+ const dispatcher = new CloudEventsDispatcher("hub1");
47
+ const result = await dispatcher.handleRequest(req, res);
48
+ assert.isFalse(result);
49
+ assert.isTrue(endSpy.notCalled);
54
50
  });
55
- it("Should response with 200 when option is not specified", function () {
56
- return __awaiter(this, void 0, void 0, function* () {
57
- const endSpy = sinon.spy(res, "end");
58
- buildRequest(req, "hub", "conn1");
59
- const dispatcher = new CloudEventsDispatcher("hub", ["*"]);
60
- var result = yield dispatcher.processRequest(req, res);
61
- assert.isTrue(result, "should handle");
62
- assert.isTrue(endSpy.calledOnce, "should call once");
63
- assert.equal(200, res.statusCode, "should be 200");
64
- });
51
+ it("Should response with 200 when option is not specified", async function () {
52
+ const endSpy = sinon.spy(res, "end");
53
+ buildRequest(req, "hub", "conn1");
54
+ const dispatcher = new CloudEventsDispatcher("hub");
55
+ const result = await dispatcher.handleRequest(req, res);
56
+ assert.isTrue(result, "should handle");
57
+ assert.isTrue(endSpy.calledOnce, "should call once");
58
+ assert.equal(200, res.statusCode, "should be 200");
65
59
  });
66
- it("Should response with 200 when handler is not specified", function () {
67
- return __awaiter(this, void 0, void 0, function* () {
68
- const endSpy = sinon.spy(res, "end");
69
- buildRequest(req, "hub", "conn1");
70
- const dispatcher = new CloudEventsDispatcher("hub", ["*"], {});
71
- var result = yield dispatcher.processRequest(req, res);
72
- assert.isTrue(result, "should handle");
73
- assert.isTrue(endSpy.calledOnce, "should call once");
74
- assert.equal(200, res.statusCode, "should be 200");
75
- });
60
+ it("Should response with 200 when handler is not specified", async function () {
61
+ const endSpy = sinon.spy(res, "end");
62
+ buildRequest(req, "hub", "conn1");
63
+ const dispatcher = new CloudEventsDispatcher("hub", {});
64
+ const result = await dispatcher.handleRequest(req, res);
65
+ assert.isTrue(result, "should handle");
66
+ assert.isTrue(endSpy.calledOnce, "should call once");
67
+ assert.equal(200, res.statusCode, "should be 200");
76
68
  });
77
- it("Should response 200 even the event handler throws", function () {
78
- return __awaiter(this, void 0, void 0, function* () {
79
- const endSpy = sinon.spy(res, "end");
80
- buildRequest(req, "hub", "conn1");
81
- const dispatcher = new CloudEventsDispatcher("hub", ["*"], {
82
- onConnected: (_) => __awaiter(this, void 0, void 0, function* () {
83
- throw new Error();
84
- })
85
- });
86
- var process = dispatcher.processRequest(req, res);
87
- mockBody(req, JSON.stringify({}));
88
- var result = yield process;
89
- assert.isTrue(result, "should handle");
90
- assert.isTrue(endSpy.calledOnce, "should call once");
91
- assert.equal(200, res.statusCode, "should be error");
69
+ it("Should response 200 even the event handler throws", async function () {
70
+ const endSpy = sinon.spy(res, "end");
71
+ buildRequest(req, "hub", "conn1");
72
+ const dispatcher = new CloudEventsDispatcher("hub", {
73
+ onConnected: async (_) => {
74
+ throw new Error();
75
+ }
92
76
  });
77
+ const process = dispatcher.handleRequest(req, res);
78
+ mockBody(req, JSON.stringify({}));
79
+ const result = await process;
80
+ assert.isTrue(result, "should handle");
81
+ assert.isTrue(endSpy.calledOnce, "should call once");
82
+ assert.equal(200, res.statusCode, "should be error");
93
83
  });
94
84
  });
95
85
  //# sourceMappingURL=disconnected.spec.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"disconnected.spec.js","sourceRoot":"","sources":["../../test/disconnected.spec.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;AAClC,oCAAoC;AACpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,SAAS,YAAY,CACnB,GAAoB,EACpB,GAAW,EACX,YAAoB,EACpB,MAAe;IAEf,GAAG,CAAC,OAAO,CAAC,wBAAwB,CAAC,GAAG,yBAAyB,CAAC;IAClE,GAAG,CAAC,OAAO,CAAC,cAAc,CAAC,GAAG,iCAAiC,CAAC;IAChE,GAAG,CAAC,OAAO,CAAC,gBAAgB,CAAC,GAAG,KAAK,CAAC;IACtC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC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CAAC;YACvC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAC;YACrD,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,UAAU,EAAE,iBAAiB,CAAC,CAAC;QACvD,CAAC;KAAA,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n/* eslint-disable no-invalid-this */\nimport { CloudEventsDispatcher } from \"../src/cloudEventsDispatcher\";\nimport { assert } from \"chai\";\nimport { IncomingMessage, ServerResponse } from \"http\";\nimport { Socket } from \"net\";\nimport * as sinon from \"sinon\";\n\nfunction buildRequest(\n req: IncomingMessage,\n hub: string,\n connectionId: string,\n userId?: string\n): void {\n req.headers[\"webhook-request-origin\"] = \"xxx.webpubsub.azure.com\";\n req.headers[\"Content-Type\"] = \"application/json; charset=utf-8\";\n req.headers[\"ce-specversion\"] = \"1.0\";\n req.headers[\"ce-type\"] = \"azure.webpubsub.user.disconnected\";\n req.headers[\"ce-source\"] = `/hubs/${hub}/client/${connectionId}`;\n req.headers[\"ce-id\"] = \"1\";\n req.headers[\"ce-time\"] = new Date().toUTCString();\n if (userId !== undefined) {\n req.headers[\"ce-userId\"] = userId;\n }\n req.headers[\"ce-connectionId\"] = connectionId;\n req.headers[\"ce-hub\"] = hub;\n req.headers[\"ce-event\"] = \"disconnected\";\n}\n\nfunction mockBody(req: IncomingMessage, body: string): void {\n req.emit(\"data\", body);\n req.emit(\"end\");\n}\n\ndescribe(\"Can handle disconnected event\", function() {\n let req: IncomingMessage;\n let res: ServerResponse;\n\n beforeEach(function() {\n req = new IncomingMessage(new Socket());\n res = new ServerResponse(req);\n });\n\n it(\"Should not handle the request if request is not cloud events\", async function() {\n const endSpy = sinon.spy(res.end);\n\n const dispatcher = new CloudEventsDispatcher(\"hub1\", [\"*\"]);\n var result = await dispatcher.processRequest(req, res);\n assert.isFalse(result);\n assert.isTrue(endSpy.notCalled);\n });\n\n it(\"Should not handle the request if hub does not match\", async function() {\n const endSpy = sinon.spy(res.end);\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub1\", [\"*\"]);\n var result = await dispatcher.processRequest(req, res);\n assert.isFalse(result);\n assert.isTrue(endSpy.notCalled);\n });\n\n it(\"Should response with 200 when option is not specified\", async function() {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", [\"*\"]);\n var result = await dispatcher.processRequest(req, res);\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be 200\");\n });\n\n it(\"Should response with 200 when handler is not specified\", async function() {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", [\"*\"], {});\n var result = await dispatcher.processRequest(req, res);\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be 200\");\n });\n\n it(\"Should response 200 even the event handler throws\", async function() {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", [\"*\"], {\n onConnected: async (_) => {\n throw new Error();\n }\n });\n var process = dispatcher.processRequest(req, res);\n mockBody(req, JSON.stringify({}));\n var result = await process;\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be error\");\n });\n});\n"]}
1
+ {"version":3,"file":"disconnected.spec.js","sourceRoot":"","sources":["../../test/disconnected.spec.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,oCAAoC;AACpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,M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AAG,IAAI,qBAAqB,CAAC,KAAK,EAAE;YAClD,WAAW,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;gBACvB,MAAM,IAAI,KAAK,EAAE,CAAC;YACpB,CAAC;SACF,CAAC,CAAC;QACH,MAAM,OAAO,GAAG,UAAU,CAAC,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACnD,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC;QAClC,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC;QAC7B,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;QACvC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAC;QACrD,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,UAAU,EAAE,iBAAiB,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n/* eslint-disable no-invalid-this */\nimport { CloudEventsDispatcher } from \"../src/cloudEventsDispatcher\";\nimport { assert } from \"chai\";\nimport { IncomingMessage, ServerResponse } from \"http\";\nimport { Socket } from \"net\";\nimport * as sinon from \"sinon\";\n\nfunction buildRequest(\n req: IncomingMessage,\n hub: string,\n connectionId: string,\n userId?: string\n): void {\n req.headers[\"webhook-request-origin\"] = \"xxx.webpubsub.azure.com\";\n req.headers[\"Content-Type\"] = \"application/json; charset=utf-8\";\n req.headers[\"ce-awpsversion\"] = \"1.0\";\n req.headers[\"ce-specversion\"] = \"1.0\";\n req.headers[\"ce-type\"] = \"azure.webpubsub.user.disconnected\";\n req.headers[\"ce-source\"] = `/hubs/${hub}/client/${connectionId}`;\n req.headers[\"ce-id\"] = \"1\";\n req.headers[\"ce-time\"] = new Date().toUTCString();\n if (userId !== undefined) {\n req.headers[\"ce-userId\"] = userId;\n }\n req.headers[\"ce-connectionId\"] = connectionId;\n req.headers[\"ce-hub\"] = hub;\n req.headers[\"ce-event\"] = \"disconnected\";\n}\n\nfunction mockBody(req: IncomingMessage, body: string): void {\n req.emit(\"data\", body);\n req.emit(\"end\");\n}\n\ndescribe(\"Can handle disconnected event\", function() {\n let req: IncomingMessage;\n let res: ServerResponse;\n\n beforeEach(function() {\n req = new IncomingMessage(new Socket());\n res = new ServerResponse(req);\n });\n\n it(\"Should not handle the request if request is not cloud events\", async function() {\n const endSpy = sinon.spy(res.end);\n\n const dispatcher = new CloudEventsDispatcher(\"hub1\");\n const result = await dispatcher.handleRequest(req, res);\n assert.isFalse(result);\n assert.isTrue(endSpy.notCalled);\n });\n\n it(\"Should not handle the request if hub does not match\", async function() {\n const endSpy = sinon.spy(res.end);\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub1\");\n const result = await dispatcher.handleRequest(req, res);\n assert.isFalse(result);\n assert.isTrue(endSpy.notCalled);\n });\n\n it(\"Should response with 200 when option is not specified\", async function() {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\");\n const result = await dispatcher.handleRequest(req, res);\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be 200\");\n });\n\n it(\"Should response with 200 when handler is not specified\", async function() {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {});\n const result = await dispatcher.handleRequest(req, res);\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be 200\");\n });\n\n it(\"Should response 200 even the event handler throws\", async function() {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n onConnected: async (_) => {\n throw new Error();\n }\n });\n const process = dispatcher.handleRequest(req, res);\n mockBody(req, JSON.stringify({}));\n const result = await process;\n assert.isTrue(result, \"should handle\");\n assert.isTrue(endSpy.calledOnce, \"should call once\");\n assert.equal(200, res.statusCode, \"should be error\");\n });\n});\n"]}