Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions test/fixtures/rc/non-readable/node.config.json

This file was deleted.

25 changes: 17 additions & 8 deletions test/parallel/test-config-file.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
'use strict';

const { spawnPromisified, skipIfSQLiteMissing } = require('../common');
const {
isWindows,
spawnPromisified,
skipIfSQLiteMissing,
} = require('../common');
skipIfSQLiteMissing();
const fixtures = require('../common/fixtures');
const tmpdir = require('../common/tmpdir');
const { match, strictEqual, deepStrictEqual } = require('node:assert');
const { test, it, describe } = require('node:test');
const { chmodSync, constants } = require('node:fs');
const common = require('../common');
const { chmodSync, writeFileSync, constants } = require('node:fs');
const { join } = require('node:path');

test('should handle non existing json', async () => {
const result = await spawnPromisified(process.execPath, [
Expand Down Expand Up @@ -239,6 +244,7 @@ test('--inspect=true should be parsed correctly', { skip: !process.features.insp
'--no-warnings',
'--experimental-config-file',
fixtures.path('rc/inspect-true.json'),
'--inspect-port', '0',
'-p', 'require("node:inspector").url()',
]);
match(result.stderr, /^Debugger listening on (ws:\/\/[^\s]+)/);
Expand Down Expand Up @@ -363,21 +369,24 @@ test('should override node.config.json when specificied', async () => {
// Skip on windows because it doesn't support chmod changing read permissions
// Also skip if user is root because it would have read permissions anyway
test('should throw an error when the file is non readable', {
skip: common.isWindows || process.getuid() === 0,
skip: isWindows || process.getuid() === 0,
}, async () => {
chmodSync(fixtures.path('rc/non-readable/node.config.json'), constants.O_RDONLY);
tmpdir.refresh();
const dest = join(tmpdir.path, 'node.config.json');
writeFileSync(dest, JSON.stringify({
nodeOptions: { 'max-http-header-size': 10 }
}));
chmodSync(dest, constants.O_RDONLY);
const result = await spawnPromisified(process.execPath, [
'--no-warnings',
'--experimental-default-config-file',
'-p', 'http.maxHeaderSize',
], {
cwd: fixtures.path('rc/non-readable'),
cwd: tmpdir.path,
});
match(result.stderr, /Cannot read configuration from node\.config\.json: permission denied/);
strictEqual(result.stdout, '');
strictEqual(result.code, 9);
chmodSync(fixtures.path('rc/non-readable/node.config.json'),
constants.S_IRWXU | constants.S_IRWXG | constants.S_IRWXO);
});

describe('namespace-scoped options', () => {
Expand Down
Loading