Skip to content

Commit

Permalink
ignore payload key-value if value is empty (#22105)
Browse files Browse the repository at this point in the history
fixes #22104
  • Loading branch information
eleanorjboyd authored Sep 28, 2023
1 parent cc2a567 commit 0fe920f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/client/testing/testController/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,10 @@ export function parseJsonRPCHeadersAndData(rawData: string): ParsedRPCHeadersAnd
break;
}
const [key, value] = line.split(':');
if ([JSONRPC_UUID_HEADER, JSONRPC_CONTENT_LENGTH_HEADER, JSONRPC_CONTENT_TYPE_HEADER].includes(key)) {
headerMap.set(key.trim(), value.trim());
if (value.trim()) {
if ([JSONRPC_UUID_HEADER, JSONRPC_CONTENT_LENGTH_HEADER, JSONRPC_CONTENT_TYPE_HEADER].includes(key)) {
headerMap.set(key.trim(), value.trim());
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/test/testing/common/testingPayloadsEot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
PAYLOAD_SPLIT_ACROSS_CHUNKS_ARRAY,
DataWithPayloadChunks,
PAYLOAD_SPLIT_MULTI_CHUNK_ARRAY,
PAYLOAD_ONLY_HEADER_MULTI_CHUNK,
} from '../testController/payloadTestCases';
import { traceLog } from '../../../client/logging';

Expand All @@ -37,6 +38,10 @@ export interface TestCase {
}

const testCases: Array<TestCase> = [
{
name: 'header in single chunk edge case',
value: PAYLOAD_ONLY_HEADER_MULTI_CHUNK(FAKE_UUID),
},
{
name: 'single payload single chunk',
value: PAYLOAD_SINGLE_CHUNK(FAKE_UUID),
Expand Down
19 changes: 19 additions & 0 deletions src/test/testing/testController/payloadTestCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,25 @@ export function PAYLOAD_MULTI_CHUNK(uuid: string): DataWithPayloadChunks {
};
}

// more than one payload, split so the first one is only 'Content-Length' to confirm headers
// with null values are ignored
export function PAYLOAD_ONLY_HEADER_MULTI_CHUNK(uuid: string): DataWithPayloadChunks {
const payloadArray: string[] = [];
const result = JSON.stringify(SINGLE_UNITTEST_SUBTEST.result);

const val = createPayload(uuid, SINGLE_UNITTEST_SUBTEST);
const firstSpaceIndex = val.indexOf(' ');
const payload1 = val.substring(0, firstSpaceIndex);
const payload2 = val.substring(firstSpaceIndex);
payloadArray.push(payload1);
payloadArray.push(payload2);
payloadArray.push(EOT_PAYLOAD);
return {
payloadArray,
data: result,
};
}

// single payload divided by an arbitrary character and split across payloads
export function PAYLOAD_SPLIT_ACROSS_CHUNKS_ARRAY(uuid: string): DataWithPayloadChunks {
const payload = createPayload(uuid, SINGLE_PYTEST_PAYLOAD);
Expand Down

0 comments on commit 0fe920f

Please sign in to comment.