From d49f50db88fa04c3d1f025b3fd0b42aa7bad8e4d Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Wed, 24 Apr 2024 16:45:39 -0700 Subject: [PATCH] Release v1.2.2 (#73) - fix default path - fix getDir result --- CHANGELOG.md | 10 +++------- CONTRIBUTORS.md | 2 +- lib/reader.js | 17 +++++++++-------- package.json | 2 +- test/config.js | 10 +++++----- test/{configfile.js => reader.js} | 13 +++++++++---- 6 files changed, 28 insertions(+), 26 deletions(-) rename test/{configfile.js => reader.js} (96%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 500da4a..301f1ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,11 +4,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/). ### Unreleased -### [1.2.1] - 2024-04-24 - -- config: guard against prototype pollution - -### [1.2.0] - 2024-04-14 +### [1.2.2] - 2024-04-24 - feat: getDir can parse different types of files in a dir - feat: all file readers now have load and loadPromise, so that @@ -29,6 +25,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/). - lint: remove duplicate / stale rules from .eslintrc - package.json: populate [files] - deps: version bumps +- config: guard against prototype pollution ### [1.1.0] - 2022-05-27 @@ -128,5 +125,4 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/). - reduce node required 4.3 -> 0.10.43 [1.1.0]: https://github.com/haraka/haraka-config/releases/tag/1.1.0 -[1.2.0]: https://github.com/haraka/haraka-config/releases/tag/v1.2.0 -[1.2.1]: https://github.com/haraka/haraka-config/releases/tag/v1.2.1 +[1.2.2]: https://github.com/haraka/haraka-config/releases/tag/v1.2.2 diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 1f02864..06267fd 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -2,7 +2,7 @@ This handcrafted artisinal software is brought to you by: -|
msimerson (53) |
PSSGCSim (7) |
baudehlo (1) |
Wesitos (1) |
oreoluwa (1) | +|
msimerson (54) |
PSSGCSim (7) |
baudehlo (1) |
Wesitos (1) |
oreoluwa (1) | | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | this file is maintained by [.release](https://github.com/msimerson/.release) diff --git a/lib/reader.js b/lib/reader.js index e729024..2d7f70b 100644 --- a/lib/reader.js +++ b/lib/reader.js @@ -34,11 +34,11 @@ class Reader { return } - // these work when this is loaded with require('haraka-config') - if (/node_modules[\\/]haraka-config$/.test(__dirname)) { + // when loaded with require('haraka-config') + if (/node_modules\/haraka-config\/lib$/.test(__dirname)) { config_dir_candidates = [ - path.join(__dirname, '..', '..', 'config'), // haraka/Haraka/* - path.join(__dirname, '..', '..'), // npm packaged modules + path.join(__dirname, '..', '..', '..', 'config'), // haraka/Haraka/* + path.join(__dirname, '..', '..', '..'), // npm packaged modules ] } @@ -50,7 +50,7 @@ class Reader { return } } catch (ignore) { - console.error(ignore.message) + // console.error(ignore.message) } } } @@ -146,9 +146,10 @@ class Reader { const contents = [] for (const file of fileList) { const type = opts.type ?? this.getType(file) - contents.push( - this.load_config(path.resolve(name, file), type, opts), - ) + contents.push({ + path: file, + data: this.load_config(path.resolve(name, file), type, opts), + }) } return contents }) diff --git a/package.json b/package.json index 24e64f8..c2f05c4 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "name": "haraka-config", "license": "MIT", "description": "Haraka's config file loader", - "version": "1.2.1", + "version": "1.2.2", "homepage": "http://haraka.github.io", "repository": { "type": "git", diff --git a/test/config.js b/test/config.js index 41083cf..e54d71d 100644 --- a/test/config.js +++ b/test/config.js @@ -474,8 +474,8 @@ describe('getDir', function () { assert.ifError(err) assert.equal(err, null) assert.equal(files.length, 3) - assert.equal(files[0], `contents1${os.EOL}`) - assert.equal(files[2], `contents3${os.EOL}`) + assert.equal(files[0].data, `contents1${os.EOL}`) + assert.equal(files[2].data, `contents3${os.EOL}`) done() }) }) @@ -508,15 +508,15 @@ describe('getDir', function () { // console.log(files); assert.equal(err, null) assert.equal(files.length, 3) - assert.equal(files[0], `contents1${os.EOL}`) - assert.equal(files[2], `contents3${os.EOL}`) + assert.equal(files[0].data, `contents1${os.EOL}`) + assert.equal(files[2].data, `contents3${os.EOL}`) fs.writeFile(tmpFile, 'contents4\n', (err2) => { assert.equal(err2, null) // console.log('file touched, waiting for callback'); }) } if (callCount === 2) { - assert.equal(files[3], 'contents4\n') + assert.equal(files[3].data, 'contents4\n') fs.unlink(tmpFile, () => {}) done() } diff --git a/test/configfile.js b/test/reader.js similarity index 96% rename from test/configfile.js rename to test/reader.js index fd7e4dd..6e92233 100644 --- a/test/configfile.js +++ b/test/reader.js @@ -169,19 +169,23 @@ describe('reader', function () { }) describe('read_dir', function () { - it.skip('returns dir contents', async function () { + it('returns dir contents', async function () { // may have race collission with config.getDir test const result = await this.cfreader.read_dir( path.resolve('test/config/dir'), ) - assert.deepEqual(result, ['contents1', 'contents2', 'contents3']) + assert.deepEqual(result, [ + {data: 'contents1', path: '1.ext' }, + {data: 'contents2', path: '2.ext' }, + {data: 'contents3', path: '3.ext' } + ]) }) it('returns dir with mixed types', async function () { const result = await this.cfreader.read_dir('test/config/mixed') assert.deepEqual(result, [ - { main: {}, sect: { one: 'true' } }, - { main: { two: false } }, + { data: { main: {}, sect: { one: 'true' } }, path: '1.ini' }, + { data: { main: { two: false } }, path: '2.yml' }, ]) }) }) @@ -340,6 +344,7 @@ describe('reader', function () { }) it('NODE_ENV=test', function () { + delete process.env.HARAKA process.env.NODE_ENV = 'test' this.cfreader.get_path_to_config_dir() assert.ok(