diff options
| author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2019-05-30 14:59:30 +0200 |
|---|---|---|
| committer | Ryan Dahl <ry@tinyclouds.org> | 2019-05-30 08:59:30 -0400 |
| commit | 50a79584cb12129b3db1ef3e0eb9d0c8b9f20b62 (patch) | |
| tree | ee9a90a8b8018c03b1e1a6ace07abdaa494ea90d /http/server_test.ts | |
| parent | 80b3c486f6222f65b52eb2eca903b67312e8ce0c (diff) | |
chore: Implement strict mode (denoland/deno_std#453)
Original: https://github.com/denoland/deno_std/commit/be24677d15494e83eea2e99bfc5ccfdde31cb892
Diffstat (limited to 'http/server_test.ts')
| -rw-r--r-- | http/server_test.ts | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/http/server_test.ts b/http/server_test.ts index e24ab0be9..2a6163d91 100644 --- a/http/server_test.ts +++ b/http/server_test.ts @@ -336,65 +336,64 @@ malformedHeader // https://github.com/golang/go/blob/go1.12.5/src/net/http/request_test.go#L377-L443 // TODO(zekth) fix tests test(async function testReadRequestError(): Promise<void> { - const testCases = { - 0: { + const testCases = [ + { in: "GET / HTTP/1.1\r\nheader: foo\r\n\r\n", headers: [{ key: "header", value: "foo" }] }, - 1: { + { in: "GET / HTTP/1.1\r\nheader:foo\r\n", err: UnexpectedEOFError }, - 2: { in: "", err: EOF }, - 3: { + { in: "", err: EOF }, + { in: "HEAD / HTTP/1.1\r\nContent-Length:4\r\n\r\n", err: "http: method cannot contain a Content-Length" }, - 4: { + { in: "HEAD / HTTP/1.1\r\n\r\n", headers: [] }, // Multiple Content-Length values should either be // deduplicated if same or reject otherwise // See Issue 16490. - 5: { + { in: "POST / HTTP/1.1\r\nContent-Length: 10\r\nContent-Length: 0\r\n\r\nGopher hey\r\n", err: "cannot contain multiple Content-Length headers" }, - 6: { + { in: "POST / HTTP/1.1\r\nContent-Length: 10\r\nContent-Length: 6\r\n\r\nGopher\r\n", err: "cannot contain multiple Content-Length headers" }, - 7: { + { in: "PUT / HTTP/1.1\r\nContent-Length: 6 \r\nContent-Length: 6\r\nContent-Length:6\r\n\r\nGopher\r\n", headers: [{ key: "Content-Length", value: "6" }] }, - 8: { + { in: "PUT / HTTP/1.1\r\nContent-Length: 1\r\nContent-Length: 6 \r\n\r\n", err: "cannot contain multiple Content-Length headers" }, // Setting an empty header is swallowed by textproto // see: readMIMEHeader() - // 9: { + // { // in: "POST / HTTP/1.1\r\nContent-Length:\r\nContent-Length: 3\r\n\r\n", // err: "cannot contain multiple Content-Length headers" // }, - 10: { + { in: "HEAD / HTTP/1.1\r\nContent-Length:0\r\nContent-Length: 0\r\n\r\n", headers: [{ key: "Content-Length", value: "0" }] }, - 11: { + { in: "POST / HTTP/1.1\r\nContent-Length:0\r\ntransfer-encoding: chunked\r\n\r\n", headers: [], err: "http: Transfer-Encoding and Content-Length cannot be send together" } - }; - for (const p in testCases) { - const test = testCases[p]; + ]; + for (const test of testCases) { const reader = new BufReader(new StringReader(test.in)); let err; let req; @@ -408,12 +407,12 @@ test(async function testReadRequestError(): Promise<void> { } else if (typeof test.err === "string") { assertEquals(err.message, test.err); } else if (test.err) { - assert(err instanceof test.err); + assert(err instanceof (test.err as typeof UnexpectedEOFError)); } else { assertEquals(err, undefined); assertNotEquals(req, EOF); - for (const h of test.headers) { - assertEquals(req.headers.get(h.key), h.value); + for (const h of test.headers!) { + assertEquals((req! as ServerRequest).headers.get(h.key), h.value); } } } |
