ruby-ajp 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/COPYING +504 -0
- data/Install.en +231 -0
- data/Install.ja +250 -0
- data/NEWS.en +13 -0
- data/NEWS.ja +12 -0
- data/README.en +56 -0
- data/README.ja +54 -0
- data/Rakefile +24 -0
- data/example/dump-server.rb +68 -0
- data/example/error-server.rb +13 -0
- data/example/hello-server.rb +18 -0
- data/lib/net/ajp13.rb +815 -0
- data/lib/net/ajp13client.rb +361 -0
- data/lib/net/ajp13server.rb +430 -0
- data/ruby-ajp.gemspec +27 -0
- data/setup.rb +1585 -0
- data/test/net/data/ajp13request-data.1 +0 -0
- data/test/net/data/ajp13response-header.1 +0 -0
- data/test/net/data/ajp13response-webdav.1 +0 -0
- data/test/net/data/ajp13response-webdav.2 +0 -0
- data/test/net/data/rand +0 -0
- data/test/net/test_ajp13client.rb +353 -0
- data/test/net/test_ajp13packet.rb +320 -0
- data/test/net/test_ajp13request.rb +177 -0
- data/test/net/test_ajp13response.rb +162 -0
- data/test/net/test_ajp13server.rb +548 -0
- metadata +73 -0
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/test/net/data/rand
ADDED
Binary file
|
@@ -0,0 +1,353 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.dirname(__FILE__) + '/../../lib/net/ajp13client'
|
3
|
+
|
4
|
+
class Net::AJP13::ClientTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
begin
|
7
|
+
sock = TCPSocket.new('localhost', 8009)
|
8
|
+
rescue
|
9
|
+
warn "#{__FILE__}:#{__LINE__}: This test case requires that" +
|
10
|
+
" a servlet container is listening localhost:8009." +
|
11
|
+
" Almost all tests in #{self.class} will be ignored."
|
12
|
+
@ignored = true
|
13
|
+
else
|
14
|
+
sock.close
|
15
|
+
end
|
16
|
+
@c = Net::AJP13::Client.new('localhost')
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_new
|
20
|
+
assert_equal 'localhost', @c.address
|
21
|
+
assert_equal 8009, @c.port
|
22
|
+
assert !@c.started?
|
23
|
+
assert !@c.assigned?
|
24
|
+
assert !@c.idle?
|
25
|
+
assert_nil @c.state
|
26
|
+
assert_kind_of Integer, @c.open_timeout
|
27
|
+
assert_kind_of Integer, @c.read_timeout
|
28
|
+
assert_kind_of Integer, @c.write_timeout
|
29
|
+
|
30
|
+
c = Net::AJP13::Client.new('localhost', 9008)
|
31
|
+
assert_equal 'localhost', c.address
|
32
|
+
assert_equal 9008, c.port
|
33
|
+
assert !c.started?
|
34
|
+
assert !c.assigned?
|
35
|
+
assert !c.idle?
|
36
|
+
assert_nil c.state
|
37
|
+
|
38
|
+
# Nothing raised because client does not try to connect until #start()ing.
|
39
|
+
assert_nothing_raised {
|
40
|
+
c = Net::AJP13::Client.new('test.invalid') # unresolvable by RFC2026
|
41
|
+
}
|
42
|
+
assert_equal 'test.invalid', c.address
|
43
|
+
assert_equal 8009, c.port
|
44
|
+
assert !c.started?
|
45
|
+
assert !c.assigned?
|
46
|
+
assert !c.idle?
|
47
|
+
assert_nil c.state
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_start_finish
|
51
|
+
return if @ignored
|
52
|
+
|
53
|
+
assert_nothing_raised { @c.start }
|
54
|
+
assert @c.started?
|
55
|
+
assert @c.idle?
|
56
|
+
assert !@c.assigned?
|
57
|
+
assert_equal :idle, @c.state
|
58
|
+
|
59
|
+
assert_nothing_raised { @c.finish }
|
60
|
+
assert !@c.started?
|
61
|
+
assert !@c.assigned?
|
62
|
+
assert !@c.idle?
|
63
|
+
assert_nil @c.state
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_finish
|
67
|
+
assert_raise(Net::AJP13::AJPStateError) { @c.finish }
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_start_with_block
|
71
|
+
return if @ignored
|
72
|
+
|
73
|
+
expected = Object.new
|
74
|
+
retval = @c.start { |c|
|
75
|
+
assert_same @c, c
|
76
|
+
assert @c.started?
|
77
|
+
assert @c.idle?
|
78
|
+
assert !@c.assigned?
|
79
|
+
assert_equal :idle, @c.state
|
80
|
+
|
81
|
+
expected
|
82
|
+
}
|
83
|
+
assert_same expected, retval
|
84
|
+
|
85
|
+
assert !@c.started?
|
86
|
+
assert !@c.assigned?
|
87
|
+
assert !@c.idle?
|
88
|
+
assert_nil @c.state
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_start_with_block_on_raised
|
92
|
+
return if @ignored
|
93
|
+
|
94
|
+
assert_raise(RuntimeError, 'Error on connection opened') {
|
95
|
+
@c.start { |c|
|
96
|
+
assert_same @c, c
|
97
|
+
assert @c.started?
|
98
|
+
assert @c.idle?
|
99
|
+
assert !@c.assigned?
|
100
|
+
assert_equal :idle, @c.state
|
101
|
+
|
102
|
+
raise 'Error on connection opened'
|
103
|
+
}
|
104
|
+
}
|
105
|
+
assert !@c.started?
|
106
|
+
assert !@c.assigned?
|
107
|
+
assert !@c.idle?
|
108
|
+
assert_nil @c.state
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_finish_only_once
|
112
|
+
return if @ignored
|
113
|
+
|
114
|
+
class << @c
|
115
|
+
alias :orig_finish :finish
|
116
|
+
def finish
|
117
|
+
@finish_count ||= 0
|
118
|
+
@finish_count += 1
|
119
|
+
orig_finish
|
120
|
+
end
|
121
|
+
attr :finish_count
|
122
|
+
end
|
123
|
+
@c.start { |c|
|
124
|
+
assert @c.started?
|
125
|
+
assert @c.idle?
|
126
|
+
assert !@c.assigned?
|
127
|
+
|
128
|
+
c.finish
|
129
|
+
|
130
|
+
assert !@c.started?
|
131
|
+
assert !@c.idle?
|
132
|
+
assert !@c.assigned?
|
133
|
+
}
|
134
|
+
assert_equal 1, @c.finish_count
|
135
|
+
assert !@c.started?
|
136
|
+
assert !@c.idle?
|
137
|
+
assert !@c.assigned?
|
138
|
+
end
|
139
|
+
|
140
|
+
|
141
|
+
def test_restart
|
142
|
+
return if @ignored
|
143
|
+
|
144
|
+
class << @c
|
145
|
+
alias :orig_finish :finish
|
146
|
+
def finish
|
147
|
+
@finish_count ||= 0
|
148
|
+
@finish_count += 1
|
149
|
+
orig_finish
|
150
|
+
end
|
151
|
+
attr :finish_count
|
152
|
+
end
|
153
|
+
@c.start { |c|
|
154
|
+
assert @c.started?
|
155
|
+
assert @c.idle?
|
156
|
+
assert !@c.assigned?
|
157
|
+
|
158
|
+
c.finish
|
159
|
+
|
160
|
+
assert !@c.started?
|
161
|
+
assert !@c.idle?
|
162
|
+
assert !@c.assigned?
|
163
|
+
|
164
|
+
c.start
|
165
|
+
|
166
|
+
assert @c.started?
|
167
|
+
assert @c.idle?
|
168
|
+
assert !@c.assigned?
|
169
|
+
}
|
170
|
+
assert_equal 2, @c.finish_count
|
171
|
+
|
172
|
+
assert !@c.started?
|
173
|
+
assert !@c.assigned?
|
174
|
+
assert !@c.idle?
|
175
|
+
end
|
176
|
+
|
177
|
+
def test_class_start
|
178
|
+
return if @ignored
|
179
|
+
|
180
|
+
c = Net::AJP13::Client.start('localhost')
|
181
|
+
begin
|
182
|
+
assert_equal 'localhost', c.address
|
183
|
+
assert_equal 8009, c.port
|
184
|
+
assert c.started?
|
185
|
+
assert c.idle?
|
186
|
+
return if @ignored
|
187
|
+
return if @ignored
|
188
|
+
|
189
|
+
|
190
|
+
assert !c.assigned?
|
191
|
+
assert_equal :idle, c.state
|
192
|
+
ensure
|
193
|
+
c.finish
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
def test_class_start_with_block
|
198
|
+
return if @ignored
|
199
|
+
|
200
|
+
created_conn = nil
|
201
|
+
expected = Object.new
|
202
|
+
retval = Net::AJP13::Client.start('localhost') { |c|
|
203
|
+
assert_equal 'localhost', c.address
|
204
|
+
assert_equal 8009, c.port
|
205
|
+
assert c.started?
|
206
|
+
assert c.idle?
|
207
|
+
assert !c.assigned?
|
208
|
+
assert_equal :idle, c.state
|
209
|
+
|
210
|
+
created_conn = c
|
211
|
+
expected
|
212
|
+
}
|
213
|
+
assert_same expected, retval
|
214
|
+
|
215
|
+
assert !created_conn.started?
|
216
|
+
assert !created_conn.assigned?
|
217
|
+
assert !created_conn.idle?
|
218
|
+
assert_nil created_conn.state
|
219
|
+
end
|
220
|
+
|
221
|
+
def test_ask_to_shutdown
|
222
|
+
return if @ignored
|
223
|
+
|
224
|
+
@c.start { |conn|
|
225
|
+
assert conn.started?
|
226
|
+
assert conn.idle?
|
227
|
+
assert !conn.assigned?
|
228
|
+
|
229
|
+
assert_nothing_raised { conn.ask_to_shutdown }
|
230
|
+
|
231
|
+
assert conn.started?
|
232
|
+
assert conn.idle?
|
233
|
+
assert !conn.assigned?
|
234
|
+
}
|
235
|
+
end
|
236
|
+
|
237
|
+
def test_ping
|
238
|
+
return if @ignored
|
239
|
+
|
240
|
+
@c.start { |conn|
|
241
|
+
assert conn.started?
|
242
|
+
assert conn.idle?
|
243
|
+
assert !conn.assigned?
|
244
|
+
|
245
|
+
conn.ping
|
246
|
+
|
247
|
+
assert conn.started?
|
248
|
+
assert conn.idle?
|
249
|
+
assert !conn.assigned?
|
250
|
+
}
|
251
|
+
end
|
252
|
+
|
253
|
+
def test_request
|
254
|
+
return if @ignored
|
255
|
+
|
256
|
+
req = Object.new
|
257
|
+
class << req
|
258
|
+
def send_to(io)
|
259
|
+
io.write "" +
|
260
|
+
"\x12\x34\x00\x35" + # signature length
|
261
|
+
"\x02\x03" + # FORWARD_REQUEST HEAD
|
262
|
+
"\x00\x08HTTP/1.0\x00" + # protocol: HTTP/1.0
|
263
|
+
"\x00\x01/\x00" + # req_uri: /
|
264
|
+
"\x00\x09127.0.0.1\x00" + # remote_addr: 127.0.0.1
|
265
|
+
"\xFF\xFF" + # remote_host: nil
|
266
|
+
"\xFF\xFF" + # server_name: nil
|
267
|
+
"\x00\x50" + # server_port: 80
|
268
|
+
"\x00" + # is_ssl : false
|
269
|
+
"\x00\x01" + # num_headers = 1
|
270
|
+
"\xA0\x0B" + # Host:
|
271
|
+
"\x00\x09localhost\x00" + # localhost
|
272
|
+
"\xFF" # TERMINATOR
|
273
|
+
end
|
274
|
+
def method_missing(*args)
|
275
|
+
nil
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
@c.start { |conn|
|
280
|
+
assert conn.started?
|
281
|
+
assert conn.idle?
|
282
|
+
assert !conn.assigned?
|
283
|
+
|
284
|
+
res = conn.request(req)
|
285
|
+
|
286
|
+
assert conn.started?
|
287
|
+
assert conn.idle?
|
288
|
+
assert !conn.assigned?
|
289
|
+
}
|
290
|
+
end
|
291
|
+
|
292
|
+
def test_request_with_body
|
293
|
+
return if @ignored
|
294
|
+
|
295
|
+
req = Net::AJP13::PostRequest.new('/index.jsp')
|
296
|
+
req.body = (['a=1'] * 10 * 1024).join('&')
|
297
|
+
@c.start { |conn|
|
298
|
+
assert conn.started?
|
299
|
+
assert conn.idle?
|
300
|
+
assert !conn.assigned?
|
301
|
+
|
302
|
+
res = conn.request(req)
|
303
|
+
|
304
|
+
assert conn.started?
|
305
|
+
assert conn.idle?
|
306
|
+
assert !conn.assigned?
|
307
|
+
}
|
308
|
+
end
|
309
|
+
|
310
|
+
def test_request_with_block
|
311
|
+
return if @ignored
|
312
|
+
|
313
|
+
req = Net::AJP13::PostRequest.new('/index.jsp')
|
314
|
+
req.body = (['a=1'] * 10 * 1024).join('&')
|
315
|
+
@c.start { |conn|
|
316
|
+
assert conn.started?
|
317
|
+
assert conn.idle?
|
318
|
+
assert !conn.assigned?
|
319
|
+
|
320
|
+
body = ''
|
321
|
+
res = conn.request(req){ |frag|
|
322
|
+
assert conn.started?
|
323
|
+
assert !conn.idle?
|
324
|
+
assert conn.assigned?
|
325
|
+
assert_kind_of String, frag
|
326
|
+
body << frag
|
327
|
+
}
|
328
|
+
assert_nil res.body
|
329
|
+
assert body.length > 0
|
330
|
+
|
331
|
+
assert conn.started?
|
332
|
+
assert conn.idle?
|
333
|
+
assert !conn.assigned?
|
334
|
+
}
|
335
|
+
end
|
336
|
+
|
337
|
+
def test_get
|
338
|
+
return if @ignored
|
339
|
+
|
340
|
+
@c.start { |conn|
|
341
|
+
assert conn.started?
|
342
|
+
assert conn.idle?
|
343
|
+
assert !conn.assigned?
|
344
|
+
|
345
|
+
res = conn.get('/', 'User-Agent' => "Ruby/AJP #{__FILE__}")
|
346
|
+
assert res.body.length > 0
|
347
|
+
|
348
|
+
assert conn.started?
|
349
|
+
assert conn.idle?
|
350
|
+
assert !conn.assigned?
|
351
|
+
}
|
352
|
+
end
|
353
|
+
end
|
@@ -0,0 +1,320 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'stringio'
|
3
|
+
require File.dirname(__FILE__) + '/../../lib/net/ajp13'
|
4
|
+
|
5
|
+
class Net::AJP13::PacketTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
@packet = Net::AJP13::Packet.new
|
8
|
+
end
|
9
|
+
def test_direction
|
10
|
+
assert_nil @packet.direction
|
11
|
+
|
12
|
+
@packet.direction = :to_app
|
13
|
+
assert_equal :to_app, @packet.direction
|
14
|
+
|
15
|
+
@packet.direction = :from_app
|
16
|
+
assert_equal :from_app, @packet.direction
|
17
|
+
|
18
|
+
assert_raise(ArgumentError) { @packet.direction = :something_wrong }
|
19
|
+
assert_raise(ArgumentError) { @packet.direction = 'to_app' }
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_length
|
23
|
+
assert_equal 0, @packet.length
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_from_io
|
27
|
+
data = StringIO.new("\x41\x42\x00\x02\x05\x00") # AJP13_END_RESPONSE packet
|
28
|
+
assert_nothing_raised { Net::AJP13::Packet.from_io(data) }
|
29
|
+
assert 4, data.pos
|
30
|
+
|
31
|
+
data = StringIO.new("\x12\x34\x00\x01\x0A") # AJP13_CPING
|
32
|
+
assert_nothing_raised { Net::AJP13::Packet.from_io(data) }
|
33
|
+
assert 4, data.pos
|
34
|
+
|
35
|
+
# packet with unrecognized header
|
36
|
+
data = StringIO.new("\x63\x23\x00\x00\x00\x00\x00")
|
37
|
+
assert_raise(Net::AJP13::AJPPacketError) { Net::AJP13::Packet.from_io(data) }
|
38
|
+
|
39
|
+
# packet with mismatched length
|
40
|
+
data = StringIO.new("\x12\x34\x00\x010\x00\x00\x00")
|
41
|
+
# nothing raised until Packet#read_* called
|
42
|
+
assert_nothing_raised { Net::AJP13::Packet.from_io(data) }
|
43
|
+
assert 4, data.pos
|
44
|
+
|
45
|
+
data = StringIO.new("\x12\x34\x00") # packet with imcomplete length field
|
46
|
+
assert_raise(Net::AJP13::AJPPacketError) { Net::AJP13::Packet.from_io(data) }
|
47
|
+
assert 4, data.pos
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_send_to
|
51
|
+
io = StringIO.new
|
52
|
+
assert_raise(Net::AJP13::AJPPacketError, 'Packet direction not specified') {
|
53
|
+
@packet.send_to(io)
|
54
|
+
}
|
55
|
+
|
56
|
+
@packet.direction = :to_app
|
57
|
+
@packet.send_to(io)
|
58
|
+
io.rewind
|
59
|
+
assert_equal "\x12\x34\x00\x00", io.read
|
60
|
+
|
61
|
+
io = StringIO.new
|
62
|
+
@packet.direction = :from_app
|
63
|
+
@packet.send_to(io)
|
64
|
+
io.rewind
|
65
|
+
assert_equal "\x41\x42\x00\x00", io.read
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_append_byte
|
69
|
+
@packet.direction = :from_app
|
70
|
+
@packet.append_byte 0x13
|
71
|
+
@packet.append_byte 0x35
|
72
|
+
assert_raise(ArgumentError) { @packet.append_byte 0x100 }
|
73
|
+
assert_raise(ArgumentError) { @packet.append_byte 0x3400 }
|
74
|
+
|
75
|
+
io = StringIO.new
|
76
|
+
@packet.send_to(io)
|
77
|
+
io.rewind
|
78
|
+
assert_equal "\x41\x42\x00\x02\x13\x35", io.read
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_append_bytes
|
82
|
+
@packet.direction = :from_app
|
83
|
+
@packet.append_bytes "abcdefg\x00\x0C\x0A123\x00"
|
84
|
+
@packet.append_bytes "\x12\x6A"
|
85
|
+
|
86
|
+
io = StringIO.new
|
87
|
+
@packet.send_to(io)
|
88
|
+
io.rewind
|
89
|
+
assert_equal "\x41\x42\x00\x10abcdefg\x00\x0C\x0A123\x00\x12\x6A", io.read
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_append_boolean
|
93
|
+
@packet.direction = :from_app
|
94
|
+
@packet.append_boolean true
|
95
|
+
@packet.append_boolean false
|
96
|
+
@packet.append_boolean nil
|
97
|
+
@packet.append_boolean 0
|
98
|
+
@packet.append_boolean ""
|
99
|
+
@packet.append_boolean "0"
|
100
|
+
@packet.append_boolean "nil"
|
101
|
+
@packet.append_boolean :nil
|
102
|
+
@packet.append_boolean "asdf"
|
103
|
+
@packet.append_boolean nil
|
104
|
+
|
105
|
+
io = StringIO.new
|
106
|
+
@packet.send_to(io)
|
107
|
+
io.rewind
|
108
|
+
assert_equal "\x41\x42\x00\x0A\x01\x00\x00\x01\x01\x01\x01\x01\x01\x00",
|
109
|
+
io.read
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_append_integer
|
113
|
+
@packet.direction = :from_app
|
114
|
+
@packet.append_integer 0x6789
|
115
|
+
@packet.append_integer 0xAB01
|
116
|
+
assert_raise(ArgumentError) { @packet.append_integer 0x10000 }
|
117
|
+
assert_raise(ArgumentError) { @packet.append_integer 0xFF0000 }
|
118
|
+
|
119
|
+
io = StringIO.new
|
120
|
+
@packet.send_to(io)
|
121
|
+
io.rewind
|
122
|
+
assert_equal "\x41\x42\x00\x04\x67\x89\xAB\x01", io.read
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_append_string
|
126
|
+
@packet.direction = :from_app
|
127
|
+
@packet.append_string "test str"
|
128
|
+
@packet.append_string "string including NUL(\x00) character"
|
129
|
+
@packet.append_string "string ending with NUL\x00"
|
130
|
+
@packet.append_string "more string"
|
131
|
+
|
132
|
+
io = StringIO.new
|
133
|
+
@packet.send_to(io)
|
134
|
+
io.rewind
|
135
|
+
assert_equal "" +
|
136
|
+
"\x41\x42\x00\x57" +
|
137
|
+
"\x00\x08test str\x00" +
|
138
|
+
"\x00\x21string including NUL(\x00) character\x00" +
|
139
|
+
"\x00\x17string ending with NUL\x00\x00" +
|
140
|
+
"\x00\x0Bmore string\x00",
|
141
|
+
io.read
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_eof
|
145
|
+
data = "\x12\x34\x00\x00"
|
146
|
+
packet = Net::AJP13::Packet.from_io(StringIO.new(data))
|
147
|
+
assert packet.eof?
|
148
|
+
|
149
|
+
data = "\x12\x34\x00\x03\x00\xAF\x00"
|
150
|
+
packet = Net::AJP13::Packet.from_io(StringIO.new(data))
|
151
|
+
assert !packet.eof?
|
152
|
+
packet.read_integer; packet.read_byte
|
153
|
+
assert packet.eof?
|
154
|
+
|
155
|
+
data = "\x12\x34\x00\x03\x00\xAF\x00" +
|
156
|
+
"extra bytes"
|
157
|
+
packet = Net::AJP13::Packet.from_io(StringIO.new(data))
|
158
|
+
assert !packet.eof?
|
159
|
+
packet.read_integer; packet.read_byte
|
160
|
+
assert packet.eof?
|
161
|
+
end
|
162
|
+
|
163
|
+
|
164
|
+
def test_read_byte
|
165
|
+
data = "\x12\x34\x00\x08\x12\x34\x56\x78\x9A\xBC\xDE\xF0" +
|
166
|
+
"extra bytes"
|
167
|
+
packet = Net::AJP13::Packet.from_io(StringIO.new(data))
|
168
|
+
assert !packet.eof?
|
169
|
+
assert_equal 0x12, packet.read_byte
|
170
|
+
assert !packet.eof?
|
171
|
+
assert_equal 0x34, packet.read_byte
|
172
|
+
assert !packet.eof?
|
173
|
+
assert_equal 0x56, packet.read_byte
|
174
|
+
assert !packet.eof?
|
175
|
+
assert_equal 0x78, packet.read_byte
|
176
|
+
assert !packet.eof?
|
177
|
+
assert_equal 0x9A, packet.read_byte
|
178
|
+
assert !packet.eof?
|
179
|
+
assert_equal 0xBC, packet.read_byte
|
180
|
+
assert !packet.eof?
|
181
|
+
assert_equal 0xDE, packet.read_byte
|
182
|
+
assert !packet.eof?
|
183
|
+
assert_equal 0xF0, packet.read_byte
|
184
|
+
assert packet.eof?
|
185
|
+
assert_nil packet.read_byte
|
186
|
+
assert_nil packet.read_byte
|
187
|
+
assert_nil packet.read_byte
|
188
|
+
end
|
189
|
+
|
190
|
+
def test_read_bytes
|
191
|
+
data = "\x12\x34\x00\x08\xFE\xDC\xBA\x98\x76\x54\x32\x10"
|
192
|
+
"extra bytes"
|
193
|
+
data.freeze
|
194
|
+
|
195
|
+
packet = Net::AJP13::Packet.from_io(StringIO.new(data))
|
196
|
+
assert !packet.eof?
|
197
|
+
assert_equal "\xFE\xDC\xBA\x98\x76\x54\x32\x10", packet.read_bytes(8)
|
198
|
+
assert packet.eof?
|
199
|
+
assert_nil packet.read_bytes(3)
|
200
|
+
assert_nil packet.read_byte
|
201
|
+
assert_nil packet.read_bytes(10)
|
202
|
+
|
203
|
+
packet = Net::AJP13::Packet.from_io(StringIO.new(data))
|
204
|
+
assert !packet.eof?
|
205
|
+
assert_equal "\xFE\xDC\xBA\x98\x76\x54\x32\x10", packet.read_bytes(100)
|
206
|
+
assert packet.eof?
|
207
|
+
assert_nil packet.read_bytes(3)
|
208
|
+
assert_nil packet.read_byte
|
209
|
+
assert_nil packet.read_bytes(10)
|
210
|
+
|
211
|
+
packet = Net::AJP13::Packet.from_io(StringIO.new(data))
|
212
|
+
assert !packet.eof?
|
213
|
+
assert_equal "\xFE\xDC\xBA", packet.read_bytes(3)
|
214
|
+
assert !packet.eof?
|
215
|
+
assert_equal "\x98\x76\x54", packet.read_bytes(3)
|
216
|
+
assert !packet.eof?
|
217
|
+
assert_equal "\x32\x10", packet.read_bytes(3)
|
218
|
+
assert packet.eof?
|
219
|
+
assert_nil packet.read_bytes(3)
|
220
|
+
assert_nil packet.read_byte
|
221
|
+
assert_nil packet.read_bytes(10)
|
222
|
+
end
|
223
|
+
|
224
|
+
def test_read_boolean
|
225
|
+
data = "\x41\x42\x00\x05\x01\x01\x00\x01\x03" + "extra bytes"
|
226
|
+
|
227
|
+
packet = Net::AJP13::Packet.from_io(StringIO.new(data))
|
228
|
+
assert !packet.eof?
|
229
|
+
assert_same true, packet.read_boolean
|
230
|
+
assert !packet.eof?
|
231
|
+
assert_same true, packet.read_boolean
|
232
|
+
assert !packet.eof?
|
233
|
+
assert_same false, packet.read_boolean
|
234
|
+
assert !packet.eof?
|
235
|
+
assert_same true, packet.read_boolean
|
236
|
+
assert !packet.eof?
|
237
|
+
assert_raise(Net::AJP13::AJPPacketError) { packet.read_boolean }
|
238
|
+
assert packet.eof?
|
239
|
+
assert_nil packet.read_boolean
|
240
|
+
assert_nil packet.read_bytes(10)
|
241
|
+
assert_nil packet.read_byte
|
242
|
+
end
|
243
|
+
|
244
|
+
def test_read_integer
|
245
|
+
data = "\x41\x42\x00\x0B\x00\x01\xCB\x35\x00\x00\x01\x00\xFF\xFF\x00" +
|
246
|
+
"extra bytes"
|
247
|
+
data.freeze
|
248
|
+
|
249
|
+
packet = Net::AJP13::Packet.from_io(StringIO.new(data))
|
250
|
+
assert !packet.eof?
|
251
|
+
assert_equal 0x0001, packet.read_integer
|
252
|
+
assert !packet.eof?
|
253
|
+
assert_equal 0xCB35, packet.read_integer
|
254
|
+
assert !packet.eof?
|
255
|
+
assert_equal 0x0000, packet.read_integer
|
256
|
+
assert !packet.eof?
|
257
|
+
assert_equal 0x0100, packet.read_integer
|
258
|
+
assert !packet.eof?
|
259
|
+
assert_equal 0xFFFF, packet.read_integer
|
260
|
+
assert !packet.eof?
|
261
|
+
assert_raise(Net::AJP13::AJPPacketError, "too short to read as integer") {
|
262
|
+
packet.read_integer
|
263
|
+
}
|
264
|
+
assert !packet.eof?
|
265
|
+
assert_equal 0x00, packet.read_byte
|
266
|
+
assert packet.eof?
|
267
|
+
assert_nil packet.read_integer
|
268
|
+
end
|
269
|
+
|
270
|
+
def test_read_string
|
271
|
+
data = "" +
|
272
|
+
"\x12\x34\x00\x25" +
|
273
|
+
"\x00\x0Btest string\x00" +
|
274
|
+
"\x00\x0Fstr with NUL(\x00)\x00" +
|
275
|
+
"\xFF\xFF" + # treated as NULL string
|
276
|
+
"\x00\x00\x00" +
|
277
|
+
"some extraa bytes"
|
278
|
+
data.freeze
|
279
|
+
|
280
|
+
packet = Net::AJP13::Packet.from_io(StringIO.new(data))
|
281
|
+
assert !packet.eof?
|
282
|
+
assert_equal "test string", packet.read_string
|
283
|
+
assert !packet.eof?
|
284
|
+
assert_equal "str with NUL(\x00)", packet.read_string
|
285
|
+
assert !packet.eof?
|
286
|
+
assert_nil packet.read_string
|
287
|
+
assert !packet.eof?
|
288
|
+
assert_equal "", packet.read_string
|
289
|
+
assert packet.eof?
|
290
|
+
assert_nil packet.read_string
|
291
|
+
|
292
|
+
|
293
|
+
data = "" +
|
294
|
+
"\x41\x42\x00\x07" +
|
295
|
+
"\x00\x03str\x00" +
|
296
|
+
"\x00" + # str length incomplete8
|
297
|
+
"some extra bytes"
|
298
|
+
packet = Net::AJP13::Packet.from_io(StringIO.new(data))
|
299
|
+
assert !packet.eof?
|
300
|
+
assert_equal "str", packet.read_string
|
301
|
+
assert_raise(Net::AJP13::AJPPacketError) { packet.read_string }
|
302
|
+
|
303
|
+
data = "" +
|
304
|
+
"\x12\x34\x00\x08" +
|
305
|
+
"\x00\x0712345\x00" + # str length too large
|
306
|
+
"some extra bytes"
|
307
|
+
packet = Net::AJP13::Packet.from_io(StringIO.new(data))
|
308
|
+
assert !packet.eof?
|
309
|
+
assert_raise(Net::AJP13::AJPPacketError) { packet.read_string }
|
310
|
+
|
311
|
+
data = "" +
|
312
|
+
"\x41\x42\x00\x0B" +
|
313
|
+
"\x00\x08ABCDabcd" + # missing NUL
|
314
|
+
"some extra bytes"
|
315
|
+
packet = Net::AJP13::Packet.from_io(StringIO.new(data))
|
316
|
+
assert !packet.eof?
|
317
|
+
assert_raise(Net::AJP13::AJPPacketError) { packet.read_string }
|
318
|
+
assert packet.eof?
|
319
|
+
end
|
320
|
+
end
|