diff --git a/packages/bruno-cli/src/runner/run-single-request.js b/packages/bruno-cli/src/runner/run-single-request.js index 0fdda11ec90..4b85f1047cd 100644 --- a/packages/bruno-cli/src/runner/run-single-request.js +++ b/packages/bruno-cli/src/runner/run-single-request.js @@ -604,9 +604,6 @@ const runSingleRequest = async function ( } request.oauth2CredentialVariables = getFormattedOauth2Credentials(); - - // Remove oauth2 config from request to prevent it from being sent - delete request.oauth2; } let response, responseTime; @@ -631,7 +628,6 @@ const runSingleRequest = async function ( if (request.ntlmConfig) { axiosInstance = NtlmClient(request.ntlmConfig, axiosInstance.defaults); - delete request.ntlmConfig; } if (request.oauth1config) { @@ -657,12 +653,10 @@ const runSingleRequest = async function ( request.awsv4config = await resolveAwsV4Credentials(request); addAwsV4Interceptor(axiosInstance, request); - delete request.awsv4config; } if (request.digestConfig) { addDigestInterceptor(axiosInstance, request); - delete request.digestConfig; } /** @type {import('axios').AxiosResponse} */ diff --git a/packages/bruno-cli/src/utils/axios-instance.js b/packages/bruno-cli/src/utils/axios-instance.js index cf94f8536a1..7670f22d879 100644 --- a/packages/bruno-cli/src/utils/axios-instance.js +++ b/packages/bruno-cli/src/utils/axios-instance.js @@ -66,6 +66,17 @@ const createRedirectConfig = (error, redirectUrl) => { return requestConfig; }; +const deleteAuthConfig = (config) => { + // Keep auth configs on the runtime request for scripts, but don't pass them to transport. + delete config.ntlmConfig; + delete config.awsv4config; + delete config.digestConfig; + delete config.oauth1config; + delete config.oauth2; + delete config.apiKeyHeaderName; + delete config.apiKeyAuthValueForQueryParams; +}; + /** * Function that configures axios with timing interceptors * Important to note here that the timings are not completely accurate. @@ -98,6 +109,8 @@ function makeAxiosInstance({ }; instance.interceptors.request.use((config) => { + deleteAuthConfig(config); + config.headers['request-start-time'] = Date.now(); /** diff --git a/packages/bruno-cli/tests/utils/axios-instance.spec.js b/packages/bruno-cli/tests/utils/axios-instance.spec.js new file mode 100644 index 00000000000..9d43555a6ef --- /dev/null +++ b/packages/bruno-cli/tests/utils/axios-instance.spec.js @@ -0,0 +1,66 @@ +jest.mock('../../src/constants', () => ({ + CLI_VERSION: '1.0.0' +})); + +jest.mock('../../src/utils/cookies', () => ({ + addCookieToJar: jest.fn(), + getCookieStringForUrl: jest.fn() +})); + +jest.mock('../../src/utils/form-data', () => ({ + createFormData: jest.fn() +})); + +jest.mock('../../src/utils/proxy-util', () => ({ + setupProxyAgents: jest.fn() +})); + +const { makeAxiosInstance } = require('../../src/utils/axios-instance'); + +function createStubAdapter() { + let capturedConfig = null; + + const adapter = (config) => { + capturedConfig = config; + return Promise.resolve({ + data: {}, + status: 200, + statusText: 'OK', + headers: {}, + config + }); + }; + + adapter.getConfig = () => capturedConfig; + + return adapter; +} + +describe('axios-instance: auth config cleanup', () => { + test('should remove auth config before request reaches the axios adapter', async () => { + const axiosInstance = makeAxiosInstance(); + const stubAdapter = createStubAdapter(); + + await axiosInstance({ + url: 'https://api.example.com/test', + method: 'get', + adapter: stubAdapter, + ntlmConfig: { username: 'user', password: 'pass' }, + awsv4config: { accessKeyId: 'access-key', secretAccessKey: 'secret-key' }, + digestConfig: { username: 'digest-user', password: 'digest-pass' }, + oauth1config: { consumerSecret: 'consumer-secret' }, + oauth2: { clientSecret: 'client-secret' }, + apiKeyHeaderName: 'x-api-key', + apiKeyAuthValueForQueryParams: 'api-key-value' + }); + + const config = stubAdapter.getConfig(); + expect(config.ntlmConfig).toBeUndefined(); + expect(config.awsv4config).toBeUndefined(); + expect(config.digestConfig).toBeUndefined(); + expect(config.oauth1config).toBeUndefined(); + expect(config.oauth2).toBeUndefined(); + expect(config.apiKeyHeaderName).toBeUndefined(); + expect(config.apiKeyAuthValueForQueryParams).toBeUndefined(); + }); +}); diff --git a/packages/bruno-electron/src/ipc/network/axios-instance.js b/packages/bruno-electron/src/ipc/network/axios-instance.js index a22475bc804..47c90875802 100644 --- a/packages/bruno-electron/src/ipc/network/axios-instance.js +++ b/packages/bruno-electron/src/ipc/network/axios-instance.js @@ -65,6 +65,17 @@ const checkConnection = (host, port) => } }); +const deleteAuthConfig = (config) => { + // Keep auth configs on the runtime request for scripts, but don't pass them to transport. + delete config.ntlmConfig; + delete config.awsv4config; + delete config.digestConfig; + delete config.oauth1config; + delete config.oauth2; + delete config.apiKeyHeaderName; + delete config.apiKeyAuthValueForQueryParams; +}; + /** * Function that configures axios with timing interceptors * Important to note here that the timings are not completely accurate. @@ -105,6 +116,8 @@ function makeAxiosInstance({ }; instance.interceptors.request.use(async (config) => { + deleteAuthConfig(config); + const url = URL.parse(config.url); config.metadata = config.metadata || {}; config.metadata.startTime = new Date().getTime(); diff --git a/packages/bruno-electron/src/ipc/network/index.js b/packages/bruno-electron/src/ipc/network/index.js index 1445a097921..11258661cfd 100644 --- a/packages/bruno-electron/src/ipc/network/index.js +++ b/packages/bruno-electron/src/ipc/network/index.js @@ -157,7 +157,6 @@ const configureRequest = async ( if (request.ntlmConfig) { axiosInstance = NtlmClient(request.ntlmConfig, axiosInstance.defaults); - delete request.ntlmConfig; } if (request.oauth1config) { @@ -301,7 +300,6 @@ const configureRequest = async ( if (request.awsv4config) { request.awsv4config = await resolveAwsV4Credentials(request); addAwsV4Interceptor(axiosInstance, request); - delete request.awsv4config; } if (request.digestConfig) { diff --git a/packages/bruno-electron/tests/network/axios-instance.spec.js b/packages/bruno-electron/tests/network/axios-instance.spec.js index 7ace03d66d2..0c657f5ac3b 100644 --- a/packages/bruno-electron/tests/network/axios-instance.spec.js +++ b/packages/bruno-electron/tests/network/axios-instance.spec.js @@ -185,3 +185,32 @@ describe('axios-instance: DNS lookup behavior (GitHub #7343)', () => { expect(config.lookup).not.toBe(inheritedLookup); }); }); + +describe('axios-instance: auth config cleanup', () => { + test('should remove auth config before request reaches the axios adapter', async () => { + const axiosInstance = makeAxiosInstance(); + const stubAdapter = createStubAdapter(); + + await axiosInstance({ + url: 'https://api.example.com/test', + method: 'get', + adapter: stubAdapter, + ntlmConfig: { username: 'user', password: 'pass' }, + awsv4config: { accessKeyId: 'access-key', secretAccessKey: 'secret-key' }, + digestConfig: { username: 'digest-user', password: 'digest-pass' }, + oauth1config: { consumerSecret: 'consumer-secret' }, + oauth2: { clientSecret: 'client-secret' }, + apiKeyHeaderName: 'x-api-key', + apiKeyAuthValueForQueryParams: 'api-key-value' + }); + + const config = stubAdapter.getConfig(); + expect(config.ntlmConfig).toBeUndefined(); + expect(config.awsv4config).toBeUndefined(); + expect(config.digestConfig).toBeUndefined(); + expect(config.oauth1config).toBeUndefined(); + expect(config.oauth2).toBeUndefined(); + expect(config.apiKeyHeaderName).toBeUndefined(); + expect(config.apiKeyAuthValueForQueryParams).toBeUndefined(); + }); +}); diff --git a/packages/bruno-js/src/bruno-request.js b/packages/bruno-js/src/bruno-request.js index ddf0a22e5dc..aab1b95fdde 100644 --- a/packages/bruno-js/src/bruno-request.js +++ b/packages/bruno-js/src/bruno-request.js @@ -100,16 +100,18 @@ class BrunoRequest { return 'oauth1'; } else if (this.headers?.['Authorization']?.startsWith('Bearer')) { return 'bearer'; - } else if (this.headers?.['Authorization']?.startsWith('Basic') || this.req?.auth?.username) { + } else if (this.headers?.['Authorization']?.startsWith('Basic') || this.req?.basicAuth) { return 'basic'; } else if (this.req?.apiKeyAuthValueForQueryParams) { return 'apikey'; } else if (this.req?.apiKeyHeaderName && this.headers?.[this.req.apiKeyHeaderName] !== undefined) { return 'apikey'; - } else if (this.req?.awsv4) { + } else if (this.req?.awsv4config) { return 'awsv4'; } else if (this.req?.digestConfig) { return 'digest'; + } else if (this.req?.ntlmConfig) { + return 'ntlm'; } else if (this.headers?.['X-WSSE'] || this.req?.auth?.username) { return 'wsse'; } else { diff --git a/packages/bruno-js/tests/bruno-request-auth-mode.spec.js b/packages/bruno-js/tests/bruno-request-auth-mode.spec.js index bd3e815fa4e..5928882ff86 100644 --- a/packages/bruno-js/tests/bruno-request-auth-mode.spec.js +++ b/packages/bruno-js/tests/bruno-request-auth-mode.spec.js @@ -13,6 +13,43 @@ const makeReq = (overrides = {}) => ({ }); describe('BrunoRequest - getAuthMode()', () => { + it('returns oauth2 when OAuth2 config is present', () => { + const req = new BrunoRequest( + makeReq({ + oauth2: { + access_token: 'access-token' + } + }) + ); + + expect(req.getAuthMode()).toBe('oauth2'); + }); + + it('returns oauth1 when OAuth1 config is present', () => { + const req = new BrunoRequest( + makeReq({ + oauth1config: { + consumerKey: 'consumer-key', + consumerSecret: 'consumer-secret' + } + }) + ); + + expect(req.getAuthMode()).toBe('oauth1'); + }); + + it('returns bearer when bearer authorization header is present', () => { + const req = new BrunoRequest( + makeReq({ + headers: { + Authorization: 'Bearer token' + } + }) + ); + + expect(req.getAuthMode()).toBe('bearer'); + }); + it('returns apikey for header placement when the api key header is present', () => { const req = new BrunoRequest( makeReq({ @@ -50,4 +87,77 @@ describe('BrunoRequest - getAuthMode()', () => { expect(req.getAuthMode()).toBe('apikey'); }); + + it('returns awsv4 when AWS SigV4 config is present', () => { + const req = new BrunoRequest( + makeReq({ + awsv4config: { + accessKeyId: 'access-key', + secretAccessKey: 'secret-key', + service: 'execute-api', + region: 'us-east-1' + } + }) + ); + + expect(req.getAuthMode()).toBe('awsv4'); + }); + + it('returns digest when Digest config is present', () => { + const req = new BrunoRequest( + makeReq({ + digestConfig: { + username: 'user', + password: 'password' + } + }) + ); + + expect(req.getAuthMode()).toBe('digest'); + }); + + it('returns basic when basic auth config is present before interpolation', () => { + const req = new BrunoRequest( + makeReq({ + basicAuth: { + username: 'user', + password: 'password' + } + }) + ); + + expect(req.getAuthMode()).toBe('basic'); + }); + + it('returns ntlm when NTLM config is present', () => { + const req = new BrunoRequest( + makeReq({ + ntlmConfig: { + username: 'user', + password: 'password', + domain: 'domain' + } + }) + ); + + expect(req.getAuthMode()).toBe('ntlm'); + }); + + it('returns wsse when WSSE auth header is present', () => { + const req = new BrunoRequest( + makeReq({ + headers: { + 'X-WSSE': 'UsernameToken Username="user"' + } + }) + ); + + expect(req.getAuthMode()).toBe('wsse'); + }); + + it('returns none when no auth config is present', () => { + const req = new BrunoRequest(makeReq()); + + expect(req.getAuthMode()).toBe('none'); + }); }); diff --git a/packages/bruno-requests/src/auth/oauth1-request-authorization.ts b/packages/bruno-requests/src/auth/oauth1-request-authorization.ts index 5ba1654ccc1..af619b3e581 100644 --- a/packages/bruno-requests/src/auth/oauth1-request-authorization.ts +++ b/packages/bruno-requests/src/auth/oauth1-request-authorization.ts @@ -365,9 +365,6 @@ export function applyOAuth1ToRequest(request: { version, realm, placement, includeBodyHash } = request.oauth1config; - // Clear credentials from the request object before any operation that could throw - delete (request as any).oauth1config; - // Resolve private key: read from file if privateKeyType is 'file', otherwise use as-is let resolvedPrivateKey: string | undefined; if (privateKey) { diff --git a/tests/auth/apikey/apikey-runner.spec.ts b/tests/auth/apikey/apikey-runner.spec.ts deleted file mode 100644 index 02052afdbd3..00000000000 --- a/tests/auth/apikey/apikey-runner.spec.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { test } from '../../../playwright'; -import { setSandboxMode, runCollection, validateRunnerResults } from '../../utils/page'; - -const COLLECTION_NAME = 'apikey-auth-mode-test'; - -test.describe.serial('API Key Auth Mode Runner', () => { - for (const mode of ['safe', 'developer'] as const) { - test(`detects API key auth in ${mode} mode`, async ({ pageWithUserData: page }) => { - await setSandboxMode(page, COLLECTION_NAME, mode); - await runCollection(page, COLLECTION_NAME); - - await validateRunnerResults(page, { - totalRequests: 2, - passed: 2, - failed: 0, - skipped: 0 - }); - }); - } -}); diff --git a/tests/auth/auth-mode/auth-mode-runner.spec.ts b/tests/auth/auth-mode/auth-mode-runner.spec.ts new file mode 100644 index 00000000000..3fc478b05cd --- /dev/null +++ b/tests/auth/auth-mode/auth-mode-runner.spec.ts @@ -0,0 +1,40 @@ +import { test } from '../../../playwright'; +import { setSandboxMode, runCollection, validateRunnerResults } from '../../utils/page'; + +const COLLECTION_NAME = 'auth-mode-test'; +const AUTH_MODE_REQUESTS = [ + 'aws-sigv4', + 'basic-auth', + 'ntlm', + 'bearer', + 'digest', + 'wsse', + 'oauth1', + 'oauth2', + 'api-key-header', + 'api-key-query' +]; + +const EXTRA_REQUESTS = [ + 'no-auth', + 'inherited-aws-sigv4', + 'inherited-basic-auth', + 'inherited-ntlm' +]; +const EXPECTED_REQUESTS = [...AUTH_MODE_REQUESTS, ...EXTRA_REQUESTS]; + +test.describe.serial('Auth Mode Runner', () => { + for (const mode of ['safe', 'developer'] as const) { + test(`detects auth modes in ${mode} mode`, async ({ pageWithUserData: page }) => { + await setSandboxMode(page, COLLECTION_NAME, mode); + await runCollection(page, COLLECTION_NAME); + + await validateRunnerResults(page, { + totalRequests: EXPECTED_REQUESTS.length, + passed: EXPECTED_REQUESTS.length, + failed: 0, + skipped: 0 + }); + }); + } +}); diff --git a/tests/auth/auth-mode/fixtures/collections/auth-mode-test/api-key-header.bru b/tests/auth/auth-mode/fixtures/collections/auth-mode-test/api-key-header.bru new file mode 100644 index 00000000000..f476e6d6d5d --- /dev/null +++ b/tests/auth/auth-mode/fixtures/collections/auth-mode-test/api-key-header.bru @@ -0,0 +1,34 @@ +meta { + name: api-key-header + type: http + seq: 10 +} + +get { + url: http://localhost:8081/ping + body: none + auth: apikey +} + +auth:apikey { + key: {{api_key_header_name}} + value: {{api_key_value}} + placement: header +} + +vars:pre-request { + api_key_header_name: X-API-Key + api_key_value: secret-key-value +} + +script:pre-request { + test("detects API key auth for header placement in pre-request script", function() { + expect(req.getAuthMode()).to.equal("apikey"); + }); +} + +tests { + test("detects API key auth for header placement in test script", function() { + expect(req.getAuthMode()).to.equal("apikey"); + }); +} diff --git a/tests/auth/auth-mode/fixtures/collections/auth-mode-test/api-key-query.bru b/tests/auth/auth-mode/fixtures/collections/auth-mode-test/api-key-query.bru new file mode 100644 index 00000000000..2e7e1ddc08e --- /dev/null +++ b/tests/auth/auth-mode/fixtures/collections/auth-mode-test/api-key-query.bru @@ -0,0 +1,34 @@ +meta { + name: api-key-query + type: http + seq: 11 +} + +get { + url: http://localhost:8081/ping + body: none + auth: apikey +} + +auth:apikey { + key: {{api_key_query_name}} + value: {{api_key_value}} + placement: queryparams +} + +vars:pre-request { + api_key_query_name: api_key + api_key_value: secret-key-value +} + +script:pre-request { + test("detects API key auth for query placement in pre-request script", function() { + expect(req.getAuthMode()).to.equal("apikey"); + }); +} + +tests { + test("detects API key auth for query placement in test script", function() { + expect(req.getAuthMode()).to.equal("apikey"); + }); +} diff --git a/tests/auth/auth-mode/fixtures/collections/auth-mode-test/aws-sigv4.bru b/tests/auth/auth-mode/fixtures/collections/auth-mode-test/aws-sigv4.bru new file mode 100644 index 00000000000..1297ad8844d --- /dev/null +++ b/tests/auth/auth-mode/fixtures/collections/auth-mode-test/aws-sigv4.bru @@ -0,0 +1,32 @@ +meta { + name: aws-sigv4 + type: http + seq: 1 +} + +get { + url: http://localhost:8081/ping + body: none + auth: awsv4 +} + +auth:awsv4 { + accessKeyId: access-key + secretAccessKey: secret-key + sessionToken: + service: execute-api + region: us-east-1 + profileName: +} + +script:pre-request { + test("detects AWS SigV4 auth in pre-request script", function() { + expect(req.getAuthMode()).to.equal("awsv4"); + }); +} + +tests { + test("detects AWS SigV4 auth in test script", function() { + expect(req.getAuthMode()).to.equal("awsv4"); + }); +} diff --git a/tests/auth/auth-mode/fixtures/collections/auth-mode-test/basic-auth.bru b/tests/auth/auth-mode/fixtures/collections/auth-mode-test/basic-auth.bru new file mode 100644 index 00000000000..4a1347c1002 --- /dev/null +++ b/tests/auth/auth-mode/fixtures/collections/auth-mode-test/basic-auth.bru @@ -0,0 +1,28 @@ +meta { + name: basic-auth + type: http + seq: 2 +} + +get { + url: http://localhost:8081/ping + body: none + auth: basic +} + +auth:basic { + username: user + password: password +} + +script:pre-request { + test("detects Basic auth in pre-request script", function() { + expect(req.getAuthMode()).to.equal("basic"); + }); +} + +tests { + test("detects Basic auth after interpolation", function() { + expect(req.getAuthMode()).to.equal("basic"); + }); +} diff --git a/tests/auth/auth-mode/fixtures/collections/auth-mode-test/bearer.bru b/tests/auth/auth-mode/fixtures/collections/auth-mode-test/bearer.bru new file mode 100644 index 00000000000..8c82af23ecc --- /dev/null +++ b/tests/auth/auth-mode/fixtures/collections/auth-mode-test/bearer.bru @@ -0,0 +1,27 @@ +meta { + name: bearer + type: http + seq: 5 +} + +get { + url: http://localhost:8081/ping + body: none + auth: bearer +} + +auth:bearer { + token: bearer-token +} + +script:pre-request { + test("detects Bearer auth in pre-request script", function() { + expect(req.getAuthMode()).to.equal("bearer"); + }); +} + +tests { + test("detects Bearer auth in test script", function() { + expect(req.getAuthMode()).to.equal("bearer"); + }); +} diff --git a/tests/auth/auth-mode/fixtures/collections/auth-mode-test/bruno.json b/tests/auth/auth-mode/fixtures/collections/auth-mode-test/bruno.json new file mode 100644 index 00000000000..029a3cf4319 --- /dev/null +++ b/tests/auth/auth-mode/fixtures/collections/auth-mode-test/bruno.json @@ -0,0 +1,5 @@ +{ + "version": "1", + "name": "auth-mode-test", + "type": "collection" +} diff --git a/tests/auth/auth-mode/fixtures/collections/auth-mode-test/digest.bru b/tests/auth/auth-mode/fixtures/collections/auth-mode-test/digest.bru new file mode 100644 index 00000000000..8f9d809b5e9 --- /dev/null +++ b/tests/auth/auth-mode/fixtures/collections/auth-mode-test/digest.bru @@ -0,0 +1,28 @@ +meta { + name: digest + type: http + seq: 6 +} + +get { + url: http://localhost:8081/ping + body: none + auth: digest +} + +auth:digest { + username: user + password: password +} + +script:pre-request { + test("detects Digest auth in pre-request script", function() { + expect(req.getAuthMode()).to.equal("digest"); + }); +} + +tests { + test("detects Digest auth in test script", function() { + expect(req.getAuthMode()).to.equal("digest"); + }); +} diff --git a/tests/auth/auth-mode/fixtures/collections/auth-mode-test/inherit-aws-sigv4/folder.bru b/tests/auth/auth-mode/fixtures/collections/auth-mode-test/inherit-aws-sigv4/folder.bru new file mode 100644 index 00000000000..801108ac2f6 --- /dev/null +++ b/tests/auth/auth-mode/fixtures/collections/auth-mode-test/inherit-aws-sigv4/folder.bru @@ -0,0 +1,16 @@ +meta { + name: inherit-aws-sigv4 +} + +auth { + mode: awsv4 +} + +auth:awsv4 { + accessKeyId: access-key + secretAccessKey: secret-key + sessionToken: + service: execute-api + region: us-east-1 + profileName: +} diff --git a/tests/auth/auth-mode/fixtures/collections/auth-mode-test/inherit-aws-sigv4/inherited-aws-sigv4.bru b/tests/auth/auth-mode/fixtures/collections/auth-mode-test/inherit-aws-sigv4/inherited-aws-sigv4.bru new file mode 100644 index 00000000000..b334650c7aa --- /dev/null +++ b/tests/auth/auth-mode/fixtures/collections/auth-mode-test/inherit-aws-sigv4/inherited-aws-sigv4.bru @@ -0,0 +1,23 @@ +meta { + name: inherited-aws-sigv4 + type: http + seq: 1 +} + +get { + url: http://localhost:8081/ping + body: none + auth: inherit +} + +script:pre-request { + test("detects inherited AWS SigV4 auth in pre-request script", function() { + expect(req.getAuthMode()).to.equal("awsv4"); + }); +} + +tests { + test("detects inherited AWS SigV4 auth in test script", function() { + expect(req.getAuthMode()).to.equal("awsv4"); + }); +} diff --git a/tests/auth/auth-mode/fixtures/collections/auth-mode-test/inherit-basic-auth/folder.bru b/tests/auth/auth-mode/fixtures/collections/auth-mode-test/inherit-basic-auth/folder.bru new file mode 100644 index 00000000000..03fcdc73c82 --- /dev/null +++ b/tests/auth/auth-mode/fixtures/collections/auth-mode-test/inherit-basic-auth/folder.bru @@ -0,0 +1,12 @@ +meta { + name: inherit-basic-auth +} + +auth { + mode: basic +} + +auth:basic { + username: user + password: password +} diff --git a/tests/auth/auth-mode/fixtures/collections/auth-mode-test/inherit-basic-auth/inherited-basic-auth.bru b/tests/auth/auth-mode/fixtures/collections/auth-mode-test/inherit-basic-auth/inherited-basic-auth.bru new file mode 100644 index 00000000000..8107cda3e3e --- /dev/null +++ b/tests/auth/auth-mode/fixtures/collections/auth-mode-test/inherit-basic-auth/inherited-basic-auth.bru @@ -0,0 +1,23 @@ +meta { + name: inherited-basic-auth + type: http + seq: 1 +} + +get { + url: http://localhost:8081/ping + body: none + auth: inherit +} + +script:pre-request { + test("detects inherited Basic auth in pre-request script", function() { + expect(req.getAuthMode()).to.equal("basic"); + }); +} + +tests { + test("detects inherited Basic auth in test script", function() { + expect(req.getAuthMode()).to.equal("basic"); + }); +} diff --git a/tests/auth/auth-mode/fixtures/collections/auth-mode-test/inherit-ntlm/folder.bru b/tests/auth/auth-mode/fixtures/collections/auth-mode-test/inherit-ntlm/folder.bru new file mode 100644 index 00000000000..97760083a4b --- /dev/null +++ b/tests/auth/auth-mode/fixtures/collections/auth-mode-test/inherit-ntlm/folder.bru @@ -0,0 +1,13 @@ +meta { + name: inherit-ntlm +} + +auth { + mode: ntlm +} + +auth:ntlm { + username: user + password: password + domain: domain +} diff --git a/tests/auth/auth-mode/fixtures/collections/auth-mode-test/inherit-ntlm/inherited-ntlm.bru b/tests/auth/auth-mode/fixtures/collections/auth-mode-test/inherit-ntlm/inherited-ntlm.bru new file mode 100644 index 00000000000..408c231349d --- /dev/null +++ b/tests/auth/auth-mode/fixtures/collections/auth-mode-test/inherit-ntlm/inherited-ntlm.bru @@ -0,0 +1,23 @@ +meta { + name: inherited-ntlm + type: http + seq: 1 +} + +get { + url: http://localhost:8081/ping + body: none + auth: inherit +} + +script:pre-request { + test("detects inherited NTLM auth in pre-request script", function() { + expect(req.getAuthMode()).to.equal("ntlm"); + }); +} + +tests { + test("detects inherited NTLM auth in test script", function() { + expect(req.getAuthMode()).to.equal("ntlm"); + }); +} diff --git a/tests/auth/auth-mode/fixtures/collections/auth-mode-test/no-auth.bru b/tests/auth/auth-mode/fixtures/collections/auth-mode-test/no-auth.bru new file mode 100644 index 00000000000..2093763df9b --- /dev/null +++ b/tests/auth/auth-mode/fixtures/collections/auth-mode-test/no-auth.bru @@ -0,0 +1,23 @@ +meta { + name: no-auth + type: http + seq: 4 +} + +get { + url: http://localhost:8081/ping + body: none + auth: none +} + +script:pre-request { + test("detects no auth in pre-request script", function() { + expect(req.getAuthMode()).to.equal("none"); + }); +} + +tests { + test("detects no auth in test script", function() { + expect(req.getAuthMode()).to.equal("none"); + }); +} diff --git a/tests/auth/auth-mode/fixtures/collections/auth-mode-test/ntlm.bru b/tests/auth/auth-mode/fixtures/collections/auth-mode-test/ntlm.bru new file mode 100644 index 00000000000..73efe1f2a8d --- /dev/null +++ b/tests/auth/auth-mode/fixtures/collections/auth-mode-test/ntlm.bru @@ -0,0 +1,29 @@ +meta { + name: ntlm + type: http + seq: 3 +} + +get { + url: http://localhost:8081/ping + body: none + auth: ntlm +} + +auth:ntlm { + username: user + password: password + domain: domain +} + +script:pre-request { + test("detects NTLM auth in pre-request script", function() { + expect(req.getAuthMode()).to.equal("ntlm"); + }); +} + +tests { + test("detects NTLM auth in test script", function() { + expect(req.getAuthMode()).to.equal("ntlm"); + }); +} diff --git a/tests/auth/auth-mode/fixtures/collections/auth-mode-test/oauth1.bru b/tests/auth/auth-mode/fixtures/collections/auth-mode-test/oauth1.bru new file mode 100644 index 00000000000..0c8cac53a3e --- /dev/null +++ b/tests/auth/auth-mode/fixtures/collections/auth-mode-test/oauth1.bru @@ -0,0 +1,40 @@ +meta { + name: oauth1 + type: http + seq: 8 +} + +get { + url: http://localhost:8081/ping + body: none + auth: oauth1 +} + +auth:oauth1 { + consumer_key: consumer-key + consumer_secret: consumer-secret + access_token: access-token + token_secret: token-secret + callback_url: + verifier: + signature_method: PLAINTEXT + private_key: + timestamp: + nonce: + version: 1.0 + realm: + placement: header + include_body_hash: false +} + +script:pre-request { + test("detects OAuth1 auth in pre-request script", function() { + expect(req.getAuthMode()).to.equal("oauth1"); + }); +} + +tests { + test("detects OAuth1 auth in test script", function() { + expect(req.getAuthMode()).to.equal("oauth1"); + }); +} diff --git a/tests/auth/auth-mode/fixtures/collections/auth-mode-test/oauth2.bru b/tests/auth/auth-mode/fixtures/collections/auth-mode-test/oauth2.bru new file mode 100644 index 00000000000..eecd143d855 --- /dev/null +++ b/tests/auth/auth-mode/fixtures/collections/auth-mode-test/oauth2.bru @@ -0,0 +1,43 @@ +meta { + name: oauth2 + type: http + seq: 9 +} + +get { + url: http://localhost:8081/ping + body: none + auth: oauth2 +} + +auth:oauth2 { + grant_type: authorization_code + callback_url: + authorization_url: + access_token_url: + refresh_token_url: + client_id: + client_secret: + scope: + state: + pkce: false + credentials_placement: body + credentials_id: credentials + token_source: access_token + token_placement: header + token_header_prefix: Bearer + auto_fetch_token: false + auto_refresh_token: false +} + +script:pre-request { + test("detects OAuth2 auth in pre-request script", function() { + expect(req.getAuthMode()).to.equal("oauth2"); + }); +} + +tests { + test("detects OAuth2 auth in test script", function() { + expect(req.getAuthMode()).to.equal("oauth2"); + }); +} diff --git a/tests/auth/auth-mode/fixtures/collections/auth-mode-test/wsse.bru b/tests/auth/auth-mode/fixtures/collections/auth-mode-test/wsse.bru new file mode 100644 index 00000000000..6ae750cbd7a --- /dev/null +++ b/tests/auth/auth-mode/fixtures/collections/auth-mode-test/wsse.bru @@ -0,0 +1,28 @@ +meta { + name: wsse + type: http + seq: 7 +} + +get { + url: http://localhost:8081/ping + body: none + auth: wsse +} + +auth:wsse { + username: user + password: password +} + +script:pre-request { + test("detects WSSE auth in pre-request script", function() { + expect(req.getAuthMode()).to.equal("wsse"); + }); +} + +tests { + test("detects WSSE auth in test script", function() { + expect(req.getAuthMode()).to.equal("wsse"); + }); +} diff --git a/tests/auth/auth-mode/init-user-data/preferences.json b/tests/auth/auth-mode/init-user-data/preferences.json new file mode 100644 index 00000000000..011c51e3df6 --- /dev/null +++ b/tests/auth/auth-mode/init-user-data/preferences.json @@ -0,0 +1,11 @@ +{ + "lastOpenedCollections": [ + "{{collectionPath}}/auth-mode-test" + ], + "preferences": { + "onboarding": { + "hasLaunchedBefore": true, + "hasSeenWelcomeModal": true + } + } +}