From 46dab6e4746c1131ada545ed07f50768271e89e6 Mon Sep 17 00:00:00 2001 From: Pragadesh-45 Date: Tue, 22 Apr 2025 20:25:27 +0545 Subject: [PATCH] test: add request authentication tests for basic and bearer auth handling --- .../postman-to-bruno/request-auth.spec.js | 134 ++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 packages/bruno-converters/tests/postman/postman-to-bruno/request-auth.spec.js diff --git a/packages/bruno-converters/tests/postman/postman-to-bruno/request-auth.spec.js b/packages/bruno-converters/tests/postman/postman-to-bruno/request-auth.spec.js new file mode 100644 index 000000000..a542a6b61 --- /dev/null +++ b/packages/bruno-converters/tests/postman/postman-to-bruno/request-auth.spec.js @@ -0,0 +1,134 @@ +import { describe, it, expect } from '@jest/globals'; +import postmanToBruno from '../../../src/postman/postman-to-bruno'; + +describe('Request Authentication', () => { + it('should handle basic auth at request level', () => { + const postmanCollection = { + info: { + name: 'Request Auth Collection', + schema: 'https://schema.getpostman.com/json/collection/v2.1.0/collection.json' + }, + item: [ + { + name: 'Basic Auth Request', + request: { + method: 'GET', + url: 'https://api.example.com/test', + auth: { + type: 'basic', + basic: [ + { key: 'username', value: 'requestuser' }, + { key: 'password', value: 'requestpass' } + ] + } + } + } + ] + }; + + const result = postmanToBruno(postmanCollection); + + expect(result.items[0].request.auth).toEqual({ + mode: 'basic', + basic: { + username: 'requestuser', + password: 'requestpass' + }, + bearer: null, + awsv4: null, + apikey: null, + oauth2: null, + digest: null + }); + }); + + it('should inherit folder auth when request has no auth', () => { + const postmanCollection = { + info: { + name: 'Inherit Request Auth Collection', + schema: 'https://schema.getpostman.com/json/collection/v2.1.0/collection.json' + }, + item: [ + { + name: 'Auth Folder', + auth: { + type: 'bearer', + bearer: [{ key: 'token', value: 'foldertoken' }] + }, + item: [ + { + name: 'No Auth Request', + request: { + method: 'GET', + url: 'https://api.example.com/test' + } + } + ] + } + ] + }; + + const result = postmanToBruno(postmanCollection); + + expect(result.items[0].items[0].request.auth).toEqual({ + mode: 'bearer', + basic: null, + bearer: { + token: 'foldertoken' + }, + awsv4: null, + apikey: null, + oauth2: null, + digest: null + }); + }); + + it('should override folder auth with request auth', () => { + const postmanCollection = { + info: { + name: 'Override Request Auth Collection', + schema: 'https://schema.getpostman.com/json/collection/v2.1.0/collection.json' + }, + item: [ + { + name: 'Auth Folder', + auth: { + type: 'basic', + basic: [ + { key: 'username', value: 'folderuser' }, + { key: 'password', value: 'folderpass' } + ] + }, + item: [ + { + name: 'Override Auth Request', + request: { + method: 'GET', + url: 'https://api.example.com/test', + auth: { + type: 'bearer', + bearer: [{ key: 'token', value: 'requesttoken' }] + } + } + } + ] + } + ] + }; + + const result = postmanToBruno(postmanCollection); + + expect(result.items[0].items[0].request.auth).toEqual({ + mode: 'bearer', + basic: null, + bearer: { + token: 'requesttoken' + }, + awsv4: null, + apikey: null, + oauth2: null, + digest: null + }); + }); + +});