Skip to content

Commit

Permalink
Add a bunch of failing fragmentation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
uNetworkingAB committed Oct 26, 2024
1 parent 6a0b70d commit e81dbcb
Showing 1 changed file with 109 additions and 3 deletions.
112 changes: 109 additions & 3 deletions tests/http_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,106 @@ interface TestCase {
}

const testCases: TestCase[] = [
{
request: "G",
description: "Fragmented method",
expectedStatus: [[-1, -1]],
expectedTimeout: true
},
{
request: "GET ",
description: "Fragmented URL 1",
expectedStatus: [[-1, -1]],
expectedTimeout: true
},
{
request: "GET /hello",
description: "Fragmented URL 2",
expectedStatus: [[-1, -1]],
expectedTimeout: true
},
{
request: "GET /hello ",
description: "Fragmented URL 3",
expectedStatus: [[-1, -1]],
expectedTimeout: true
},
{
request: "GET /hello HTTP",
description: "Fragmented HTTP version",
expectedStatus: [[-1, -1]],
expectedTimeout: true
},
{
request: "GET /hello HTTP/1.1",
description: "Fragmented request line",
expectedStatus: [[-1, -1]],
expectedTimeout: true
},
{
request: "GET /hello HTTP/1.1\r",
description: "Fragmented request line newline 1",
expectedStatus: [[-1, -1]],
expectedTimeout: true
},
{
request: "GET /hello HTTP/1.1\r\n",
description: "Fragmented request line newline 2",
expectedStatus: [[-1, -1]],
expectedTimeout: true
},
{
request: "GET /hello HTTP/1.1\r\nHos",
description: "Fragmented field name",
expectedStatus: [[-1, -1]],
expectedTimeout: true
},
{
request: "GET /hello HTTP/1.1\r\nHost:",
description: "Fragmented field value 1",
expectedStatus: [[-1, -1]],
expectedTimeout: true
},
{
request: "GET /hello HTTP/1.1\r\nHost: ",
description: "Fragmented field value 2",
expectedStatus: [[-1, -1]],
expectedTimeout: true
},
{
request: "GET /hello HTTP/1.1\r\nHost: localhost",
description: "Fragmented field value 3",
expectedStatus: [[-1, -1]],
expectedTimeout: true
},
{
request: "GET /hello HTTP/1.1\r\nHost: localhost\r",
description: "Fragmented field value 4",
expectedStatus: [[-1, -1]],
expectedTimeout: true
},
{
request: "GET /hello HTTP/1.1\r\nHost: localhost\r\n",
description: "Fragmented request",
expectedStatus: [[-1, -1]],
expectedTimeout: true
},
{
request: "GET /hello HTTP/1.1\r\nHost: localhost\r\n\r",
description: "Fragmented request termination",
expectedStatus: [[-1, -1]],
expectedTimeout: true
},
{
request: "GET / \r\n\r\n",
description: "Request without HTTP version",
expectedStatus: [[400, 599]],
},
{
request: "GET / HTTP/1.1\r\nHost: example.com\r\nExpect: 100-continue\r\n\r\n",
description: "Request with Expect header",
expectedStatus: [[100, 100], [200, 299]],
},
{
request: "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n",
description: "Valid GET request",
Expand Down Expand Up @@ -109,9 +209,15 @@ async function runTestCase(testCase: TestCase, host: string, port: number): Prom
// Set up a read timeout promise
const readTimeout = new Promise<boolean>((resolve) => {
const timeoutId = setTimeout(() => {
console.error(`❌ ${testCase.description}: Read operation timed out`);
conn.close(); // Ensure the connection is closed on timeout
resolve(false);
if (testCase.expectedTimeout) {
console.error(`✅ ${testCase.description}: Server waited successfully`);
conn.close(); // Ensure the connection is closed on timeout
resolve(true);
} else {
console.error(`❌ ${testCase.description}: Read operation timed out`);
conn.close(); // Ensure the connection is closed on timeout
resolve(false);
}
}, 500);

const readPromise = (async () => {
Expand Down

0 comments on commit e81dbcb

Please sign in to comment.