mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2025-12-27 13:40:47 +00:00
makeHttpError: Ensure response headers have lowercase names
This commit is contained in:
40
ts/test-electron/textsecure/WebAPI_test.ts
Normal file
40
ts/test-electron/textsecure/WebAPI_test.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
// Copyright 2025 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { assert } from 'chai';
|
||||
|
||||
import { makeKeysLowercase } from '../../textsecure/WebAPI';
|
||||
|
||||
describe('WebAPI', () => {
|
||||
describe('makeKeysLowercase', () => {
|
||||
it('handles empty object', () => {
|
||||
const expected = Object.create(null);
|
||||
const actual = makeKeysLowercase({});
|
||||
assert.deepEqual(expected, actual);
|
||||
});
|
||||
it('handles one key', () => {
|
||||
const expected = Object.create(null);
|
||||
expected.low = 4;
|
||||
|
||||
const actual = makeKeysLowercase({
|
||||
LOW: 4,
|
||||
});
|
||||
|
||||
assert.deepEqual(expected, actual);
|
||||
});
|
||||
it('handles lots of keys', () => {
|
||||
const expected = Object.create(null);
|
||||
expected.one = 'one more';
|
||||
expected.two = 'two more';
|
||||
expected.three = 'three';
|
||||
|
||||
const actual = makeKeysLowercase({
|
||||
One: 'one more',
|
||||
TWO: 'two more',
|
||||
ThreE: 'three',
|
||||
});
|
||||
|
||||
assert.deepEqual(expected, actual);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -638,12 +638,25 @@ function makeHTTPError(
|
||||
) {
|
||||
return new HTTPError(message, {
|
||||
code: providedCode,
|
||||
headers,
|
||||
headers: makeKeysLowercase(headers),
|
||||
response,
|
||||
stack,
|
||||
});
|
||||
}
|
||||
|
||||
export function makeKeysLowercase<V>(
|
||||
headers: Record<string, V>
|
||||
): Record<string, V> {
|
||||
const keys = Object.keys(headers);
|
||||
const lowerCase: Record<string, V> = Object.create(null);
|
||||
|
||||
keys.forEach(key => {
|
||||
lowerCase[key.toLowerCase()] = headers[key];
|
||||
});
|
||||
|
||||
return lowerCase;
|
||||
}
|
||||
|
||||
const URL_CALLS = {
|
||||
accountExistence: 'v1/accounts/account',
|
||||
attachmentUploadForm: 'v4/attachments/form/upload',
|
||||
|
||||
Reference in New Issue
Block a user