* Fix case-insensitive pre-auth header check in doPing HTTP headers are case-insensitive per RFC 7230, but the pre-auth rejection check accessed x-reject-reason using an exact lowercase key. Servers/proxies may return varying cases (e.g. X-Reject-Reason). Add a getResponseHeader utility for case-insensitive lookup and use it in both pre-auth check paths. * Address PR feedback: optimize getResponseHeader and fix test description Try exact match and lowercase match before falling back to a full scan to avoid array allocation on every call. Fix test description to say "uppercase" instead of "mixed case" to match the test data.
30 lines
1.2 KiB
TypeScript
30 lines
1.2 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {getResponseHeader} from './headers';
|
|
|
|
describe('getResponseHeader', () => {
|
|
it('should return the value for an exact-case match', () => {
|
|
const headers = {'X-Reject-Reason': 'pre-auth'};
|
|
expect(getResponseHeader(headers, 'X-Reject-Reason')).toBe('pre-auth');
|
|
});
|
|
|
|
it('should return the value when header name differs in case', () => {
|
|
const headers = {'x-reject-reason': 'pre-auth'};
|
|
expect(getResponseHeader(headers, 'X-Reject-Reason')).toBe('pre-auth');
|
|
});
|
|
|
|
it('should return the value when lookup name is lowercase but header is uppercase', () => {
|
|
const headers = {'X-REJECT-REASON': 'pre-auth'};
|
|
expect(getResponseHeader(headers, 'x-reject-reason')).toBe('pre-auth');
|
|
});
|
|
|
|
it('should return undefined when the header is not present', () => {
|
|
const headers = {'Content-Type': 'application/json'};
|
|
expect(getResponseHeader(headers, 'X-Reject-Reason')).toBeUndefined();
|
|
});
|
|
|
|
it('should return undefined when headers object is undefined', () => {
|
|
expect(getResponseHeader(undefined, 'X-Reject-Reason')).toBeUndefined();
|
|
});
|
|
});
|