fix: update authentication mode to inherit in OpenAPI to Bruno (#5300)

This commit is contained in:
sanish chirayath
2025-08-14 20:47:17 +05:30
committed by GitHub
parent c2063ce71b
commit fc53dd88e2
3 changed files with 141 additions and 3 deletions

View File

@@ -57,7 +57,7 @@ const transformOpenapiRequestItem = (request) => {
url: ensureUrl(request.global.server + path),
method: request.method.toUpperCase(),
auth: {
mode: 'none',
mode: 'inherit',
basic: null,
bearer: null,
digest: null
@@ -419,6 +419,19 @@ export const parseOpenApiCollection = (data) => {
uid: uuid(),
name: group.name,
type: 'folder',
root: {
request: {
auth: {
mode: 'inherit',
basic: null,
bearer: null,
digest: null
}
},
meta: {
name: group.name
}
},
items: group.requests.map(transformOpenapiRequestItem)
};
});

View File

@@ -233,7 +233,7 @@ const circularRefsOutput = {
"url": "{{baseUrl}}/",
"method": "POST",
"auth": {
"mode": "none",
"mode": "inherit",
},
"headers": [],
"params": [],

View File

@@ -8,6 +8,13 @@ describe('openapi-collection', () => {
expect(brunoCollection).toMatchObject(expectedOutput);
});
it('should set auth mode to inherit when no security is defined in the collection', () => {
const brunoCollection = openApiToBruno(openApiCollectionString);
// The openApiCollectionString has no security defined, so auth mode should be 'inherit'
expect(brunoCollection.items[0].items[0].request.auth.mode).toBe('inherit');
});
it('trims whitespace from info.title and uses the trimmed value as the collection name', () => {
const openApiWithTitle = `
openapi: '3.0.0'
@@ -109,6 +116,124 @@ servers:
expect(result.name).toBe('Untitled Collection');
});
describe('authentication inheritance', () => {
it('should set auth mode to inherit when no security is defined', () => {
const openApiWithoutSecurity = `
openapi: '3.0.0'
info:
version: '1.0.0'
title: 'API without security'
paths:
/test:
get:
summary: 'Test endpoint'
operationId: 'testEndpoint'
responses:
'200':
description: 'OK'
servers:
- url: 'https://example.com'
`;
const result = openApiToBruno(openApiWithoutSecurity);
expect(result.items[0].request.auth.mode).toBe('inherit');
});
it('should set auth mode to inherit when no global security schemes exist', () => {
const openApiWithEmptySecurity = `
openapi: '3.0.0'
info:
version: '1.0.0'
title: 'API with empty security'
security: []
paths:
/test:
get:
summary: 'Test endpoint'
operationId: 'testEndpoint'
responses:
'200':
description: 'OK'
servers:
- url: 'https://example.com'
`;
const result = openApiToBruno(openApiWithEmptySecurity);
expect(result.items[0].request.auth.mode).toBe('inherit');
});
it('should set auth mode to inherit when components.securitySchemes is empty', () => {
const openApiWithEmptyComponents = `
openapi: '3.0.0'
info:
version: '1.0.0'
title: 'API with empty components'
components:
securitySchemes: {}
paths:
/test:
get:
summary: 'Test endpoint'
operationId: 'testEndpoint'
responses:
'200':
description: 'OK'
servers:
- url: 'https://example.com'
`;
const result = openApiToBruno(openApiWithEmptyComponents);
expect(result.items[0].request.auth.mode).toBe('inherit');
});
it('should set auth mode to inherit when operation has empty security array', () => {
const openApiWithEmptyOperationSecurity = `
openapi: '3.0.0'
info:
version: '1.0.0'
title: 'API with empty operation security'
components:
securitySchemes:
basicAuth:
type: http
scheme: basic
paths:
/test:
get:
summary: 'Test endpoint'
operationId: 'testEndpoint'
security: []
responses:
'200':
description: 'OK'
servers:
- url: 'https://example.com'
`;
const result = openApiToBruno(openApiWithEmptyOperationSecurity);
expect(result.items[0].request.auth.mode).toBe('inherit');
});
it('should set auth mode to inherit for folder root when no security is defined', () => {
const openApiWithTags = `
openapi: '3.0.0'
info:
version: '1.0.0'
title: 'API with tags'
paths:
/test:
get:
tags:
- TestGroup
summary: 'Test endpoint'
operationId: 'testEndpoint'
responses:
'200':
description: 'OK'
servers:
- url: 'https://example.com'
`;
const result = openApiToBruno(openApiWithTags);
expect(result.items[0].type).toBe('folder');
expect(result.items[0].root.request.auth.mode).toBe('inherit');
});
});
});
const openApiCollectionString = `
@@ -174,7 +299,7 @@ const expectedOutput = {
"basic": null,
"bearer": null,
"digest": null,
"mode": "none",
"mode": "inherit",
},
"body": {
"formUrlEncoded": [],