Skip to content

Commit 90496c8

Browse files
committed
fixup! feat(ncu-config): add support for partially encrypted config files
1 parent 41c1ef5 commit 90496c8

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

lib/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function setOwnProperty(target, key, value) {
5151
});
5252
}
5353
function addEncryptedPropertyGetter(target, key, input) {
54-
if (input.startsWith?.('-----BEGIN PGP MESSAGE-----\n')) {
54+
if (input?.startsWith?.('-----BEGIN PGP MESSAGE-----\n')) {
5555
return Object.defineProperty(target, key, {
5656
__proto__: null,
5757
configurable: true,

test/unit/auth.test.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@ describe('auth', async function() {
2121
it('asks for auth data if no ncurc is found', async function() {
2222
await runAuthScript(
2323
undefined,
24-
[FIRST_TIME_MSG, MOCKED_TOKEN]
24+
[FIRST_TIME_MSG, MOCKED_TOKEN],
25+
/^Spawning gpg to encrypt the config value\r?\nError: spawn do-not-exist ENOENT(?:.*\n)+Failed encrypt token, storing unencrypted instead\r?\n$/,
2526
);
2627
});
2728

2829
it('asks for auth data if ncurc is invalid json', async function() {
2930
await runAuthScript(
3031
{ HOME: 'this is not json' },
31-
[FIRST_TIME_MSG, MOCKED_TOKEN]
32+
[FIRST_TIME_MSG, MOCKED_TOKEN],
33+
/^Spawning gpg to encrypt the config value\r?\nError: spawn do-not-exist ENOENT(?:.*\n)+Failed encrypt token, storing unencrypted instead\r?\n$/,
3234
);
3335
});
3436

@@ -117,7 +119,7 @@ describe('auth', async function() {
117119
function runAuthScript(
118120
ncurc = {}, expect = [], error = '', fixture = 'run-auth-github') {
119121
return new Promise((resolve, reject) => {
120-
const newEnv = { HOME: undefined, XDG_CONFIG_HOME: undefined };
122+
const newEnv = { HOME: undefined, XDG_CONFIG_HOME: undefined, GPG_BIN: 'do-not-exist' };
121123
if (ncurc.HOME === undefined) ncurc.HOME = ''; // HOME must always be set.
122124
for (const envVar in ncurc) {
123125
if (ncurc[envVar] === undefined) continue;
@@ -154,8 +156,9 @@ function runAuthScript(
154156
});
155157
proc.on('close', () => {
156158
try {
157-
assert.strictEqual(stderr, error);
158-
assert.strictEqual(expect.length, 0);
159+
if (typeof error === 'string') assert.strictEqual(stderr, error);
160+
else assert.match(stderr, error);
161+
assert.deepStrictEqual(expect, []);
159162
if (newEnv.HOME) {
160163
fs.rmSync(newEnv.HOME, { recursive: true, force: true });
161164
}

0 commit comments

Comments
 (0)