UNPKG

cqr-env

Version:

Have multiple env files that can be encrypted and included in version control

64 lines (48 loc) 2.34 kB
const test = require('ava') const { spawnSync } = require('child_process') const fs = require('fs') function clearFiles () { try { fs.unlinkSync('tests/F/password.env.js.exposed') } catch (e) {} try { fs.unlinkSync('tests/F/password.env.js.encrypted') } catch (e) {} } test.before(function (t) { // set key in environment variable process.env.cqr_key = '1234' }) test.beforeEach(t => clearFiles()) test.serial.skip('invalid parameters', function (t) { t.timeout(3000000, 'writing files can take long') let file = 'tests/F/password.env.js.exposed' fs.writeFileSync(file, 'a=b') t.throws(() => spawnSync('node', ['./cli.js'])) t.throws(() => spawnSync('node', ['./cli.js', '-e'])) t.throws(() => spawnSync('node', ['./cli.js', '-e', file])) t.throws(() => spawnSync('node', ['./cli.js', '-e', file, 'unexisting_env_var'])) t.throws(() => spawnSync('node', ['./cli.js', 'e', file, 'cqr_key'])) t.throws(() => spawnSync('node', ['./cli.js', 'this is not right'])) t.notThrows(() => spawnSync('node', ['./cli.js', '-e', file, 'cqr_key'])) file = 'tests/F/password.env.js.encrypted' t.throws(() => spawnSync('node', ['./cli.js'])) t.throws(() => spawnSync('node', ['./cli.js', '-d'])) t.throws(() => spawnSync('node', ['./cli.js', '-d', file])) t.throws(() => spawnSync('node', ['./cli.js', '-d', file, 'unexisting_env_var'])) t.throws(() => spawnSync('node', ['./cli.js', 'd', file, 'cqr_key'])) t.throws(() => spawnSync('node', ['./cli.js', '-d=this is not right'])) fs.unlinkSync(file) }) test.serial('glob sanitization', function (t) { const file = 'tests/G/password.env.js.exposed' fs.writeFileSync(file, 'a=b') t.notThrows(() => spawnSync('node', ['./cli.js', '-e', 'tests/G/password.env.js.exposed', '-v', 'cqr_key'])) fs.unlinkSync(file.replace('.exposed', '.encrypted')) fs.writeFileSync(file, 'a=b') t.notThrows(() => spawnSync('node', ['./cli.js', '-e', 'tests\\G\\password.env.js.exposed', '-v', 'cqr_key'])) fs.unlinkSync(file.replace('.exposed', '.encrypted')) fs.writeFileSync(file, 'a=b') t.notThrows(() => spawnSync('node', ['./cli.js', '-e', 'tests\\G/password.env.js.exposed', '-v', 'cqr_key'])) fs.unlinkSync(file.replace('.exposed', '.encrypted')) }) test.skip('multiple envvars', function (t) { t.pass() }) test.afterEach(t => clearFiles())