@azure/web-pubsub-express 1.0.0-beta.3 → 1.0.1-alpha.20220103.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 +40 -0
- package/README.md +127 -31
- package/dist/index.js +66 -36
- 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 +45 -25
- 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/utils.js +5 -3
- package/dist-esm/src/utils.js.map +1 -1
- package/dist-esm/src/webPubSubEventHandler.js +8 -8
- package/dist-esm/src/webPubSubEventHandler.js.map +1 -1
- package/dist-esm/test/connect.spec.js +57 -56
- package/dist-esm/test/connect.spec.js.map +1 -1
- package/dist-esm/test/connected.spec.js +13 -12
- package/dist-esm/test/connected.spec.js.map +1 -1
- package/dist-esm/test/ctor.spec.js +4 -4
- package/dist-esm/test/ctor.spec.js.map +1 -1
- package/dist-esm/test/disconnected.spec.js +13 -12
- package/dist-esm/test/disconnected.spec.js.map +1 -1
- package/dist-esm/test/user.spec.js +50 -49
- 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 +17 -31
- package/types/web-pubsub-express.d.ts +24 -20
|
@@ -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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AAM,EAAE,EAAE,CAAC,CAAC;gBACzB,GAAG,CAAC,OAAO,EAAE,CAAC;YAChB,CAAC;SACF,CAAC,CAAC;QACH,IAAI,OAAO,GAAG,UAAU,CAAC,cAAc,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAClD,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC;QAClC,IAAI,MAAM,GAAG,MAAM,OAAO,CAAC;QAC3B,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;QAEvD,MAAM,CAAC,KAAK,CACV,MAAM,CAAC,IAAI,CACT,IAAI,CAAC,SAAS,CAAC;YACb,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,EAAE;SACT,CAAC,CACH,CAAC,QAAQ,CAAC,QAAQ,CAAC,EACpB,GAAG,CAAC,SAAS,CAAC,oBAAoB,CAAC,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-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 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 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 (_, res) => {\n res.fail(500);\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(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 (_, 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 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 (_, res) => {\n res.success(\"a\");\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 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 (_, res) => {\n res.success(\"a\", \"text\");\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 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 (_, res) => {\n res.success(\"a\", \"json\");\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 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 (_, res) => {\n res.setState(\"key1\", \"val1\");\n res.setState(\"key2\", \"val2\");\n res.setState(\"key1\", \"val3\");\n res.setState(\"key3\", \"\");\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 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.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QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;gBAC9B,QAAQ,CAAC,OAAO,EAAE,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;QAEvD,MAAM,CAAC,KAAK,CACV,MAAM,CAAC,IAAI,CACT,IAAI,CAAC,SAAS,CAAC;YACb,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,EAAE;SACT,CAAC,CACH,CAAC,QAAQ,CAAC,QAAQ,CAAC,EACpB,GAAG,CAAC,SAAS,CAAC,oBAAoB,CAAC,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
|
-
|
|
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
|
-
|
|
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;AAE7B,QAAQ,CAAC,wBAAwB,EAAE;IACjC,EAAE,CAAC,mDAAmD,EAAE;QACtD,MAAM,GAAG,GAAG,IAAI,eAAe,CAAC,IAAI,MAAM,EAAE,CAAC,CAAC;QAC9C,MAAM,GAAG,GAAG,IAAI,cAAc,CAAC,GAAG,CAAC,CAAC;QACpC,MAAM,UAAU,GAAG,IAAI,qBAAqB,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;
|
|
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,E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AC,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.
|
|
3
|
+
"version": "1.0.1-alpha.20220103.2",
|
|
4
4
|
"description": "Azure Web PubSub CloudEvents handlers",
|
|
5
5
|
"sdk-type": "client",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"build:browser": "echo \"Browser is not supported.\" && exit 0",
|
|
12
12
|
"build:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1",
|
|
13
13
|
"build:samples": "echo Obsolete.",
|
|
14
|
-
"build:test": "tsc -p . && rollup -c
|
|
15
|
-
"build": "tsc -p . && rollup -c 2>&1 && api-extractor run --local",
|
|
14
|
+
"build:test": "tsc -p . && rollup -c 2>&1",
|
|
15
|
+
"build": "npm run clean && tsc -p . && rollup -c 2>&1 && api-extractor run --local",
|
|
16
16
|
"check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
|
|
17
17
|
"format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
|
|
18
18
|
"clean": "rimraf dist dist-esm test-dist temp types *.tgz *.log",
|
|
@@ -22,16 +22,14 @@
|
|
|
22
22
|
"integration-test:node": "echo skipped",
|
|
23
23
|
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
|
|
24
24
|
"lint:fix": "eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]",
|
|
25
|
-
"lint": "eslint package.json api-extractor.json src test --ext .ts
|
|
25
|
+
"lint": "eslint package.json api-extractor.json src test --ext .ts",
|
|
26
26
|
"pack": "npm pack 2>&1",
|
|
27
|
-
"prebuild": "npm run clean",
|
|
28
27
|
"test:browser": "echo \"Browser is not supported.\" && exit 0",
|
|
29
28
|
"test:node": "npm run build:test && npm run unit-test:node && npm run integration-test:node",
|
|
30
29
|
"test": "npm run build:test && npm run unit-test && npm run integration-test",
|
|
31
30
|
"unit-test:browser": "echo \"Browser is not supported.\" && exit 0",
|
|
32
|
-
"unit-test:node": "mocha --reporter ../../../common/tools/mocha-multi-reporter.js
|
|
33
|
-
"unit-test": "npm run unit-test:node && npm run unit-test:browser"
|
|
34
|
-
"docs": "typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src"
|
|
31
|
+
"unit-test:node": "mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace \"test/{,!(browser)/**/}*.spec.ts\"",
|
|
32
|
+
"unit-test": "npm run unit-test:node && npm run unit-test:browser"
|
|
35
33
|
},
|
|
36
34
|
"files": [
|
|
37
35
|
"dist/",
|
|
@@ -43,7 +41,7 @@
|
|
|
43
41
|
],
|
|
44
42
|
"repository": "github:Azure/azure-sdk-for-js",
|
|
45
43
|
"keywords": [
|
|
46
|
-
"
|
|
44
|
+
"azure",
|
|
47
45
|
"cloud"
|
|
48
46
|
],
|
|
49
47
|
"author": "Microsoft Corporation",
|
|
@@ -54,31 +52,25 @@
|
|
|
54
52
|
"engines": {
|
|
55
53
|
"node": ">=12.0.0"
|
|
56
54
|
},
|
|
57
|
-
"homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/
|
|
55
|
+
"homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/web-pubsub/web-pubsub-express/README.md",
|
|
58
56
|
"sideEffects": false,
|
|
59
57
|
"dependencies": {
|
|
60
58
|
"tslib": "^2.2.0",
|
|
59
|
+
"@azure/logger": "^1.0.0",
|
|
61
60
|
"cloudevents": "^4.0.0"
|
|
62
61
|
},
|
|
63
62
|
"devDependencies": {
|
|
64
|
-
"@azure/dev-tool": "
|
|
65
|
-
"@azure/eslint-plugin-azure-sdk": "
|
|
66
|
-
"@azure/test-
|
|
67
|
-
"@microsoft/api-extractor": "7.
|
|
68
|
-
"@rollup/plugin-commonjs": "11.0.2",
|
|
69
|
-
"@rollup/plugin-json": "^4.0.0",
|
|
70
|
-
"@rollup/plugin-multi-entry": "^3.0.0",
|
|
71
|
-
"@rollup/plugin-node-resolve": "^8.0.0",
|
|
72
|
-
"@rollup/plugin-replace": "^2.2.0",
|
|
63
|
+
"@azure/dev-tool": ">=1.0.0-alpha <1.0.0-alphb",
|
|
64
|
+
"@azure/eslint-plugin-azure-sdk": ">=3.0.0-alpha <3.0.0-alphb",
|
|
65
|
+
"@azure-tools/test-recorder": "^1.0.0",
|
|
66
|
+
"@microsoft/api-extractor": "^7.18.11",
|
|
73
67
|
"@types/chai": "^4.1.6",
|
|
74
68
|
"@types/express": "^4.16.0",
|
|
75
69
|
"@types/express-serve-static-core": "^4.17.19",
|
|
76
70
|
"@types/jsonwebtoken": "~8.5.0",
|
|
77
71
|
"@types/mocha": "^7.0.2",
|
|
78
72
|
"@types/node": "^12.0.0",
|
|
79
|
-
"@types/query-string": "6.2.0",
|
|
80
73
|
"@types/sinon": "^9.0.4",
|
|
81
|
-
"assert": "^1.4.1",
|
|
82
74
|
"chai": "^4.2.0",
|
|
83
75
|
"cross-env": "^7.0.2",
|
|
84
76
|
"dotenv": "^8.2.0",
|
|
@@ -98,20 +90,14 @@
|
|
|
98
90
|
"karma-mocha-reporter": "^2.2.5",
|
|
99
91
|
"karma-sourcemap-loader": "^0.3.8",
|
|
100
92
|
"mocha": "^7.1.1",
|
|
101
|
-
"mocha-junit-reporter": "^
|
|
102
|
-
"nyc": "^
|
|
103
|
-
"prettier": "^
|
|
104
|
-
"puppeteer": "^
|
|
105
|
-
"query-string": "^5.0.0",
|
|
93
|
+
"mocha-junit-reporter": "^2.0.0",
|
|
94
|
+
"nyc": "^15.0.0",
|
|
95
|
+
"prettier": "^2.5.1",
|
|
96
|
+
"puppeteer": "^10.2.0",
|
|
106
97
|
"rimraf": "^3.0.0",
|
|
107
98
|
"rollup": "^1.16.3",
|
|
108
|
-
"rollup-plugin-shim": "^1.0.0",
|
|
109
|
-
"rollup-plugin-sourcemaps": "^0.4.2",
|
|
110
|
-
"rollup-plugin-terser": "^5.1.1",
|
|
111
|
-
"rollup-plugin-visualizer": "^4.0.4",
|
|
112
99
|
"sinon": "^9.0.2",
|
|
113
100
|
"source-map-support": "^0.5.9",
|
|
114
|
-
"typedoc": "0.15.2",
|
|
115
101
|
"typescript": "~4.2.0"
|
|
116
102
|
},
|
|
117
103
|
"//sampleConfiguration": {
|
|
@@ -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
|
*/
|
|
@@ -108,19 +112,19 @@ export declare interface ConnectResponse {
|
|
|
108
112
|
export declare interface ConnectResponseHandler {
|
|
109
113
|
/**
|
|
110
114
|
* Set the state of the connection
|
|
111
|
-
* @param name The name of the state
|
|
112
|
-
* @param value The value of the state
|
|
115
|
+
* @param name - The name of the state
|
|
116
|
+
* @param value - The value of the state
|
|
113
117
|
*/
|
|
114
118
|
setState(name: string, value: unknown): void;
|
|
115
119
|
/**
|
|
116
120
|
* Return success response to the service.
|
|
117
|
-
* @param response The response for the connect event.
|
|
121
|
+
* @param response - The response for the connect event.
|
|
118
122
|
*/
|
|
119
123
|
success(response?: ConnectResponse): void;
|
|
120
124
|
/**
|
|
121
125
|
* Return failed response and the service will reject the client WebSocket connection.
|
|
122
|
-
* @param code Code can be 400 user error, 401 unauthorized and 500 server error.
|
|
123
|
-
* @param detail The detail of the error.
|
|
126
|
+
* @param code - Code can be 400 user error, 401 unauthorized and 500 server error.
|
|
127
|
+
* @param detail - The detail of the error.
|
|
124
128
|
*/
|
|
125
129
|
fail(code: 400 | 401 | 500, detail?: string): void;
|
|
126
130
|
}
|
|
@@ -176,20 +180,20 @@ export declare type UserEventRequest = {
|
|
|
176
180
|
export declare interface UserEventResponseHandler {
|
|
177
181
|
/**
|
|
178
182
|
* Set the state of the connection
|
|
179
|
-
* @param name The name of the state
|
|
180
|
-
* @param value The value of the state
|
|
183
|
+
* @param name - The name of the state
|
|
184
|
+
* @param value - The value of the state
|
|
181
185
|
*/
|
|
182
186
|
setState(name: string, value: unknown): void;
|
|
183
187
|
/**
|
|
184
188
|
* Return success response with data to be delivered to the client WebSocket connection.
|
|
185
|
-
* @param data The payload data to be returned to the client.
|
|
186
|
-
* @param dataType The type of the payload data.
|
|
189
|
+
* @param data - The payload data to be returned to the client.
|
|
190
|
+
* @param dataType - The type of the payload data.
|
|
187
191
|
*/
|
|
188
192
|
success(data?: string | ArrayBuffer, dataType?: "binary" | "text" | "json"): void;
|
|
189
193
|
/**
|
|
190
194
|
* Return failed response and the service will close the client WebSocket connection.
|
|
191
|
-
* @param code Code can be 400 user error, 401 unauthorized and 500 server error.
|
|
192
|
-
* @param detail The detail of the error.
|
|
195
|
+
* @param code - Code can be 400 user error, 401 unauthorized and 500 server error.
|
|
196
|
+
* @param detail - The detail of the error.
|
|
193
197
|
*/
|
|
194
198
|
fail(code: 400 | 401 | 500, detail?: string): void;
|
|
195
199
|
}
|
|
@@ -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
|
-
* @param hub The name of the hub to listen to
|
|
232
|
-
* @param
|
|
233
|
-
* @param options Options to configure the event handler
|
|
236
|
+
* @param hub - The name of the hub to listen to
|
|
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 { }
|