mirror of
https://github.com/usebruno/bruno.git
synced 2025-05-05 23:42:58 +00:00
test: add request authentication tests for basic and bearer auth handling
This commit is contained in:
parent
c7e8c07d40
commit
46dab6e474
@ -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
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user