35 lines
1.5 KiB
JavaScript
35 lines
1.5 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import fs from 'node:fs';
|
|
import os from 'node:os';
|
|
import path from 'node:path';
|
|
import { getRequestConfigForFile, mergeRequestConfig } from './generate-http-docs.js';
|
|
|
|
test('does not inherit parent auth when a child config has no auth override', () => {
|
|
const parentAuth = { type: 'bearer', token: 'parent-token' };
|
|
const merged = mergeRequestConfig({ auth: parentAuth }, {});
|
|
|
|
assert.equal(merged.auth, undefined);
|
|
});
|
|
|
|
test('uses an explicit child auth object instead of inheriting the parent auth', () => {
|
|
const parentAuth = { type: 'bearer', token: 'parent-token' };
|
|
const childAuth = { type: 'basic', username: 'user', password: 'pass' };
|
|
const merged = mergeRequestConfig({ auth: parentAuth }, { auth: childAuth });
|
|
|
|
assert.deepEqual(merged.auth, childAuth);
|
|
});
|
|
|
|
test('reads auth inherit from a Bruno-style http block', () => {
|
|
const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'bruno-auth-'));
|
|
const childDir = path.join(tempRoot, 'nested');
|
|
fs.mkdirSync(childDir, { recursive: true });
|
|
fs.writeFileSync(path.join(tempRoot, 'opencollection.yml'), `request:\n auth:\n type: bearer\n token: "parent-token"\n`);
|
|
fs.writeFileSync(path.join(tempRoot, 'folder.yml'), 'auth: inherit\n');
|
|
fs.writeFileSync(path.join(childDir, 'request.yml'), 'http:\n auth: inherit\n');
|
|
|
|
const config = getRequestConfigForFile(path.join(childDir, 'request.yml'), tempRoot);
|
|
|
|
assert.deepEqual(config.auth, { type: 'bearer', token: 'parent-token' });
|
|
});
|