@sockethub/server 5.0.0-alpha.3 → 5.0.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/coverage/tmp/coverage-39338-1663949520416-0.json +1 -0
  2. package/dist/bootstrap/init.js +2 -1
  3. package/dist/bootstrap/init.js.map +1 -1
  4. package/dist/config.d.ts +7 -1
  5. package/dist/config.js +6 -1
  6. package/dist/config.js.map +1 -1
  7. package/dist/index.d.ts +1 -2
  8. package/dist/index.js +7 -3
  9. package/dist/index.js.map +1 -1
  10. package/dist/janitor.d.ts +27 -12
  11. package/dist/janitor.js +97 -66
  12. package/dist/janitor.js.map +1 -1
  13. package/dist/listener.d.ts +4 -1
  14. package/dist/listener.js +8 -5
  15. package/dist/listener.js.map +1 -1
  16. package/dist/middleware/create-activity-object.d.ts +3 -1
  17. package/dist/middleware/create-activity-object.js.map +1 -1
  18. package/dist/middleware/expand-activity-stream.d.ts +2 -1
  19. package/dist/middleware/expand-activity-stream.js +4 -1
  20. package/dist/middleware/expand-activity-stream.js.map +1 -1
  21. package/dist/middleware/expand-activity-stream.test.data.js +4 -4
  22. package/dist/middleware/expand-activity-stream.test.data.js.map +1 -1
  23. package/dist/middleware/store-credentials.d.ts +3 -3
  24. package/dist/middleware/store-credentials.js +2 -12
  25. package/dist/middleware/store-credentials.js.map +1 -1
  26. package/dist/middleware/validate.d.ts +2 -2
  27. package/dist/middleware/validate.js +1 -3
  28. package/dist/middleware/validate.js.map +1 -1
  29. package/dist/middleware/validate.test.data.js +5 -5
  30. package/dist/middleware/validate.test.data.js.map +1 -1
  31. package/dist/middleware.d.ts +14 -3
  32. package/dist/middleware.js +3 -1
  33. package/dist/middleware.js.map +1 -1
  34. package/dist/platform-instance.d.ts +11 -10
  35. package/dist/platform-instance.js +77 -62
  36. package/dist/platform-instance.js.map +1 -1
  37. package/dist/platform.js +93 -104
  38. package/dist/platform.js.map +1 -1
  39. package/dist/process-manager.js +7 -3
  40. package/dist/process-manager.js.map +1 -1
  41. package/dist/routes.d.ts +1 -1
  42. package/dist/routes.js +1 -1
  43. package/dist/routes.js.map +1 -1
  44. package/dist/sockethub.d.ts +1 -22
  45. package/dist/sockethub.js +19 -26
  46. package/dist/sockethub.js.map +1 -1
  47. package/package.json +30 -36
  48. package/src/bootstrap/init.d.ts +17 -7
  49. package/src/bootstrap/init.ts +2 -1
  50. package/src/config.ts +9 -1
  51. package/src/index.ts +3 -2
  52. package/src/janitor.test.ts +189 -0
  53. package/src/janitor.ts +110 -65
  54. package/src/listener.ts +11 -7
  55. package/src/middleware/create-activity-object.ts +5 -2
  56. package/src/middleware/expand-activity-stream.test.data.ts +5 -5
  57. package/src/middleware/expand-activity-stream.test.ts +2 -2
  58. package/src/middleware/expand-activity-stream.ts +12 -7
  59. package/src/middleware/store-credentials.test.ts +4 -6
  60. package/src/middleware/store-credentials.ts +8 -14
  61. package/src/middleware/validate.test.data.ts +5 -5
  62. package/src/middleware/validate.ts +4 -6
  63. package/src/middleware.ts +28 -11
  64. package/src/platform-instance.test.ts +18 -18
  65. package/src/platform-instance.ts +98 -73
  66. package/src/platform.ts +79 -101
  67. package/src/process-manager.ts +1 -1
  68. package/src/routes.ts +3 -2
  69. package/src/sockethub.ts +29 -57
  70. package/views/examples/dummy.ejs +3 -1
  71. package/views/examples/shared.js +1 -1
  72. package/views/examples/xmpp.ejs +60 -34
  73. package/coverage/tmp/coverage-93126-1649152190997-0.json +0 -1
  74. package/dist/common.d.ts +0 -3
  75. package/dist/common.js +0 -20
  76. package/dist/common.js.map +0 -1
  77. package/dist/crypto.d.ts +0 -10
  78. package/dist/crypto.js +0 -38
  79. package/dist/crypto.js.map +0 -1
  80. package/dist/store.d.ts +0 -5
  81. package/dist/store.js +0 -17
  82. package/dist/store.js.map +0 -1
  83. package/src/common.test.ts +0 -54
  84. package/src/common.ts +0 -14
  85. package/src/config.d.ts +0 -2
  86. package/src/crypto.d.ts +0 -5
  87. package/src/crypto.test.ts +0 -41
  88. package/src/crypto.ts +0 -41
  89. package/src/janitor.d.ts +0 -8
  90. package/src/middleware/validate.d.ts +0 -1
  91. package/src/middleware.d.ts +0 -21
  92. package/src/sockethub.d.ts +0 -1
  93. package/src/store.test.ts +0 -28
  94. package/src/store.ts +0 -17
  95. package/test/queue.functional.test.js +0 -0
package/dist/common.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import { JobDataDecrypted, JobEncrypted } from "./sockethub";
2
- export declare function getPlatformId(platform: string, actor?: string): string;
3
- export declare function decryptJobData(job: JobEncrypted, secret: string): JobDataDecrypted;
package/dist/common.js DELETED
@@ -1,20 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.decryptJobData = exports.getPlatformId = void 0;
7
- const crypto_1 = __importDefault(require("./crypto"));
8
- function getPlatformId(platform, actor) {
9
- return actor ? crypto_1.default.hash(platform + actor) : crypto_1.default.hash(platform);
10
- }
11
- exports.getPlatformId = getPlatformId;
12
- function decryptJobData(job, secret) {
13
- return {
14
- title: job.data.title,
15
- msg: crypto_1.default.decrypt(job.data.msg, secret),
16
- sessionId: job.data.sessionId
17
- };
18
- }
19
- exports.decryptJobData = decryptJobData;
20
- //# sourceMappingURL=/common.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"common.js","sourceRoot":"/","sources":["common.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA8B;AAG9B,SAAgB,aAAa,CAAC,QAAgB,EAAE,KAAc;IAC5D,OAAO,KAAK,CAAC,CAAC,CAAC,gBAAM,CAAC,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,gBAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AACvE,CAAC;AAFD,sCAEC;AAED,SAAgB,cAAc,CAAC,GAAiB,EAAE,MAAc;IAC9D,OAAO;QACL,KAAK,EAAE,GAAG,CAAC,IAAI,CAAC,KAAK;QACrB,GAAG,EAAE,gBAAM,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC;QACzC,SAAS,EAAE,GAAG,CAAC,IAAI,CAAC,SAAS;KAC9B,CAAC;AACJ,CAAC;AAND,wCAMC"}
package/dist/crypto.d.ts DELETED
@@ -1,10 +0,0 @@
1
- import { IActivityStream } from "@sockethub/schemas";
2
- declare class Crypto {
3
- constructor();
4
- encrypt(json: IActivityStream, secret: string): string;
5
- decrypt(text: string, secret: string): IActivityStream;
6
- hash(text: string): string;
7
- randToken(len: number): string;
8
- }
9
- declare const crypto: Crypto;
10
- export default crypto;
package/dist/crypto.js DELETED
@@ -1,38 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const crypto_1 = require("crypto");
4
- const ALGORITHM = 'aes-256-cbc', IV_LENGTH = 16; // For AES, this is always 16
5
- class Crypto {
6
- constructor() { }
7
- encrypt(json, secret) {
8
- const iv = (0, crypto_1.randomBytes)(IV_LENGTH);
9
- const cipher = (0, crypto_1.createCipheriv)(ALGORITHM, Buffer.from(secret), iv);
10
- let encrypted = cipher.update(JSON.stringify(json));
11
- encrypted = Buffer.concat([encrypted, cipher.final()]);
12
- return iv.toString('hex') + ':' + encrypted.toString('hex');
13
- }
14
- decrypt(text, secret) {
15
- let parts = text.split(':');
16
- const iv = Buffer.from(parts.shift(), 'hex');
17
- const encryptedText = Buffer.from(parts.join(':'), 'hex');
18
- const decipher = (0, crypto_1.createDecipheriv)(ALGORITHM, Buffer.from(secret), iv);
19
- let decrypted = decipher.update(encryptedText);
20
- decrypted = Buffer.concat([decrypted, decipher.final()]);
21
- return JSON.parse(decrypted.toString());
22
- }
23
- hash(text) {
24
- const shasum = (0, crypto_1.createHash)('sha1');
25
- shasum.update(text);
26
- return shasum.digest('hex').substring(0, 7);
27
- }
28
- randToken(len) {
29
- if (len > 32) {
30
- throw new Error(`crypto.randToken supports a length param of up to 32, ${len} given`);
31
- }
32
- const buf = (0, crypto_1.randomBytes)(len);
33
- return buf.toString('hex').substring(0, len);
34
- }
35
- }
36
- const crypto = new Crypto();
37
- exports.default = crypto;
38
- //# sourceMappingURL=/crypto.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"crypto.js","sourceRoot":"/","sources":["crypto.ts"],"names":[],"mappings":";;AAAA,mCAAmF;AAGnF,MAAM,SAAS,GAAG,aAAa,EACzB,SAAS,GAAG,EAAE,CAAC,CAAC,6BAA6B;AAEnD,MAAM,MAAM;IACV,gBAAe,CAAC;IAChB,OAAO,CAAC,IAAqB,EAAE,MAAc;QAC3C,MAAM,EAAE,GAAG,IAAA,oBAAW,EAAC,SAAS,CAAC,CAAC;QAClC,MAAM,MAAM,GAAG,IAAA,uBAAc,EAAC,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC;QAClE,IAAI,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;QAEpD,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QACvD,OAAO,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,GAAG,GAAG,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC9D,CAAC;IACD,OAAO,CAAC,IAAY,EAAE,MAAc;QAClC,IAAI,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC5B,MAAM,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,EAAE,KAAK,CAAC,CAAC;QAC7C,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;QAC1D,MAAM,QAAQ,GAAG,IAAA,yBAAgB,EAAC,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC;QACtE,IAAI,SAAS,GAAG,QAAQ,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;QAC/C,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QACzD,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC1C,CAAC;IACD,IAAI,CAAC,IAAY;QACf,MAAM,MAAM,GAAG,IAAA,mBAAU,EAAC,MAAM,CAAC,CAAC;QAClC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACpB,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC9C,CAAC;IACD,SAAS,CAAC,GAAW;QACnB,IAAI,GAAG,GAAG,EAAE,EAAE;YACZ,MAAM,IAAI,KAAK,CAAC,yDAAyD,GAAG,QAAQ,CAAC,CAAC;SACvF;QACD,MAAM,GAAG,GAAG,IAAA,oBAAW,EAAC,GAAG,CAAC,CAAC;QAC7B,OAAO,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAC/C,CAAC;CACF;AAED,MAAM,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;AAC5B,kBAAe,MAAM,CAAC"}
package/dist/store.d.ts DELETED
@@ -1,5 +0,0 @@
1
- export interface ISecureStoreInstance {
2
- save(id: string, obj: any, cb: Function): any;
3
- get(id: string, cb: Function): any;
4
- }
5
- export declare function getSessionStore(parentId: string, parentSecret: string, sessionId: string, sessionSecret: string): ISecureStoreInstance;
package/dist/store.js DELETED
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getSessionStore = void 0;
7
- const secure_store_redis_1 = __importDefault(require("secure-store-redis"));
8
- const config_1 = __importDefault(require("./config"));
9
- function getSessionStore(parentId, parentSecret, sessionId, sessionSecret) {
10
- return new secure_store_redis_1.default({
11
- namespace: 'sockethub:' + parentId + ':session:' + sessionId + ':store',
12
- secret: parentSecret + sessionSecret,
13
- redis: config_1.default.get('redis')
14
- });
15
- }
16
- exports.getSessionStore = getSessionStore;
17
- //# sourceMappingURL=/store.js.map
package/dist/store.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"store.js","sourceRoot":"/","sources":["store.ts"],"names":[],"mappings":";;;;;;AAAA,4EAA6C;AAE7C,sDAA8B;AAO9B,SAAgB,eAAe,CAAC,QAAgB,EAAE,YAAoB,EACtC,SAAiB,EAAE,aAAqB;IACtE,OAAO,IAAI,4BAAW,CAAC;QACrB,SAAS,EAAE,YAAY,GAAG,QAAQ,GAAG,WAAW,GAAG,SAAS,GAAG,QAAQ;QACvE,MAAM,EAAE,YAAY,GAAG,aAAa;QACpC,KAAK,EAAE,gBAAM,CAAC,GAAG,CAAC,OAAO,CAAC;KAC3B,CAAC,CAAC;AACL,CAAC;AAPD,0CAOC"}
@@ -1,54 +0,0 @@
1
- import proxyquire from 'proxyquire';
2
- import { expect } from 'chai';
3
- import * as sinon from 'sinon';
4
-
5
- import { decryptJobData, getPlatformId } from './common';
6
- import crypto from './crypto';
7
-
8
- proxyquire.noPreserveCache();
9
- proxyquire.noCallThru();
10
-
11
- describe("getPlatformId", () => {
12
- let cryptoHashStub: any;
13
-
14
- beforeEach(() => {
15
- cryptoHashStub = sinon.stub(crypto, 'hash');
16
- cryptoHashStub.returnsArg(0);
17
- proxyquire('./common', { crypto: { hash: cryptoHashStub }});
18
- });
19
-
20
- afterEach(() => {
21
- cryptoHashStub.restore();
22
- });
23
-
24
- it('generates platform hash', () => {
25
- expect(getPlatformId('foo')).to.be.equal('foo');
26
- sinon.assert.calledOnce(cryptoHashStub);
27
- sinon.assert.calledWith(cryptoHashStub, 'foo');
28
- });
29
- it('generates platform + actor hash', () => {
30
- expect(getPlatformId('foo', 'bar')).to.be.equal('foobar');
31
- sinon.assert.calledOnce(cryptoHashStub);
32
- sinon.assert.calledWith(cryptoHashStub, 'foobar');
33
- });
34
- });
35
-
36
- describe("decryptJobData", () => {
37
- let cryptoDecryptStub: any;
38
-
39
- beforeEach(() => {
40
- cryptoDecryptStub = sinon.stub(crypto, 'decrypt');
41
- cryptoDecryptStub.returnsArg(0);
42
- proxyquire('./common', { crypto: { hash: cryptoDecryptStub }});
43
- });
44
-
45
- afterEach(() => {
46
- cryptoDecryptStub.restore();
47
- });
48
-
49
- it("decrypts and returns expected object", () => {
50
- const jobData = {data:{title:"foo", msg:'encryptedjobdata', sessionId:'foobar'}};
51
- const secret = 'secretstring';
52
- expect(decryptJobData(jobData, secret)).to.be.eql(jobData.data);
53
- });
54
- });
package/src/common.ts DELETED
@@ -1,14 +0,0 @@
1
- import crypto from "./crypto";
2
- import { JobDataDecrypted, JobEncrypted } from "./sockethub";
3
-
4
- export function getPlatformId(platform: string, actor?: string): string {
5
- return actor ? crypto.hash(platform + actor) : crypto.hash(platform);
6
- }
7
-
8
- export function decryptJobData(job: JobEncrypted, secret: string): JobDataDecrypted {
9
- return {
10
- title: job.data.title,
11
- msg: crypto.decrypt(job.data.msg, secret),
12
- sessionId: job.data.sessionId
13
- };
14
- }
package/src/config.d.ts DELETED
@@ -1,2 +0,0 @@
1
- declare let config: any;
2
- export default config;
package/src/crypto.d.ts DELETED
@@ -1,5 +0,0 @@
1
- declare const crypto: {
2
- encrypt: (json: any, secret: any) => string;
3
- decrypt: (string: any, secret: any) => any;
4
- };
5
- export default crypto;
@@ -1,41 +0,0 @@
1
- import { expect } from 'chai';
2
- import proxyquire from 'proxyquire';
3
-
4
- const crypto = proxyquire('./crypto', {
5
- 'crypto': {
6
- randomBytes: () => Buffer.alloc(16)
7
- }
8
- }).default;
9
-
10
- const secret = 'a test secret.. that is 16 x 2..';
11
- const data = {'foo': 'bar'};
12
- const encryptedData = "00000000000000000000000000000000:0543ec94d863fbf4b7a19b48e69d9317";
13
-
14
- describe('crypto', () => {
15
- it('encrypts', () => {
16
- expect(crypto.encrypt(data, secret)).to.be.equal(encryptedData);
17
- });
18
- it('decrypts', () => {
19
- expect(crypto.decrypt(encryptedData, secret)).to.eql(data);
20
- });
21
- it('hashes', () => {
22
- expect(crypto.hash('foobar')).to.be.equal('8843d7f');
23
- });
24
- it('randTokens 8', () => {
25
- const token = crypto.randToken(8);
26
- expect(token.length).to.be.equal(8);
27
- });
28
- it('randTokens 16', () => {
29
- const token = crypto.randToken(16);
30
- expect(token.length).to.be.equal(16);
31
- });
32
- it('randTokens 32', () => {
33
- const token = crypto.randToken(32);
34
- expect(token.length).to.be.equal(32);
35
- });
36
- it('randTokens 33+ will fail', () => {
37
- expect(() => {
38
- crypto.randToken(33);
39
- }).to.throw();
40
- });
41
- });
package/src/crypto.ts DELETED
@@ -1,41 +0,0 @@
1
- import { randomBytes, createCipheriv, createDecipheriv, createHash } from 'crypto';
2
- import { IActivityStream } from "@sockethub/schemas";
3
-
4
- const ALGORITHM = 'aes-256-cbc',
5
- IV_LENGTH = 16; // For AES, this is always 16
6
-
7
- class Crypto {
8
- constructor() {}
9
- encrypt(json: IActivityStream, secret: string): string {
10
- const iv = randomBytes(IV_LENGTH);
11
- const cipher = createCipheriv(ALGORITHM, Buffer.from(secret), iv);
12
- let encrypted = cipher.update(JSON.stringify(json));
13
-
14
- encrypted = Buffer.concat([encrypted, cipher.final()]);
15
- return iv.toString('hex') + ':' + encrypted.toString('hex');
16
- }
17
- decrypt(text: string, secret: string): IActivityStream {
18
- let parts = text.split(':');
19
- const iv = Buffer.from(parts.shift(), 'hex');
20
- const encryptedText = Buffer.from(parts.join(':'), 'hex');
21
- const decipher = createDecipheriv(ALGORITHM, Buffer.from(secret), iv);
22
- let decrypted = decipher.update(encryptedText);
23
- decrypted = Buffer.concat([decrypted, decipher.final()]);
24
- return JSON.parse(decrypted.toString());
25
- }
26
- hash(text: string): string {
27
- const shasum = createHash('sha1');
28
- shasum.update(text);
29
- return shasum.digest('hex').substring(0, 7);
30
- }
31
- randToken(len: number): string {
32
- if (len > 32) {
33
- throw new Error(`crypto.randToken supports a length param of up to 32, ${len} given`);
34
- }
35
- const buf = randomBytes(len);
36
- return buf.toString('hex').substring(0, len);
37
- }
38
- }
39
-
40
- const crypto = new Crypto();
41
- export default crypto;
package/src/janitor.d.ts DELETED
@@ -1,8 +0,0 @@
1
- declare function janitorCycle(): void;
2
- declare const janitor: {
3
- start: typeof janitorCycle;
4
- alreadyCalled: boolean;
5
- cycleCount: number;
6
- reportCount: number;
7
- };
8
- export default janitor;
@@ -1 +0,0 @@
1
- export default function validate(type: any): (next: any, msg: any) => void;
@@ -1,21 +0,0 @@
1
- /**
2
- * a very simple middleware handler
3
- *
4
- * When initialized, provide a function which will be called if there were any failures during
5
- * the execution of functions along the chain.
6
- *
7
- * Use middleware.chain, passing in a list of functions to call in order. It then returns
8
- * a function which accepts the message from the input. That function then will
9
- * call each of the originally passed in functions, in order, with a `next` callback as
10
- * the first parameter, and any number of originating parameters.
11
- *
12
- * As one middleware function is done, they call `next` with the first argument `true`
13
- * (succeeded, continue) any parameters to pass along.
14
- *
15
- * If any of the middleware function calls the `next` handler with `false` as the first param, the
16
- * execution of the function chain is halted, and the failure callback is called. Again, any
17
- * number of params passed after the `false` will be passed to the failure callback.
18
- *
19
- */
20
- declare function Middleware(errorHandler: any): void;
21
- export default Middleware;
@@ -1 +0,0 @@
1
- export {};
package/src/store.test.ts DELETED
@@ -1,28 +0,0 @@
1
- import proxyquire from 'proxyquire';
2
- import { expect } from 'chai';
3
- import * as sinon from 'sinon';
4
-
5
- proxyquire.noPreserveCache();
6
- proxyquire.noCallThru();
7
-
8
- const MockSecureStore = sinon.fake();
9
-
10
- const StoreMod = proxyquire('./store', {
11
- 'secure-store-redis': MockSecureStore
12
- });
13
-
14
- const getSessionStore = StoreMod.getSessionStore;
15
-
16
- describe('getSessionStore', () => {
17
- it('returns a valid Store object', () => {
18
- const store = getSessionStore('a parent id', 'a parent secret',
19
- 'a session id', 'a session secret');
20
- sinon.assert.calledOnce(MockSecureStore);
21
- sinon.assert.calledWith(MockSecureStore, {
22
- namespace: 'sockethub:a parent id:session:a session id:store',
23
- secret: 'a parent secreta session secret',
24
- redis: { host: '127.0.0.1', port: 6379 }
25
- });
26
- expect(typeof store).to.equal('object');
27
- });
28
- });
package/src/store.ts DELETED
@@ -1,17 +0,0 @@
1
- import SecureStore from 'secure-store-redis';
2
-
3
- import config from "./config";
4
-
5
- export interface ISecureStoreInstance {
6
- save(id: string, obj: any, cb: Function);
7
- get(id: string, cb: Function);
8
- }
9
-
10
- export function getSessionStore(parentId: string, parentSecret: string,
11
- sessionId: string, sessionSecret: string): ISecureStoreInstance {
12
- return new SecureStore({
13
- namespace: 'sockethub:' + parentId + ':session:' + sessionId + ':store',
14
- secret: parentSecret + sessionSecret,
15
- redis: config.get('redis')
16
- });
17
- }
File without changes