annotate spec/net_http_parser_spec.lua @ 14205:a874c3f4570a 13.0

util.startup: Always apply umask (thanks Max Hearnden) Commit c673ff1075bd removed mod_posix, and moved functionality into util.startup, including applying a secure umask at runtime. However, the new function was not called from the startup sequence, leading Prosody to run with whatever umask it inherited from the environment. Prosody Debian packages ship with a secure umask 027 in the systemd unit file for the prosody service, so Debian systems using systemd are not affected. prosodyctl calls the switch_user() function during startup, which would set the umask, so prosodyctl commands which created files were unaffected. This change makes both prosody and prosodyctl unconditionally set a secure umask during the startup process.
author Matthew Wild <mwild1@gmail.com>
date Thu, 28 May 2026 17:25:46 +0100
parents 79a6598cef0b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10497
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
1 local http_parser = require "net.http.parser";
11030
388f599f66d1 net.http.parser: Add failing test for (large?) chunk-encoded responses
Matthew Wild <mwild1@gmail.com>
parents: 11021
diff changeset
2 local sha1 = require "util.hashes".sha1;
10497
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
3
11033
cb5555443852 net.http.parser: Allow configuration of the chunk size fed to the parser
Matthew Wild <mwild1@gmail.com>
parents: 11032
diff changeset
4 local parser_input_bytes = 3;
cb5555443852 net.http.parser: Allow configuration of the chunk size fed to the parser
Matthew Wild <mwild1@gmail.com>
parents: 11032
diff changeset
5
11032
28de68414750 net.http.parser: Switch tests so that CRLF conversion of input data is optional
Matthew Wild <mwild1@gmail.com>
parents: 11031
diff changeset
6 local function CRLF(s)
28de68414750 net.http.parser: Switch tests so that CRLF conversion of input data is optional
Matthew Wild <mwild1@gmail.com>
parents: 11031
diff changeset
7 return (s:gsub("\n", "\r\n"));
28de68414750 net.http.parser: Switch tests so that CRLF conversion of input data is optional
Matthew Wild <mwild1@gmail.com>
parents: 11031
diff changeset
8 end
28de68414750 net.http.parser: Switch tests so that CRLF conversion of input data is optional
Matthew Wild <mwild1@gmail.com>
parents: 11031
diff changeset
9
10497
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
10 local function test_stream(stream, expect)
12889
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
11 local chunks_processed = 0;
10497
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
12 local success_cb = spy.new(function (packet)
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
13 assert.is_table(packet);
11021
9673c95895fb net.http.parser: Allow specifying sink for large request bodies
Kim Alvefur <zash@zash.se>
parents: 10497
diff changeset
14 if packet.body ~= false then
9673c95895fb net.http.parser: Allow specifying sink for large request bodies
Kim Alvefur <zash@zash.se>
parents: 10497
diff changeset
15 assert.is_equal(expect.body, packet.body);
9673c95895fb net.http.parser: Allow specifying sink for large request bodies
Kim Alvefur <zash@zash.se>
parents: 10497
diff changeset
16 end
12889
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
17 if expect.chunks then
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
18 if chunks_processed == 0 then
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
19 assert.is_true(packet.partial);
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
20 packet.body_sink = {
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
21 write = function (_, data)
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
22 chunks_processed = chunks_processed + 1;
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
23 assert.equal(expect.chunks[chunks_processed], data);
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
24 return true;
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
25 end;
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
26 };
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
27 end
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
28 end
10497
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
29 end);
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
30
12889
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
31 local function options_cb()
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
32 return {
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
33 -- Force streaming API mode
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
34 body_size_limit = expect.chunks and 0 or nil;
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
35 buffer_size_limit = 10*1024*2;
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
36 };
10497
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
37 end
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
38
12889
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
39 local parser = http_parser.new(success_cb, error, (stream[1] or stream):sub(1,4) == "HTTP" and "client" or "server", options_cb)
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
40 if type(stream) == "string" then
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
41 for chunk in stream:gmatch("."..string.rep(".?", parser_input_bytes-1)) do
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
42 parser:feed(chunk);
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
43 end
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
44 else
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
45 for _, chunk in ipairs(stream) do
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
46 parser:feed(chunk);
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
47 end
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
48 end
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
49
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
50 if expect.chunks then
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
51 assert.equal(chunks_processed, #expect.chunks);
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
52 end
10497
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
53 assert.spy(success_cb).was_called(expect.count or 1);
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
54 end
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
55
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
56
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
57 describe("net.http.parser", function()
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
58 describe("parser", function()
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
59 it("should handle requests with no content-length or body", function ()
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
60 test_stream(
11032
28de68414750 net.http.parser: Switch tests so that CRLF conversion of input data is optional
Matthew Wild <mwild1@gmail.com>
parents: 11031
diff changeset
61 CRLF[[
8236
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
62 GET / HTTP/1.1
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
63 Host: example.com
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
64
10497
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
65 ]],
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
66 {
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
67 body = "";
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
68 }
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
69 );
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
70 end);
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
71
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
72 it("should handle responses with empty body", function ()
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
73 test_stream(
11032
28de68414750 net.http.parser: Switch tests so that CRLF conversion of input data is optional
Matthew Wild <mwild1@gmail.com>
parents: 11031
diff changeset
74 CRLF[[
8236
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
75 HTTP/1.1 200 OK
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
76 Content-Length: 0
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
77
10497
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
78 ]],
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
79 {
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
80 body = "";
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
81 }
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
82 );
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
83 end);
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
84
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
85 it("should handle simple responses", function ()
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
86 test_stream(
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
87
11032
28de68414750 net.http.parser: Switch tests so that CRLF conversion of input data is optional
Matthew Wild <mwild1@gmail.com>
parents: 11031
diff changeset
88 CRLF[[
8236
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
89 HTTP/1.1 200 OK
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
90 Content-Length: 7
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
91
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
92 Hello
10497
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
93 ]],
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
94 {
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
95 body = "Hello\r\n", count = 1;
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
96 }
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
97 );
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
98 end);
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
99
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
100 it("should handle chunked encoding in responses", function ()
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
101 test_stream(
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
102
11032
28de68414750 net.http.parser: Switch tests so that CRLF conversion of input data is optional
Matthew Wild <mwild1@gmail.com>
parents: 11031
diff changeset
103 CRLF[[
10497
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
104 HTTP/1.1 200 OK
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
105 Transfer-Encoding: chunked
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
106
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
107 1
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
108 H
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
109 1
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
110 e
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
111 2
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
112 ll
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
113 1
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
114 o
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
115 0
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
116
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
117
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
118 ]],
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
119 {
12882
9ed628635dc6 net.http.parser: Improve handling of responses without content-length
Matthew Wild <mwild1@gmail.com>
parents: 11033
diff changeset
120 body = "Hello", count = 3;
10497
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
121 }
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
122 );
14086
79a6598cef0b net.http.parser: Fix handling of chunked request
Kim Alvefur <zash@zash.se>
parents: 13378
diff changeset
123
79a6598cef0b net.http.parser: Fix handling of chunked request
Kim Alvefur <zash@zash.se>
parents: 13378
diff changeset
124 test_stream(
79a6598cef0b net.http.parser: Fix handling of chunked request
Kim Alvefur <zash@zash.se>
parents: 13378
diff changeset
125 "POST /debug HTTP/1.1\r\nHost: localhost:5280\r\nUser-Agent: curl/8.14.1\r\nTransfer-Encoding: chunked\r\nContent-Type: application/json\r\n"
79a6598cef0b net.http.parser: Fix handling of chunked request
Kim Alvefur <zash@zash.se>
parents: 13378
diff changeset
126 .."Accept: application/json\r\n\r\nd\r\n{\"json\":true}\r\n0\r\n\r\n",
79a6598cef0b net.http.parser: Fix handling of chunked request
Kim Alvefur <zash@zash.se>
parents: 13378
diff changeset
127 { count = 2; body = "{\"json\":true}" })
10497
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
128 end);
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
129
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
130 it("should handle a stream of responses", function ()
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
131 test_stream(
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
132
11032
28de68414750 net.http.parser: Switch tests so that CRLF conversion of input data is optional
Matthew Wild <mwild1@gmail.com>
parents: 11031
diff changeset
133 CRLF[[
10497
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
134 HTTP/1.1 200 OK
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
135 Content-Length: 5
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
136
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
137 Hello
8236
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
138 HTTP/1.1 200 OK
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
139 Transfer-Encoding: chunked
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
140
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
141 1
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
142 H
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
143 1
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
144 e
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
145 2
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
146 ll
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
147 1
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
148 o
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
149 0
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
150
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
151
10497
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
152 ]],
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
153 {
12882
9ed628635dc6 net.http.parser: Improve handling of responses without content-length
Matthew Wild <mwild1@gmail.com>
parents: 11033
diff changeset
154 body = "Hello", count = 4;
10497
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
155 }
a9fb553b6dbb net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents: 8236
diff changeset
156 );
8236
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
157 end);
12889
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
158
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
159 it("should correctly find chunk boundaries", function ()
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
160 test_stream({
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
161
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
162 CRLF[[
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
163 HTTP/1.1 200 OK
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
164 Transfer-Encoding: chunked
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
165
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
166 ]].."3\r\n:)\n\r\n"},
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
167 {
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
168 count = 1; -- Once (partial)
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
169 chunks = {
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
170 ":)\n"
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
171 };
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
172 }
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
173 );
94a99330ce87 net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents: 12882
diff changeset
174 end);
13378
db30ffbf2090 net.http.parser: Reject overlarge header section earlier
Kim Alvefur <zash@zash.se>
parents: 12889
diff changeset
175
db30ffbf2090 net.http.parser: Reject overlarge header section earlier
Kim Alvefur <zash@zash.se>
parents: 12889
diff changeset
176 it("should reject very large request heads", function()
db30ffbf2090 net.http.parser: Reject overlarge header section earlier
Kim Alvefur <zash@zash.se>
parents: 12889
diff changeset
177 local finished = false;
db30ffbf2090 net.http.parser: Reject overlarge header section earlier
Kim Alvefur <zash@zash.se>
parents: 12889
diff changeset
178 local success_cb = spy.new(function()
db30ffbf2090 net.http.parser: Reject overlarge header section earlier
Kim Alvefur <zash@zash.se>
parents: 12889
diff changeset
179 finished = true;
db30ffbf2090 net.http.parser: Reject overlarge header section earlier
Kim Alvefur <zash@zash.se>
parents: 12889
diff changeset
180 end)
db30ffbf2090 net.http.parser: Reject overlarge header section earlier
Kim Alvefur <zash@zash.se>
parents: 12889
diff changeset
181 local error_cb = spy.new(function()
db30ffbf2090 net.http.parser: Reject overlarge header section earlier
Kim Alvefur <zash@zash.se>
parents: 12889
diff changeset
182 finished = true;
db30ffbf2090 net.http.parser: Reject overlarge header section earlier
Kim Alvefur <zash@zash.se>
parents: 12889
diff changeset
183 end)
db30ffbf2090 net.http.parser: Reject overlarge header section earlier
Kim Alvefur <zash@zash.se>
parents: 12889
diff changeset
184 local parser = http_parser.new(success_cb, error_cb, "server", function()
db30ffbf2090 net.http.parser: Reject overlarge header section earlier
Kim Alvefur <zash@zash.se>
parents: 12889
diff changeset
185 return { head_size_limit = 1024; body_size_limit = 1024; buffer_size_limit = 2048 };
db30ffbf2090 net.http.parser: Reject overlarge header section earlier
Kim Alvefur <zash@zash.se>
parents: 12889
diff changeset
186 end)
db30ffbf2090 net.http.parser: Reject overlarge header section earlier
Kim Alvefur <zash@zash.se>
parents: 12889
diff changeset
187 parser:feed("GET / HTTP/1.1\r\n");
db30ffbf2090 net.http.parser: Reject overlarge header section earlier
Kim Alvefur <zash@zash.se>
parents: 12889
diff changeset
188 for i = 1, 64 do -- * header line > buffer_size_limit
db30ffbf2090 net.http.parser: Reject overlarge header section earlier
Kim Alvefur <zash@zash.se>
parents: 12889
diff changeset
189 parser:feed(string.format("Header-%04d: Yet-AnotherValue\r\n", i));
db30ffbf2090 net.http.parser: Reject overlarge header section earlier
Kim Alvefur <zash@zash.se>
parents: 12889
diff changeset
190 if finished then
db30ffbf2090 net.http.parser: Reject overlarge header section earlier
Kim Alvefur <zash@zash.se>
parents: 12889
diff changeset
191 -- should hit an error around half-way
db30ffbf2090 net.http.parser: Reject overlarge header section earlier
Kim Alvefur <zash@zash.se>
parents: 12889
diff changeset
192 break
db30ffbf2090 net.http.parser: Reject overlarge header section earlier
Kim Alvefur <zash@zash.se>
parents: 12889
diff changeset
193 end
db30ffbf2090 net.http.parser: Reject overlarge header section earlier
Kim Alvefur <zash@zash.se>
parents: 12889
diff changeset
194 end
db30ffbf2090 net.http.parser: Reject overlarge header section earlier
Kim Alvefur <zash@zash.se>
parents: 12889
diff changeset
195 if not finished then
db30ffbf2090 net.http.parser: Reject overlarge header section earlier
Kim Alvefur <zash@zash.se>
parents: 12889
diff changeset
196 parser:feed("\r\n")
db30ffbf2090 net.http.parser: Reject overlarge header section earlier
Kim Alvefur <zash@zash.se>
parents: 12889
diff changeset
197 end
db30ffbf2090 net.http.parser: Reject overlarge header section earlier
Kim Alvefur <zash@zash.se>
parents: 12889
diff changeset
198 assert.spy(success_cb).was_called(0);
db30ffbf2090 net.http.parser: Reject overlarge header section earlier
Kim Alvefur <zash@zash.se>
parents: 12889
diff changeset
199 assert.spy(error_cb).was_called(1);
db30ffbf2090 net.http.parser: Reject overlarge header section earlier
Kim Alvefur <zash@zash.se>
parents: 12889
diff changeset
200 assert.spy(error_cb).was_called_with("header-too-large");
db30ffbf2090 net.http.parser: Reject overlarge header section earlier
Kim Alvefur <zash@zash.se>
parents: 12889
diff changeset
201 end)
8236
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
202 end);
11030
388f599f66d1 net.http.parser: Add failing test for (large?) chunk-encoded responses
Matthew Wild <mwild1@gmail.com>
parents: 11021
diff changeset
203
11032
28de68414750 net.http.parser: Switch tests so that CRLF conversion of input data is optional
Matthew Wild <mwild1@gmail.com>
parents: 11031
diff changeset
204 it("should handle large chunked responses", function ()
11031
57739c591a8c net.http.parser: Fix incorrect path in test
Matthew Wild <mwild1@gmail.com>
parents: 11030
diff changeset
205 local data = io.open("spec/inputs/http/httpstream-chunked-test.txt", "rb"):read("*a");
11030
388f599f66d1 net.http.parser: Add failing test for (large?) chunk-encoded responses
Matthew Wild <mwild1@gmail.com>
parents: 11021
diff changeset
206
388f599f66d1 net.http.parser: Add failing test for (large?) chunk-encoded responses
Matthew Wild <mwild1@gmail.com>
parents: 11021
diff changeset
207 -- Just a sanity check... text editors and things may mess with line endings, etc.
388f599f66d1 net.http.parser: Add failing test for (large?) chunk-encoded responses
Matthew Wild <mwild1@gmail.com>
parents: 11021
diff changeset
208 assert.equal("25930f021785ae14053a322c2dbc1897c3769720", sha1(data, true), "test data malformed");
388f599f66d1 net.http.parser: Add failing test for (large?) chunk-encoded responses
Matthew Wild <mwild1@gmail.com>
parents: 11021
diff changeset
209
388f599f66d1 net.http.parser: Add failing test for (large?) chunk-encoded responses
Matthew Wild <mwild1@gmail.com>
parents: 11021
diff changeset
210 test_stream(data, {
12882
9ed628635dc6 net.http.parser: Improve handling of responses without content-length
Matthew Wild <mwild1@gmail.com>
parents: 11033
diff changeset
211 body = string.rep("~", 11085), count = 3;
11030
388f599f66d1 net.http.parser: Add failing test for (large?) chunk-encoded responses
Matthew Wild <mwild1@gmail.com>
parents: 11021
diff changeset
212 });
388f599f66d1 net.http.parser: Add failing test for (large?) chunk-encoded responses
Matthew Wild <mwild1@gmail.com>
parents: 11021
diff changeset
213 end);
8236
4878e4159e12 Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
214 end);