diff --git a/lib/Config.js b/lib/Config.js index 9faea9e96a..bf7732b2bc 100644 --- a/lib/Config.js +++ b/lib/Config.js @@ -834,11 +834,12 @@ class Config extends EventEmitter { if (Array.isArray(config.kmip.transport)) { this.kmip.transport = config.kmip.transport.map(t => this._parseKmipTransport(t)); - if (config.kmip.retries) { - assert(typeof config.kmip.retries === 'number', - 'bad config: KMIP Cluster retries must be a number'); + if (config.kmip.retries !== undefined) { + assert(Number.isInteger(config.kmip.retries) && config.kmip.retries >= 0, + 'bad config: KMIP Cluster retries must be a non-negative integer'); assert(config.kmip.retries <= this.kmip.transport.length - 1, 'bad config: KMIP Cluster retries must be lower or equal to the number of hosts - 1'); + this.kmip.retries = config.kmip.retries; } else { this.kmip.retries = this.kmip.transport.length - 1; } diff --git a/package.json b/package.json index 8402da7932..599c6d613c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@zenko/cloudserver", - "version": "9.2.43", + "version": "9.2.44", "description": "Zenko CloudServer, an open-source Node.js implementation of a server handling the Amazon S3 protocol", "main": "index.js", "engines": { diff --git a/tests/unit/testConfigs/parseKmsKmip.js b/tests/unit/testConfigs/parseKmsKmip.js new file mode 100644 index 0000000000..eea2359c77 --- /dev/null +++ b/tests/unit/testConfigs/parseKmsKmip.js @@ -0,0 +1,41 @@ +const assert = require('assert'); + +const { ConfigObject: Config } = require('../../../lib/Config'); + +function kmipCluster(retries) { + return { + providerName: 'thales', + transport: [{ tls: { host: 'kmip1' } }, { tls: { host: 'kmip2' } }, { tls: { host: 'kmip3' } }], + retries, + }; +} + +describe('parseKmsKmip Function', () => { + let configInstance; + + beforeEach(() => { + configInstance = new Config(); + }); + + it('should default cluster retries to the number of hosts - 1', () => { + configInstance._parseKmsKmip({ kmip: kmipCluster(undefined) }); + assert.strictEqual(configInstance.kmip.retries, 2); + }); + + it('should use the configured cluster retries', () => { + configInstance._parseKmsKmip({ kmip: kmipCluster(1) }); + assert.strictEqual(configInstance.kmip.retries, 1); + }); + + it('should use cluster retries configured to 0', () => { + configInstance._parseKmsKmip({ kmip: kmipCluster(0) }); + assert.strictEqual(configInstance.kmip.retries, 0); + }); + + it('should reject cluster retries above the number of hosts - 1', () => { + assert.throws( + () => configInstance._parseKmsKmip({ kmip: kmipCluster(3) }), + /KMIP Cluster retries must be lower or equal to the number of hosts - 1/, + ); + }); +});