@azure/web-pubsub-express 1.0.0-alpha.20211001.2 → 1.0.0-alpha.20211108.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.
- package/CHANGELOG.md +23 -1
- package/README.md +127 -31
- package/dist/index.js +52 -24
- package/dist/index.js.map +1 -1
- package/dist-esm/samples-dev/server.js +3 -3
- package/dist-esm/samples-dev/server.js.map +1 -1
- package/dist-esm/src/cloudEventsDispatcher.js +38 -18
- package/dist-esm/src/cloudEventsDispatcher.js.map +1 -1
- package/dist-esm/src/cloudEventsProtocols.js.map +1 -1
- package/dist-esm/src/logger.js +10 -0
- package/dist-esm/src/logger.js.map +1 -0
- package/dist-esm/src/webPubSubEventHandler.js +6 -6
- package/dist-esm/src/webPubSubEventHandler.js.map +1 -1
- package/dist-esm/test/connect.spec.js +25 -24
- package/dist-esm/test/connect.spec.js.map +1 -1
- package/dist-esm/test/connected.spec.js +11 -10
- package/dist-esm/test/connected.spec.js.map +1 -1
- package/dist-esm/test/ctor.spec.js +3 -3
- package/dist-esm/test/ctor.spec.js.map +1 -1
- package/dist-esm/test/disconnected.spec.js +11 -10
- package/dist-esm/test/disconnected.spec.js.map +1 -1
- package/dist-esm/test/user.spec.js +21 -20
- package/dist-esm/test/user.spec.js.map +1 -1
- package/dist-esm/test/validate.spec.js +26 -10
- package/dist-esm/test/validate.spec.js.map +1 -1
- package/package.json +2 -1
- package/types/web-pubsub-express.d.ts +11 -7
|
@@ -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,O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AU,CAAC,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACxD,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,eAAe,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,mDAAmD,EAAE,KAAK;QAC3D,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACrC,YAAY,CAAC,GAAG,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;QAElC,MAAM,UAAU,GAAG,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.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,18 +5,18 @@ 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
18
|
try {
|
|
19
|
-
new WebPubSubEventHandler("hub", ["b.com"]);
|
|
19
|
+
new WebPubSubEventHandler("hub", { allowedEndpoints: ["b.com"] });
|
|
20
20
|
assert.fail("Should have thrown ERROR_INVALID_URL");
|
|
21
21
|
}
|
|
22
22
|
catch (err) {
|
|
@@ -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,
|
|
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"]}
|
|
@@ -9,6 +9,7 @@ import * as sinon from "sinon";
|
|
|
9
9
|
function buildRequest(req, hub, connectionId, userId) {
|
|
10
10
|
req.headers["webhook-request-origin"] = "xxx.webpubsub.azure.com";
|
|
11
11
|
req.headers["Content-Type"] = "application/json; charset=utf-8";
|
|
12
|
+
req.headers["ce-awpsversion"] = "1.0";
|
|
12
13
|
req.headers["ce-specversion"] = "1.0";
|
|
13
14
|
req.headers["ce-type"] = "azure.webpubsub.user.disconnected";
|
|
14
15
|
req.headers["ce-source"] = `/hubs/${hub}/client/${connectionId}`;
|
|
@@ -34,24 +35,24 @@ describe("Can handle disconnected event", function () {
|
|
|
34
35
|
});
|
|
35
36
|
it("Should not handle the request if request is not cloud events", async function () {
|
|
36
37
|
const endSpy = sinon.spy(res.end);
|
|
37
|
-
const dispatcher = new CloudEventsDispatcher("hub1"
|
|
38
|
-
const result = await dispatcher.
|
|
38
|
+
const dispatcher = new CloudEventsDispatcher("hub1");
|
|
39
|
+
const result = await dispatcher.handleRequest(req, res);
|
|
39
40
|
assert.isFalse(result);
|
|
40
41
|
assert.isTrue(endSpy.notCalled);
|
|
41
42
|
});
|
|
42
43
|
it("Should not handle the request if hub does not match", async function () {
|
|
43
44
|
const endSpy = sinon.spy(res.end);
|
|
44
45
|
buildRequest(req, "hub", "conn1");
|
|
45
|
-
const dispatcher = new CloudEventsDispatcher("hub1"
|
|
46
|
-
const result = await dispatcher.
|
|
46
|
+
const dispatcher = new CloudEventsDispatcher("hub1");
|
|
47
|
+
const result = await dispatcher.handleRequest(req, res);
|
|
47
48
|
assert.isFalse(result);
|
|
48
49
|
assert.isTrue(endSpy.notCalled);
|
|
49
50
|
});
|
|
50
51
|
it("Should response with 200 when option is not specified", async function () {
|
|
51
52
|
const endSpy = sinon.spy(res, "end");
|
|
52
53
|
buildRequest(req, "hub", "conn1");
|
|
53
|
-
const dispatcher = new CloudEventsDispatcher("hub"
|
|
54
|
-
const result = await dispatcher.
|
|
54
|
+
const dispatcher = new CloudEventsDispatcher("hub");
|
|
55
|
+
const result = await dispatcher.handleRequest(req, res);
|
|
55
56
|
assert.isTrue(result, "should handle");
|
|
56
57
|
assert.isTrue(endSpy.calledOnce, "should call once");
|
|
57
58
|
assert.equal(200, res.statusCode, "should be 200");
|
|
@@ -59,8 +60,8 @@ describe("Can handle disconnected event", function () {
|
|
|
59
60
|
it("Should response with 200 when handler is not specified", async function () {
|
|
60
61
|
const endSpy = sinon.spy(res, "end");
|
|
61
62
|
buildRequest(req, "hub", "conn1");
|
|
62
|
-
const dispatcher = new CloudEventsDispatcher("hub",
|
|
63
|
-
const result = await dispatcher.
|
|
63
|
+
const dispatcher = new CloudEventsDispatcher("hub", {});
|
|
64
|
+
const result = await dispatcher.handleRequest(req, res);
|
|
64
65
|
assert.isTrue(result, "should handle");
|
|
65
66
|
assert.isTrue(endSpy.calledOnce, "should call once");
|
|
66
67
|
assert.equal(200, res.statusCode, "should be 200");
|
|
@@ -68,12 +69,12 @@ describe("Can handle disconnected event", function () {
|
|
|
68
69
|
it("Should response 200 even the event handler throws", async function () {
|
|
69
70
|
const endSpy = sinon.spy(res, "end");
|
|
70
71
|
buildRequest(req, "hub", "conn1");
|
|
71
|
-
const dispatcher = new CloudEventsDispatcher("hub",
|
|
72
|
+
const dispatcher = new CloudEventsDispatcher("hub", {
|
|
72
73
|
onConnected: async (_) => {
|
|
73
74
|
throw new Error();
|
|
74
75
|
}
|
|
75
76
|
});
|
|
76
|
-
const process = dispatcher.
|
|
77
|
+
const process = dispatcher.handleRequest(req, res);
|
|
77
78
|
mockBody(req, JSON.stringify({}));
|
|
78
79
|
const result = await process;
|
|
79
80
|
assert.isTrue(result, "should handle");
|
|
@@ -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;I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AAC,GAAG,EAAE,GAAG,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,mDAAmD,EAAE,KAAK;QAC3D,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACrC,YAAY,CAAC,GAAG,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;QAElC,MAAM,UAAU,GAAG,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"]}
|
|
@@ -9,6 +9,7 @@ import * as sinon from "sinon";
|
|
|
9
9
|
function buildRequest(req, hub, connectionId, userId) {
|
|
10
10
|
req.headers["webhook-request-origin"] = "xxx.webpubsub.azure.com";
|
|
11
11
|
req.headers["Content-Type"] = "application/json; charset=utf-8";
|
|
12
|
+
req.headers["ce-awpsversion"] = "1.0";
|
|
12
13
|
req.headers["ce-specversion"] = "1.0";
|
|
13
14
|
req.headers["ce-type"] = "azure.webpubsub.user.connect";
|
|
14
15
|
req.headers["ce-source"] = `/hubs/${hub}/client/${connectionId}`;
|
|
@@ -34,24 +35,24 @@ describe("Can handle user event", function () {
|
|
|
34
35
|
});
|
|
35
36
|
it("Should not handle the request if request is not cloud events", async function () {
|
|
36
37
|
const endSpy = sinon.spy(res.end);
|
|
37
|
-
const dispatcher = new CloudEventsDispatcher("hub1"
|
|
38
|
-
const result = await dispatcher.
|
|
38
|
+
const dispatcher = new CloudEventsDispatcher("hub1");
|
|
39
|
+
const result = await dispatcher.handleRequest(req, res);
|
|
39
40
|
assert.isFalse(result);
|
|
40
41
|
assert.isTrue(endSpy.notCalled);
|
|
41
42
|
});
|
|
42
43
|
it("Should not handle the request if hub does not match", async function () {
|
|
43
44
|
const endSpy = sinon.spy(res.end);
|
|
44
45
|
buildRequest(req, "hub", "conn1");
|
|
45
|
-
const dispatcher = new CloudEventsDispatcher("hub1"
|
|
46
|
-
const result = await dispatcher.
|
|
46
|
+
const dispatcher = new CloudEventsDispatcher("hub1");
|
|
47
|
+
const result = await dispatcher.handleRequest(req, res);
|
|
47
48
|
assert.isFalse(result);
|
|
48
49
|
assert.isTrue(endSpy.notCalled);
|
|
49
50
|
});
|
|
50
51
|
it("Should response with 200 when option is not specified", async function () {
|
|
51
52
|
const endSpy = sinon.spy(res, "end");
|
|
52
53
|
buildRequest(req, "hub", "conn1");
|
|
53
|
-
const dispatcher = new CloudEventsDispatcher("hub"
|
|
54
|
-
const result = await dispatcher.
|
|
54
|
+
const dispatcher = new CloudEventsDispatcher("hub");
|
|
55
|
+
const result = await dispatcher.handleRequest(req, res);
|
|
55
56
|
assert.isTrue(result, "should handle");
|
|
56
57
|
assert.isTrue(endSpy.calledOnce, "should call once");
|
|
57
58
|
assert.equal(200, res.statusCode, "should be 200");
|
|
@@ -59,8 +60,8 @@ describe("Can handle user event", function () {
|
|
|
59
60
|
it("Should response with 200 when handler is not specified", async function () {
|
|
60
61
|
const endSpy = sinon.spy(res, "end");
|
|
61
62
|
buildRequest(req, "hub", "conn1");
|
|
62
|
-
const dispatcher = new CloudEventsDispatcher("hub",
|
|
63
|
-
const result = await dispatcher.
|
|
63
|
+
const dispatcher = new CloudEventsDispatcher("hub", {});
|
|
64
|
+
const result = await dispatcher.handleRequest(req, res);
|
|
64
65
|
assert.isTrue(result, "should handle");
|
|
65
66
|
assert.isTrue(endSpy.calledOnce, "should call once");
|
|
66
67
|
assert.equal(200, res.statusCode, "should be 200");
|
|
@@ -68,12 +69,12 @@ describe("Can handle user event", function () {
|
|
|
68
69
|
it("Should response with error when handler returns error", async function () {
|
|
69
70
|
const endSpy = sinon.spy(res, "end");
|
|
70
71
|
buildRequest(req, "hub", "conn1");
|
|
71
|
-
const dispatcher = new CloudEventsDispatcher("hub",
|
|
72
|
+
const dispatcher = new CloudEventsDispatcher("hub", {
|
|
72
73
|
handleUserEvent: async (_, response) => {
|
|
73
74
|
response.fail(500);
|
|
74
75
|
}
|
|
75
76
|
});
|
|
76
|
-
const process = dispatcher.
|
|
77
|
+
const process = dispatcher.handleRequest(req, res);
|
|
77
78
|
mockBody(req, JSON.stringify({}));
|
|
78
79
|
const result = await process;
|
|
79
80
|
assert.isTrue(result, "should handle");
|
|
@@ -83,12 +84,12 @@ describe("Can handle user event", function () {
|
|
|
83
84
|
it("Should response with success when handler returns success", async function () {
|
|
84
85
|
const endSpy = sinon.spy(res, "end");
|
|
85
86
|
buildRequest(req, "hub", "conn1");
|
|
86
|
-
const dispatcher = new CloudEventsDispatcher("hub",
|
|
87
|
+
const dispatcher = new CloudEventsDispatcher("hub", {
|
|
87
88
|
handleUserEvent: async (_, response) => {
|
|
88
89
|
response.success();
|
|
89
90
|
}
|
|
90
91
|
});
|
|
91
|
-
const process = dispatcher.
|
|
92
|
+
const process = dispatcher.handleRequest(req, res);
|
|
92
93
|
mockBody(req, JSON.stringify({}));
|
|
93
94
|
const result = await process;
|
|
94
95
|
assert.isTrue(result, "should handle");
|
|
@@ -98,12 +99,12 @@ describe("Can handle user event", function () {
|
|
|
98
99
|
it("Should response with success when returns success binary", async function () {
|
|
99
100
|
const endSpy = sinon.spy(res, "end");
|
|
100
101
|
buildRequest(req, "hub", "conn1");
|
|
101
|
-
const dispatcher = new CloudEventsDispatcher("hub",
|
|
102
|
+
const dispatcher = new CloudEventsDispatcher("hub", {
|
|
102
103
|
handleUserEvent: async (_, response) => {
|
|
103
104
|
response.success("a");
|
|
104
105
|
}
|
|
105
106
|
});
|
|
106
|
-
const process = dispatcher.
|
|
107
|
+
const process = dispatcher.handleRequest(req, res);
|
|
107
108
|
mockBody(req, JSON.stringify({}));
|
|
108
109
|
const result = await process;
|
|
109
110
|
assert.isTrue(result, "should handle");
|
|
@@ -114,12 +115,12 @@ describe("Can handle user event", function () {
|
|
|
114
115
|
it("Should response with success when returns success text", async function () {
|
|
115
116
|
const endSpy = sinon.spy(res, "end");
|
|
116
117
|
buildRequest(req, "hub", "conn1");
|
|
117
|
-
const dispatcher = new CloudEventsDispatcher("hub",
|
|
118
|
+
const dispatcher = new CloudEventsDispatcher("hub", {
|
|
118
119
|
handleUserEvent: async (_, response) => {
|
|
119
120
|
response.success("a", "text");
|
|
120
121
|
}
|
|
121
122
|
});
|
|
122
|
-
const process = dispatcher.
|
|
123
|
+
const process = dispatcher.handleRequest(req, res);
|
|
123
124
|
mockBody(req, JSON.stringify({}));
|
|
124
125
|
const result = await process;
|
|
125
126
|
assert.isTrue(result, "should handle");
|
|
@@ -130,12 +131,12 @@ describe("Can handle user event", function () {
|
|
|
130
131
|
it("Should response with success when returns success json", async function () {
|
|
131
132
|
const endSpy = sinon.spy(res, "end");
|
|
132
133
|
buildRequest(req, "hub", "conn1");
|
|
133
|
-
const dispatcher = new CloudEventsDispatcher("hub",
|
|
134
|
+
const dispatcher = new CloudEventsDispatcher("hub", {
|
|
134
135
|
handleUserEvent: async (_, response) => {
|
|
135
136
|
response.success("a", "json");
|
|
136
137
|
}
|
|
137
138
|
});
|
|
138
|
-
const process = dispatcher.
|
|
139
|
+
const process = dispatcher.handleRequest(req, res);
|
|
139
140
|
mockBody(req, JSON.stringify({}));
|
|
140
141
|
const result = await process;
|
|
141
142
|
assert.isTrue(result, "should handle");
|
|
@@ -146,7 +147,7 @@ describe("Can handle user event", function () {
|
|
|
146
147
|
it("Should be able to set connection state", async function () {
|
|
147
148
|
const endSpy = sinon.spy(res, "end");
|
|
148
149
|
buildRequest(req, "hub", "conn1");
|
|
149
|
-
const dispatcher = new CloudEventsDispatcher("hub",
|
|
150
|
+
const dispatcher = new CloudEventsDispatcher("hub", {
|
|
150
151
|
handleUserEvent: async (_, response) => {
|
|
151
152
|
response.setState("key1", "val1");
|
|
152
153
|
response.setState("key2", "val2");
|
|
@@ -155,7 +156,7 @@ describe("Can handle user event", function () {
|
|
|
155
156
|
response.success();
|
|
156
157
|
}
|
|
157
158
|
});
|
|
158
|
-
const process = dispatcher.
|
|
159
|
+
const process = dispatcher.handleRequest(req, res);
|
|
159
160
|
mockBody(req, JSON.stringify({}));
|
|
160
161
|
const result = await process;
|
|
161
162
|
assert.isTrue(result, "should handle");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.spec.js","sourceRoot":"","sources":["../../test/user.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,8BAA8B,CAAC;IACxD,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;K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C,CACxC,CAAC;IACJ,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-specversion\"] = \"1.0\";\n req.headers[\"ce-type\"] = \"azure.webpubsub.user.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 user 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.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 const 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 const 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 const 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 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 handleUserEvent: async (_, response) => {\n response.fail(500);\n }\n });\n const process = dispatcher.processRequest(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(500, 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 handleUserEvent: async (_, response) => {\n response.success();\n }\n });\n const process = dispatcher.processRequest(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 returns success binary\", async function() {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", [\"*\"], {\n handleUserEvent: async (_, response) => {\n response.success(\"a\");\n }\n });\n const process = dispatcher.processRequest(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 assert.equal(\"application/octet-stream\", res.getHeader(\"content-type\"), \"should be binary\");\n });\n\n it(\"Should response with success when returns success text\", async function() {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", [\"*\"], {\n handleUserEvent: async (_, response) => {\n response.success(\"a\", \"text\");\n }\n });\n const process = dispatcher.processRequest(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 assert.equal(\"text/plain; charset=utf-8\", res.getHeader(\"content-type\"), \"should be text\");\n });\n\n it(\"Should response with success when returns success json\", async function() {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", [\"*\"], {\n handleUserEvent: async (_, response) => {\n response.success(\"a\", \"json\");\n }\n });\n const process = dispatcher.processRequest(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 assert.equal(\n \"application/json; charset=utf-8\",\n res.getHeader(\"content-type\"),\n \"should be json\"\n );\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 handleUserEvent: async (_, response) => {\n response.setState(\"key1\", \"val1\");\n response.setState(\"key2\", \"val2\");\n response.setState(\"key1\", \"val3\");\n response.setState(\"key3\", \"\");\n response.success();\n }\n });\n const process = dispatcher.processRequest(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 assert.equal(\n Buffer.from(\n JSON.stringify({\n key1: \"val3\",\n key2: \"val2\",\n key3: \"\"\n })\n ).toString(\"base64\"),\n res.getHeader(\"ce-connectionState\"),\n \"should contain multiple state headers\"\n );\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"user.spec.js","sourceRoot":"","sources":["../../test/user.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,gBAAgB,CAAC,GAAG,KAAK,CAAC;IACtC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,8BAA8B,CAAC;IACxD,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,GAAG,SAAS,GAAG,WAAW,YAAY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AAC,EACnC,uCAAuC,CACxC,CAAC;IACJ,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.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 user 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 handleUserEvent: async (_, response) => {\n response.fail(500);\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(500, 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 handleUserEvent: 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 returns success binary\", async function() {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n handleUserEvent: async (_, response) => {\n response.success(\"a\");\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 assert.equal(\"application/octet-stream\", res.getHeader(\"content-type\"), \"should be binary\");\n });\n\n it(\"Should response with success when returns success text\", async function() {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n handleUserEvent: async (_, response) => {\n response.success(\"a\", \"text\");\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 assert.equal(\"text/plain; charset=utf-8\", res.getHeader(\"content-type\"), \"should be text\");\n });\n\n it(\"Should response with success when returns success json\", async function() {\n const endSpy = sinon.spy(res, \"end\");\n buildRequest(req, \"hub\", \"conn1\");\n\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n handleUserEvent: async (_, response) => {\n response.success(\"a\", \"json\");\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 assert.equal(\n \"application/json; charset=utf-8\",\n res.getHeader(\"content-type\"),\n \"should be json\"\n );\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 handleUserEvent: async (_, response) => {\n response.setState(\"key1\", \"val1\");\n response.setState(\"key2\", \"val2\");\n response.setState(\"key1\", \"val3\");\n response.setState(\"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 assert.equal(\n Buffer.from(\n JSON.stringify({\n key1: \"val3\",\n key2: \"val2\",\n key3: \"\"\n })\n ).toString(\"base64\"),\n res.getHeader(\"ce-connectionState\"),\n \"should contain multiple state headers\"\n );\n });\n});\n"]}
|
|
@@ -9,27 +9,43 @@ describe("Abuse protection works", function () {
|
|
|
9
9
|
it("Only requests with valid header will be processed", function () {
|
|
10
10
|
const req = new IncomingMessage(new Socket());
|
|
11
11
|
const res = new ServerResponse(req);
|
|
12
|
-
const dispatcher = new CloudEventsDispatcher("hub"
|
|
13
|
-
const result = dispatcher.
|
|
12
|
+
const dispatcher = new CloudEventsDispatcher("hub");
|
|
13
|
+
const result = dispatcher.handlePreflight(req, res);
|
|
14
14
|
assert.isFalse(result);
|
|
15
15
|
});
|
|
16
|
-
it("
|
|
16
|
+
it("When allow all endpoints the requested host should return", function () {
|
|
17
17
|
const req = new IncomingMessage(new Socket());
|
|
18
|
+
req.headers["ce-awpsversion"] = "1.0";
|
|
18
19
|
req.headers["webhook-request-origin"] = "a.com";
|
|
19
20
|
const res = new ServerResponse(req);
|
|
20
|
-
const dispatcher = new CloudEventsDispatcher("hub"
|
|
21
|
-
const result = dispatcher.
|
|
21
|
+
const dispatcher = new CloudEventsDispatcher("hub");
|
|
22
|
+
const result = dispatcher.handlePreflight(req, res);
|
|
22
23
|
assert.isTrue(result);
|
|
23
|
-
assert.equal("
|
|
24
|
+
assert.equal("a.com", res.getHeader("webhook-allowed-origin"));
|
|
24
25
|
});
|
|
25
|
-
it("Support valid url in allowed endpoints", function () {
|
|
26
|
+
it("Support valid url in allowed endpoints and only return the one in the request", function () {
|
|
26
27
|
const req = new IncomingMessage(new Socket());
|
|
28
|
+
req.headers["ce-awpsversion"] = "1.0";
|
|
27
29
|
req.headers["webhook-request-origin"] = "a.com";
|
|
28
30
|
const res = new ServerResponse(req);
|
|
29
|
-
const dispatcher = new CloudEventsDispatcher("hub",
|
|
30
|
-
|
|
31
|
+
const dispatcher = new CloudEventsDispatcher("hub", {
|
|
32
|
+
allowedEndpoints: ["https://a.com/c", "http://b.com"]
|
|
33
|
+
});
|
|
34
|
+
const result = dispatcher.handlePreflight(req, res);
|
|
31
35
|
assert.isTrue(result);
|
|
32
|
-
assert.equal("
|
|
36
|
+
assert.equal("a.com", res.getHeader("webhook-allowed-origin"));
|
|
37
|
+
});
|
|
38
|
+
it("Not allowed endpoints should return 400", function () {
|
|
39
|
+
const req = new IncomingMessage(new Socket());
|
|
40
|
+
req.headers["ce-awpsversion"] = "1.0";
|
|
41
|
+
req.headers["webhook-request-origin"] = "a.com";
|
|
42
|
+
const res = new ServerResponse(req);
|
|
43
|
+
const dispatcher = new CloudEventsDispatcher("hub", {
|
|
44
|
+
allowedEndpoints: ["https://c.com/c", "http://b.com"]
|
|
45
|
+
});
|
|
46
|
+
const result = dispatcher.handlePreflight(req, res);
|
|
47
|
+
assert.isTrue(result);
|
|
48
|
+
assert.equal(400, res.statusCode);
|
|
33
49
|
});
|
|
34
50
|
});
|
|
35
51
|
//# sourceMappingURL=validate.spec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.spec.js","sourceRoot":"","sources":["../../test/validate.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;AA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;QACtC,GAAG,CAAC,OAAO,CAAC,wBAAwB,CAAC,GAAG,OAAO,CAAC;QAChD,MAAM,GAAG,GAAG,IAAI,cAAc,CAAC,GAAG,CAAC,CAAC;QACpC,MAAM,UAAU,GAAG,IAAI,qBAAqB,CAAC,KAAK,EAAE;YAClD,gBAAgB,EAAE,CAAC,iBAAiB,EAAE,cAAc,CAAC;SACtD,CAAC,CAAC;QAEH,MAAM,MAAM,GAAG,UAAU,CAAC,eAAe,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACpD,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACtB,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,UAAU,CAAC,CAAC;IACpC,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\";\n\ndescribe(\"Abuse protection works\", function() {\n it(\"Only requests with valid header will be processed\", function() {\n const req = new IncomingMessage(new Socket());\n const res = new ServerResponse(req);\n const dispatcher = new CloudEventsDispatcher(\"hub\");\n\n const result = dispatcher.handlePreflight(req, res);\n assert.isFalse(result);\n });\n\n it(\"When allow all endpoints the requested host should return\", function() {\n const req = new IncomingMessage(new Socket());\n req.headers[\"ce-awpsversion\"] = \"1.0\";\n req.headers[\"webhook-request-origin\"] = \"a.com\";\n const res = new ServerResponse(req);\n const dispatcher = new CloudEventsDispatcher(\"hub\");\n\n const result = dispatcher.handlePreflight(req, res);\n assert.isTrue(result);\n assert.equal(\"a.com\", res.getHeader(\"webhook-allowed-origin\"));\n });\n\n it(\"Support valid url in allowed endpoints and only return the one in the request\", function() {\n const req = new IncomingMessage(new Socket());\n req.headers[\"ce-awpsversion\"] = \"1.0\";\n req.headers[\"webhook-request-origin\"] = \"a.com\";\n const res = new ServerResponse(req);\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n allowedEndpoints: [\"https://a.com/c\", \"http://b.com\"]\n });\n\n const result = dispatcher.handlePreflight(req, res);\n assert.isTrue(result);\n assert.equal(\"a.com\", res.getHeader(\"webhook-allowed-origin\"));\n });\n\n it(\"Not allowed endpoints should return 400\", function() {\n const req = new IncomingMessage(new Socket());\n req.headers[\"ce-awpsversion\"] = \"1.0\";\n req.headers[\"webhook-request-origin\"] = \"a.com\";\n const res = new ServerResponse(req);\n const dispatcher = new CloudEventsDispatcher(\"hub\", {\n allowedEndpoints: [\"https://c.com/c\", \"http://b.com\"]\n });\n\n const result = dispatcher.handlePreflight(req, res);\n assert.isTrue(result);\n assert.equal(400, res.statusCode);\n });\n});\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azure/web-pubsub-express",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.20211108.2",
|
|
4
4
|
"description": "Azure Web PubSub CloudEvents handlers",
|
|
5
5
|
"sdk-type": "client",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -57,6 +57,7 @@
|
|
|
57
57
|
"sideEffects": false,
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"tslib": "^2.2.0",
|
|
60
|
+
"@azure/logger": "^1.0.0",
|
|
60
61
|
"cloudevents": "^4.0.0"
|
|
61
62
|
},
|
|
62
63
|
"devDependencies": {
|
|
@@ -70,6 +70,10 @@ export declare interface ConnectRequest {
|
|
|
70
70
|
* The queries that the client WebSocket connection has when it connects.
|
|
71
71
|
*/
|
|
72
72
|
queries?: Record<string, string[]>;
|
|
73
|
+
/**
|
|
74
|
+
* The headers that the client WebSocket connection has when it connects.
|
|
75
|
+
*/
|
|
76
|
+
headers?: Record<string, string[]>;
|
|
73
77
|
/**
|
|
74
78
|
* The subprotocols that the client WebSocket connection uses to do handshake.
|
|
75
79
|
*/
|
|
@@ -212,7 +216,7 @@ export declare class WebPubSubEventHandler {
|
|
|
212
216
|
* import express from "express";
|
|
213
217
|
* import { WebPubSubEventHandler } from "@azure/web-pubsub-express";
|
|
214
218
|
* const endpoint = "https://xxxx.webpubsubdev.azure.com"
|
|
215
|
-
* const handler = new WebPubSubEventHandler('chat',
|
|
219
|
+
* const handler = new WebPubSubEventHandler('chat', {
|
|
216
220
|
* handleConnect: (req, res) => {
|
|
217
221
|
* console.log(JSON.stringify(req));
|
|
218
222
|
* return {};
|
|
@@ -224,15 +228,15 @@ export declare class WebPubSubEventHandler {
|
|
|
224
228
|
* console.log(JSON.stringify(req));
|
|
225
229
|
* res.success("Hey " + req.data, req.dataType);
|
|
226
230
|
* };
|
|
231
|
+
* allowedEndpoints: [ endpoint ]
|
|
227
232
|
* },
|
|
228
233
|
* });
|
|
229
234
|
* ```
|
|
230
235
|
*
|
|
231
236
|
* @param hub - The name of the hub to listen to
|
|
232
|
-
* @param allowedEndpoints - The allowed endpoints for the incoming CloudEvents request
|
|
233
237
|
* @param options - Options to configure the event handler
|
|
234
238
|
*/
|
|
235
|
-
constructor(hub: string,
|
|
239
|
+
constructor(hub: string, options?: WebPubSubEventHandlerOptions);
|
|
236
240
|
/**
|
|
237
241
|
* Get the middleware to process the CloudEvents requests
|
|
238
242
|
*/
|
|
@@ -247,10 +251,6 @@ export declare interface WebPubSubEventHandlerOptions {
|
|
|
247
251
|
* Custom serving path for the path of the CloudEvents handler.
|
|
248
252
|
*/
|
|
249
253
|
path?: string;
|
|
250
|
-
/**
|
|
251
|
-
* Configures if you'd like to dump the incoming HTTP request.
|
|
252
|
-
*/
|
|
253
|
-
dumpRequest?: boolean;
|
|
254
254
|
/**
|
|
255
255
|
* Handle 'connect' event, the service waits for the response to proceed.
|
|
256
256
|
*/
|
|
@@ -268,6 +268,10 @@ export declare interface WebPubSubEventHandlerOptions {
|
|
|
268
268
|
* Event triggers for "disconnected" unblocking event. This is an unblocking event and the service does not wait for the response.
|
|
269
269
|
*/
|
|
270
270
|
onDisconnected?: (disconnectedRequest: DisconnectedRequest) => void;
|
|
271
|
+
/**
|
|
272
|
+
* If not specified, by default allow all the endpoints, otherwise only allow specified endpoints
|
|
273
|
+
*/
|
|
274
|
+
allowedEndpoints?: string[];
|
|
271
275
|
}
|
|
272
276
|
|
|
273
277
|
export { }
|