fix authorization headers generation

add unit tests
This commit is contained in:
2026-06-30 12:24:10 +02:00
parent f531310718
commit b00dee4f10
2 changed files with 100 additions and 35 deletions
+34
View File
@@ -0,0 +1,34 @@
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' });
});