From 7620e08f87e4a37d155ba532de7d13eb0049148d Mon Sep 17 00:00:00 2001 From: Emiliano Sanchez Date: Tue, 15 Mar 2022 16:23:08 -0300 Subject: [PATCH 1/2] in-transit encryption support added --- src/storages/inRedis/RedisAdapter.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/storages/inRedis/RedisAdapter.ts b/src/storages/inRedis/RedisAdapter.ts index 05ef94f7..c07d9bb0 100644 --- a/src/storages/inRedis/RedisAdapter.ts +++ b/src/storages/inRedis/RedisAdapter.ts @@ -164,6 +164,9 @@ export class RedisAdapter extends ioredis { } else { // If it IS the string URL, that'll be the first param for ioredis. result.unshift(options.url); } + if (options.tls) { + merge(opts, { tls: options.tls }); + } return result; } @@ -171,9 +174,9 @@ export class RedisAdapter extends ioredis { /** * Parses the options into what we care about. */ - static _defineOptions({ connectionTimeout, operationTimeout, url, host, port, db, pass }: Record) { + static _defineOptions({ connectionTimeout, operationTimeout, url, host, port, db, pass, tls }: Record) { const parsedOptions = { - connectionTimeout, operationTimeout, url, host, port, db, pass + connectionTimeout, operationTimeout, url, host, port, db, pass, tls }; return merge({}, DEFAULT_OPTIONS, parsedOptions); From 05637d0224e48d24b043b92f41bd0cf5ed2760af Mon Sep 17 00:00:00 2001 From: Emiliano Sanchez Date: Thu, 17 Mar 2022 16:45:41 -0300 Subject: [PATCH 2/2] forwarding connectionTimeout to ioredis connectTimeout --- src/storages/inRedis/RedisAdapter.ts | 3 +++ .../inRedis/__tests__/RedisAdapter.spec.ts | 17 ++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/storages/inRedis/RedisAdapter.ts b/src/storages/inRedis/RedisAdapter.ts index c07d9bb0..0c374f23 100644 --- a/src/storages/inRedis/RedisAdapter.ts +++ b/src/storages/inRedis/RedisAdapter.ts @@ -164,6 +164,9 @@ export class RedisAdapter extends ioredis { } else { // If it IS the string URL, that'll be the first param for ioredis. result.unshift(options.url); } + if (options.connectionTimeout) { + merge(opts, { connectTimeout: options.connectionTimeout }); + } if (options.tls) { merge(opts, { tls: options.tls }); } diff --git a/src/storages/inRedis/__tests__/RedisAdapter.spec.ts b/src/storages/inRedis/__tests__/RedisAdapter.spec.ts index c9e789f6..1e9fd512 100644 --- a/src/storages/inRedis/__tests__/RedisAdapter.spec.ts +++ b/src/storages/inRedis/__tests__/RedisAdapter.spec.ts @@ -93,33 +93,36 @@ describe('STORAGE Redis Adapter', () => { new RedisAdapter(loggerMock, { url: redisUrl, connectionTimeout: 123, - operationTimeout: 124 + operationTimeout: 124, + tls: { ca: 'ca' } }); // Keep in mind we're storing the arguments object, not a true array. expect(constructorParams.length).toBe(2); // In this signature, the constructor receives two params. expect(constructorParams[0]).toBe(redisUrl); // When we use the Redis URL, that should be the first parameter passed to ioredis constructor - expect(constructorParams[1]).toEqual({ enableOfflineQueue: false, connectTimeout: 10000, lazyConnect: false }); // and the second parameter would be the default settings for the lib. + expect(constructorParams[1]).toEqual({ enableOfflineQueue: false, connectTimeout: 123, lazyConnect: false, tls: { ca: 'ca' } }); // and the second parameter would be the default settings for the lib. new RedisAdapter(loggerMock, { ...redisParams, connectionTimeout: 123, - operationTimeout: 124 + operationTimeout: 124, + tls: { ca: 'ca' } }); expect(constructorParams.length).toBe(1); // In this signature, the constructor receives one param. // we keep "pass" instead of "password" on our settings API to be backwards compatible. - expect(constructorParams[0]).toEqual({ host: redisParams.host, port: redisParams.port, db: redisParams.db, password: redisParams.pass, enableOfflineQueue: false, connectTimeout: 10000, lazyConnect: false }); // If we send all the redis params separate, it will pass one object to the library containing that and the rest of the options. + expect(constructorParams[0]).toEqual({ host: redisParams.host, port: redisParams.port, db: redisParams.db, password: redisParams.pass, enableOfflineQueue: false, connectTimeout: 123, lazyConnect: false, tls: { ca: 'ca' } }); // If we send all the redis params separate, it will pass one object to the library containing that and the rest of the options. new RedisAdapter(loggerMock, { ...redisParams, url: redisUrl, - connectionTimeout: 123, - operationTimeout: 124 + // Using default connectionTimeout + operationTimeout: 124, + tls: { ca: 'ca' } }); expect(constructorParams.length).toBe(2); // In this signature, the constructor receives two params. expect(constructorParams[0]).toBe(redisUrl); // When we use the Redis URL, even if we specified all the other params one by one the URL takes precedence, so that should be the first parameter passed to ioredis constructor - expect(constructorParams[1]).toEqual({ enableOfflineQueue: false, connectTimeout: 10000, lazyConnect: false }); // and the second parameter would be the default settings for the lib. + expect(constructorParams[1]).toEqual({ enableOfflineQueue: false, connectTimeout: 10000, lazyConnect: false, tls: { ca: 'ca' } }); // and the second parameter would be the default settings for the lib. }); test('static method - _defineOptions', () => {