diff --git a/packages/insomnia/src/network/__tests__/network.test.ts b/packages/insomnia/src/network/__tests__/network.test.ts index d7772c4158fb..c2dc8596b525 100644 --- a/packages/insomnia/src/network/__tests__/network.test.ts +++ b/packages/insomnia/src/network/__tests__/network.test.ts @@ -1098,6 +1098,32 @@ describe('getCurrentUrl for tough-cookie', () => { }); }); +describe('getOrInheritAuthentication', () => { + it('should prefer the closest parent folder auth over higher-level folder auth', () => { + const request = { authentication: {} }; + const requestGroups = [ + { authentication: { type: 'basic', username: 'closest', password: 'closest-pass' } }, + { authentication: { type: 'basic', username: 'root', password: 'root-pass' } }, + ]; + + expect(networkUtils.getOrInheritAuthentication({ request, requestGroups })).toEqual({ + type: 'basic', + username: 'closest', + password: 'closest-pass', + }); + }); + + it("should stop inheritance when the closest parent folder auth is { type: 'none' }", () => { + const request = { authentication: {} }; + const requestGroups = [ + { authentication: { type: 'none' } }, + { authentication: { type: 'basic', username: 'root', password: 'root-pass' } }, + ]; + + expect(networkUtils.getOrInheritAuthentication({ request, requestGroups })).toEqual({ type: 'none' }); + }); +}); + describe('getOrInheritHeaders', () => { it('should combine headers', () => { const requestGroups = [{ headers: [{ name: 'foo', value: 'bar' }] }, { headers: [{ name: 'baz', value: 'qux' }] }];