ruby-ajp 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,548 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'stringio'
|
3
|
+
require File.dirname(__FILE__) + '/../../lib/net/ajp13server'
|
4
|
+
|
5
|
+
class Net::AJP13::Server
|
6
|
+
unless method_defined?(:fcall)
|
7
|
+
alias :fcall :__send__
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class Net::AJP13::Server::BodyInputTest < Test::Unit::TestCase
|
12
|
+
CONTENTS = [
|
13
|
+
# line <-> chunk packet
|
14
|
+
"\xf8\xef\x2e\x7e\x1e\x76\x2d\x63\x67\x6c",
|
15
|
+
"\xea\xa3\x6c\xfd\x32\x6e\x22\x49\xc6\x58",
|
16
|
+
"\x13\x23\x45\x72\xc2\x5b\x08\x2d\xd0\x90",
|
17
|
+
"\x91\x8e\xcc\x80\x66\x74\x6d\x61\xd8\x54",
|
18
|
+
"\xea\x6e\x27\xc4\x37\xc1\x15\xb5\x64\x73",
|
19
|
+
"\x2f\x77\x02\x77\x47\xab\x79\x9b\x91\xc8",
|
20
|
+
"\x97\x39\x12\xbb\xbf\x7b\x1c\xe3\x74\xd0",
|
21
|
+
"\x91\x7d\x47\x78\x9e\xc4\xfa\xd6\x05\x60",
|
22
|
+
"\xbb\x31\xe7\xb5\x0f\xb0\xb8\xd1\xaf\xe3",
|
23
|
+
"\x63\xb0\x27\x3e\x08\x45\x5e\x57\xbf\xab",
|
24
|
+
].freeze # 100 bytes
|
25
|
+
|
26
|
+
class MockSocket
|
27
|
+
def initialize(contents)
|
28
|
+
@bodies = (
|
29
|
+
contents.map{|c| "\x12\x34#{[c.length].pack('n')}" + c } <<
|
30
|
+
"\x12\x34\x00\x00"
|
31
|
+
).map {|str| StringIO.new(str)}
|
32
|
+
@write_buf = ''
|
33
|
+
@written_packets = []
|
34
|
+
end
|
35
|
+
attr_reader :written_packets
|
36
|
+
|
37
|
+
def read(length)
|
38
|
+
io = @bodies[@io_index ||= 0]
|
39
|
+
str = io.read(length)
|
40
|
+
raise 'packet over run' if str.length != length
|
41
|
+
@io_index += 1 if io.eof?
|
42
|
+
str
|
43
|
+
end
|
44
|
+
alias :readpartial :read
|
45
|
+
|
46
|
+
def write(str)
|
47
|
+
@write_buf << str
|
48
|
+
end
|
49
|
+
|
50
|
+
def eof?
|
51
|
+
@io_index >= @bodies.length
|
52
|
+
end
|
53
|
+
def flush
|
54
|
+
@written_packets << @write_buf
|
55
|
+
@write_buf = ''
|
56
|
+
end
|
57
|
+
attr_accessor :sync
|
58
|
+
def ungetc(char)
|
59
|
+
if eof?
|
60
|
+
@io_index = @bodies.length - 1
|
61
|
+
elsif @bodies[@io_index].pos == 0
|
62
|
+
raise IOError, "can't ungetc" if @io_index == 0
|
63
|
+
@io_index -= 1
|
64
|
+
end
|
65
|
+
@bodies[@io_index].ungetc(char)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def setup
|
70
|
+
@mock_sock = MockSocket.new(CONTENTS)
|
71
|
+
@body_input = Net::AJP13::Server::BodyInput.new(@mock_sock, 100)
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_length
|
75
|
+
assert_equal 100, @body_input.length
|
76
|
+
assert_equal 100, @body_input.size
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_binmode
|
80
|
+
assert_same @body_input, @body_input.binmode
|
81
|
+
end
|
82
|
+
def test_clone
|
83
|
+
assert_raise(TypeError) { @body_input.clone }
|
84
|
+
end
|
85
|
+
def test_dup
|
86
|
+
assert_raise(TypeError) { @body_input.dup }
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_close
|
90
|
+
@body_input.close
|
91
|
+
assert_raise(IOError) { @body_input.read(1) }
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_freeze
|
95
|
+
assert !@body_input.frozen?
|
96
|
+
@body_input.freeze
|
97
|
+
assert @body_input.frozen?
|
98
|
+
assert_raise(TypeError) { @body_input.read(1) }
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_close_read
|
102
|
+
@body_input.close_read
|
103
|
+
assert_raise(IOError) { @body_input.read(1) }
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_closed?
|
107
|
+
assert !@body_input.closed?
|
108
|
+
@body_input.close
|
109
|
+
assert @body_input.closed?
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_each_byte
|
113
|
+
i = 0
|
114
|
+
@body_input.each_byte do |byte|
|
115
|
+
assert_equal CONTENTS[i/10][i%10], byte
|
116
|
+
i += 1
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_eof?
|
121
|
+
assert !@body_input.eof?
|
122
|
+
@body_input.read(100)
|
123
|
+
assert @body_input.eof?
|
124
|
+
end
|
125
|
+
def test_eof
|
126
|
+
assert !@body_input.eof
|
127
|
+
@body_input.read(37)
|
128
|
+
@body_input.read(63)
|
129
|
+
assert @body_input.eof
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_fcntl
|
133
|
+
require 'fcntl'
|
134
|
+
assert_raise(NotImplementedError){@body_input.fcntl(Fcntl::F_DUPFD)}
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_fileno
|
138
|
+
assert_nil @body_input.fileno
|
139
|
+
assert_nil @body_input.to_i
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_getc
|
143
|
+
assert_equal [], @mock_sock.written_packets
|
144
|
+
assert_equal CONTENTS[0][0], @body_input.getc
|
145
|
+
assert_equal CONTENTS[0][1], @body_input.getc
|
146
|
+
assert_equal CONTENTS[0][2], @body_input.getc
|
147
|
+
assert_equal CONTENTS[0][3], @body_input.getc
|
148
|
+
assert_equal CONTENTS[0][4], @body_input.getc
|
149
|
+
assert_equal CONTENTS[0][5], @body_input.getc
|
150
|
+
assert_equal CONTENTS[0][6], @body_input.getc
|
151
|
+
assert_equal CONTENTS[0][7], @body_input.getc
|
152
|
+
assert_equal CONTENTS[0][8], @body_input.getc
|
153
|
+
assert_equal CONTENTS[0][9], @body_input.getc
|
154
|
+
assert_equal [], @mock_sock.written_packets
|
155
|
+
|
156
|
+
assert_equal CONTENTS[1][0], @body_input.getc
|
157
|
+
assert_equal ["\x41\x42\x00\x03\x06\x00\x5A"], @mock_sock.written_packets
|
158
|
+
|
159
|
+
88.times do @body_input.getc end
|
160
|
+
|
161
|
+
assert_equal [
|
162
|
+
"\x41\x42\x00\x03\x06\x00\x5A",
|
163
|
+
"\x41\x42\x00\x03\x06\x00\x50",
|
164
|
+
"\x41\x42\x00\x03\x06\x00\x46",
|
165
|
+
"\x41\x42\x00\x03\x06\x00\x3C",
|
166
|
+
"\x41\x42\x00\x03\x06\x00\x32",
|
167
|
+
"\x41\x42\x00\x03\x06\x00\x28",
|
168
|
+
"\x41\x42\x00\x03\x06\x00\x1E",
|
169
|
+
"\x41\x42\x00\x03\x06\x00\x14",
|
170
|
+
"\x41\x42\x00\x03\x06\x00\x0A"
|
171
|
+
], @mock_sock.written_packets
|
172
|
+
|
173
|
+
assert_equal CONTENTS[9][9], @body_input.getc
|
174
|
+
assert_nil @body_input.getc
|
175
|
+
assert_equal [
|
176
|
+
"\x41\x42\x00\x03\x06\x00\x5A",
|
177
|
+
"\x41\x42\x00\x03\x06\x00\x50",
|
178
|
+
"\x41\x42\x00\x03\x06\x00\x46",
|
179
|
+
"\x41\x42\x00\x03\x06\x00\x3C",
|
180
|
+
"\x41\x42\x00\x03\x06\x00\x32",
|
181
|
+
"\x41\x42\x00\x03\x06\x00\x28",
|
182
|
+
"\x41\x42\x00\x03\x06\x00\x1E",
|
183
|
+
"\x41\x42\x00\x03\x06\x00\x14",
|
184
|
+
"\x41\x42\x00\x03\x06\x00\x0A"
|
185
|
+
], @mock_sock.written_packets
|
186
|
+
end
|
187
|
+
|
188
|
+
def test_read_all
|
189
|
+
assert !@body_input.eof?
|
190
|
+
assert_equal [], @mock_sock.written_packets
|
191
|
+
assert_equal CONTENTS.join, @body_input.read
|
192
|
+
assert @body_input.eof?
|
193
|
+
assert_equal [
|
194
|
+
"\x41\x42\x00\x03\x06\x00\x5A",
|
195
|
+
"\x41\x42\x00\x03\x06\x00\x50",
|
196
|
+
"\x41\x42\x00\x03\x06\x00\x46",
|
197
|
+
"\x41\x42\x00\x03\x06\x00\x3C",
|
198
|
+
"\x41\x42\x00\x03\x06\x00\x32",
|
199
|
+
"\x41\x42\x00\x03\x06\x00\x28",
|
200
|
+
"\x41\x42\x00\x03\x06\x00\x1E",
|
201
|
+
"\x41\x42\x00\x03\x06\x00\x14",
|
202
|
+
"\x41\x42\x00\x03\x06\x00\x0A"
|
203
|
+
], @mock_sock.written_packets
|
204
|
+
|
205
|
+
assert_equal '', @body_input.read
|
206
|
+
assert_equal [
|
207
|
+
"\x41\x42\x00\x03\x06\x00\x5A",
|
208
|
+
"\x41\x42\x00\x03\x06\x00\x50",
|
209
|
+
"\x41\x42\x00\x03\x06\x00\x46",
|
210
|
+
"\x41\x42\x00\x03\x06\x00\x3C",
|
211
|
+
"\x41\x42\x00\x03\x06\x00\x32",
|
212
|
+
"\x41\x42\x00\x03\x06\x00\x28",
|
213
|
+
"\x41\x42\x00\x03\x06\x00\x1E",
|
214
|
+
"\x41\x42\x00\x03\x06\x00\x14",
|
215
|
+
"\x41\x42\x00\x03\x06\x00\x0A"
|
216
|
+
], @mock_sock.written_packets
|
217
|
+
end
|
218
|
+
|
219
|
+
def test_read_with_length
|
220
|
+
assert_equal [], @mock_sock.written_packets
|
221
|
+
assert !@body_input.eof?
|
222
|
+
# 0...1.
|
223
|
+
assert_equal CONTENTS[0][0,1], @body_input.read(1)
|
224
|
+
assert_equal [], @mock_sock.written_packets
|
225
|
+
assert !@body_input.eof?
|
226
|
+
# 1...9
|
227
|
+
assert_equal CONTENTS[0][1,8], @body_input.read(8)
|
228
|
+
assert_equal [], @mock_sock.written_packets
|
229
|
+
assert !@body_input.eof?
|
230
|
+
# 9...53
|
231
|
+
assert_equal CONTENTS[0][9,1] + CONTENTS[1...5].join + CONTENTS[5][0,3],
|
232
|
+
@body_input.read(44)
|
233
|
+
assert !@body_input.eof?
|
234
|
+
assert_equal [
|
235
|
+
"\x41\x42\x00\x03\x06\x00\x5A",
|
236
|
+
"\x41\x42\x00\x03\x06\x00\x50",
|
237
|
+
"\x41\x42\x00\x03\x06\x00\x46",
|
238
|
+
"\x41\x42\x00\x03\x06\x00\x3C",
|
239
|
+
"\x41\x42\x00\x03\x06\x00\x32"
|
240
|
+
], @mock_sock.written_packets
|
241
|
+
# 53...60
|
242
|
+
assert_equal CONTENTS[5][3,7], @body_input.read(7)
|
243
|
+
assert !@body_input.eof?
|
244
|
+
assert_equal [
|
245
|
+
"\x41\x42\x00\x03\x06\x00\x5A",
|
246
|
+
"\x41\x42\x00\x03\x06\x00\x50",
|
247
|
+
"\x41\x42\x00\x03\x06\x00\x46",
|
248
|
+
"\x41\x42\x00\x03\x06\x00\x3C",
|
249
|
+
"\x41\x42\x00\x03\x06\x00\x32"
|
250
|
+
], @mock_sock.written_packets
|
251
|
+
# 60...70
|
252
|
+
assert_equal CONTENTS[6], @body_input.read(10)
|
253
|
+
assert !@body_input.eof?
|
254
|
+
assert_equal [
|
255
|
+
"\x41\x42\x00\x03\x06\x00\x5A",
|
256
|
+
"\x41\x42\x00\x03\x06\x00\x50",
|
257
|
+
"\x41\x42\x00\x03\x06\x00\x46",
|
258
|
+
"\x41\x42\x00\x03\x06\x00\x3C",
|
259
|
+
"\x41\x42\x00\x03\x06\x00\x32",
|
260
|
+
"\x41\x42\x00\x03\x06\x00\x28"
|
261
|
+
], @mock_sock.written_packets
|
262
|
+
# 70...81
|
263
|
+
assert_equal CONTENTS[7] + CONTENTS[8][0,1], @body_input.read(11)
|
264
|
+
assert !@body_input.eof?
|
265
|
+
assert_equal [
|
266
|
+
"\x41\x42\x00\x03\x06\x00\x5A",
|
267
|
+
"\x41\x42\x00\x03\x06\x00\x50",
|
268
|
+
"\x41\x42\x00\x03\x06\x00\x46",
|
269
|
+
"\x41\x42\x00\x03\x06\x00\x3C",
|
270
|
+
"\x41\x42\x00\x03\x06\x00\x32",
|
271
|
+
"\x41\x42\x00\x03\x06\x00\x28",
|
272
|
+
"\x41\x42\x00\x03\x06\x00\x1E",
|
273
|
+
"\x41\x42\x00\x03\x06\x00\x14"
|
274
|
+
], @mock_sock.written_packets
|
275
|
+
# 81...91
|
276
|
+
assert_equal CONTENTS[8][1,9] + CONTENTS[9][0,1], @body_input.read(10)
|
277
|
+
assert !@body_input.eof?
|
278
|
+
assert_equal [
|
279
|
+
"\x41\x42\x00\x03\x06\x00\x5A",
|
280
|
+
"\x41\x42\x00\x03\x06\x00\x50",
|
281
|
+
"\x41\x42\x00\x03\x06\x00\x46",
|
282
|
+
"\x41\x42\x00\x03\x06\x00\x3C",
|
283
|
+
"\x41\x42\x00\x03\x06\x00\x32",
|
284
|
+
"\x41\x42\x00\x03\x06\x00\x28",
|
285
|
+
"\x41\x42\x00\x03\x06\x00\x1E",
|
286
|
+
"\x41\x42\x00\x03\x06\x00\x14",
|
287
|
+
"\x41\x42\x00\x03\x06\x00\x0A"
|
288
|
+
], @mock_sock.written_packets
|
289
|
+
# 91...110(100)
|
290
|
+
assert_equal CONTENTS[9][1,9], @body_input.read(19)
|
291
|
+
assert @body_input.eof?
|
292
|
+
assert_equal [
|
293
|
+
"\x41\x42\x00\x03\x06\x00\x5A",
|
294
|
+
"\x41\x42\x00\x03\x06\x00\x50",
|
295
|
+
"\x41\x42\x00\x03\x06\x00\x46",
|
296
|
+
"\x41\x42\x00\x03\x06\x00\x3C",
|
297
|
+
"\x41\x42\x00\x03\x06\x00\x32",
|
298
|
+
"\x41\x42\x00\x03\x06\x00\x28",
|
299
|
+
"\x41\x42\x00\x03\x06\x00\x1E",
|
300
|
+
"\x41\x42\x00\x03\x06\x00\x14",
|
301
|
+
"\x41\x42\x00\x03\x06\x00\x0A"
|
302
|
+
], @mock_sock.written_packets
|
303
|
+
|
304
|
+
assert_nil @body_input.read(100000)
|
305
|
+
assert_equal "", @body_input.read
|
306
|
+
assert_equal [
|
307
|
+
"\x41\x42\x00\x03\x06\x00\x5A",
|
308
|
+
"\x41\x42\x00\x03\x06\x00\x50",
|
309
|
+
"\x41\x42\x00\x03\x06\x00\x46",
|
310
|
+
"\x41\x42\x00\x03\x06\x00\x3C",
|
311
|
+
"\x41\x42\x00\x03\x06\x00\x32",
|
312
|
+
"\x41\x42\x00\x03\x06\x00\x28",
|
313
|
+
"\x41\x42\x00\x03\x06\x00\x1E",
|
314
|
+
"\x41\x42\x00\x03\x06\x00\x14",
|
315
|
+
"\x41\x42\x00\x03\x06\x00\x0A"
|
316
|
+
], @mock_sock.written_packets
|
317
|
+
end
|
318
|
+
|
319
|
+
def test_read_with_length_and_buffer
|
320
|
+
assert !@body_input.eof?
|
321
|
+
|
322
|
+
buf = '\0' * 23
|
323
|
+
# 0...23
|
324
|
+
actual = @body_input.read(23, buf)
|
325
|
+
assert !@body_input.eof?
|
326
|
+
assert_same buf, actual
|
327
|
+
assert_equal CONTENTS[0] + CONTENTS[1] + CONTENTS[2][0,3], actual
|
328
|
+
# 23...46
|
329
|
+
actual = @body_input.read(23, buf)
|
330
|
+
assert !@body_input.eof?
|
331
|
+
assert_same buf, actual
|
332
|
+
assert_equal CONTENTS[2][3,7] + CONTENTS[3] + CONTENTS[4][0,6], actual
|
333
|
+
# 46...69
|
334
|
+
actual = @body_input.read(23, buf)
|
335
|
+
assert !@body_input.eof?
|
336
|
+
assert_same buf, actual
|
337
|
+
assert_equal CONTENTS[4][6,4] + CONTENTS[5] + CONTENTS[6][0,9], actual
|
338
|
+
# 69...92
|
339
|
+
actual = @body_input.read(23, buf)
|
340
|
+
assert !@body_input.eof?
|
341
|
+
assert_same buf, actual
|
342
|
+
assert_equal CONTENTS[6][9,1] + CONTENTS[7] +
|
343
|
+
CONTENTS[8] + CONTENTS[9][0,2], actual
|
344
|
+
# 92...115(100)
|
345
|
+
actual = @body_input.read(23, buf)
|
346
|
+
assert @body_input.eof?
|
347
|
+
assert_same buf, actual
|
348
|
+
assert_equal CONTENTS[9][2,8], actual
|
349
|
+
# 115...138 (out of range)
|
350
|
+
actual = @body_input.read(23,buf)
|
351
|
+
assert_nil actual
|
352
|
+
assert_equal "", buf
|
353
|
+
assert @body_input.eof?
|
354
|
+
|
355
|
+
assert_equal "", @body_input.read
|
356
|
+
end
|
357
|
+
|
358
|
+
def test_readchar
|
359
|
+
assert !@body_input.eof?
|
360
|
+
assert_equal CONTENTS[0][0], @body_input.readchar
|
361
|
+
assert_equal CONTENTS[0][1], @body_input.readchar
|
362
|
+
assert_equal CONTENTS[0][2], @body_input.readchar
|
363
|
+
assert_equal CONTENTS[0][3], @body_input.readchar
|
364
|
+
assert_equal CONTENTS[0][4], @body_input.readchar
|
365
|
+
assert_equal CONTENTS[0][5], @body_input.readchar
|
366
|
+
assert_equal CONTENTS[0][6], @body_input.readchar
|
367
|
+
assert_equal CONTENTS[0][7], @body_input.readchar
|
368
|
+
assert_equal CONTENTS[0][8], @body_input.readchar
|
369
|
+
assert_equal CONTENTS[0][9], @body_input.readchar
|
370
|
+
|
371
|
+
assert_equal CONTENTS[1][0], @body_input.readchar
|
372
|
+
88.times do @body_input.readchar end
|
373
|
+
assert_equal CONTENTS[9][9], @body_input.readchar
|
374
|
+
assert_raise(EOFError) { @body_input.readchar }
|
375
|
+
assert @body_input.eof?
|
376
|
+
end
|
377
|
+
|
378
|
+
def test_readline
|
379
|
+
mock_sock = MockSocket.new([
|
380
|
+
"123456789ABC\n571",
|
381
|
+
"string\nfragment\n",
|
382
|
+
"This is a long l",
|
383
|
+
"ine.\nThis is a m",
|
384
|
+
"ore more long li",
|
385
|
+
"ne.\nAnd this is ",
|
386
|
+
"the last line :P"
|
387
|
+
])
|
388
|
+
body_input = Net::AJP13::Server::BodyInput.new(mock_sock, 0x70)
|
389
|
+
assert_nil body_input.lineno
|
390
|
+
assert_equal "123456789ABC\n", body_input.readline
|
391
|
+
assert_equal 1, body_input.lineno
|
392
|
+
assert_equal "571string\n", body_input.readline
|
393
|
+
assert_equal 2, body_input.lineno
|
394
|
+
assert_equal "fragment\n", body_input.readline
|
395
|
+
assert_equal 3, body_input.lineno
|
396
|
+
assert_equal "This is a long line.\n", body_input.readline
|
397
|
+
assert_equal 4, body_input.lineno
|
398
|
+
assert_equal "This is a more more long line.\n", body_input.readline
|
399
|
+
assert_equal 5, body_input.lineno
|
400
|
+
assert_equal "And this is the last line :P", body_input.readline
|
401
|
+
assert_equal 6, body_input.lineno
|
402
|
+
end
|
403
|
+
|
404
|
+
def test_each_line
|
405
|
+
mock_sock = MockSocket.new([
|
406
|
+
"123456789ABC\n571",
|
407
|
+
"string\nfragment\n",
|
408
|
+
"This is a long l",
|
409
|
+
"ine.\nThis is a m",
|
410
|
+
"ore more long li",
|
411
|
+
"ne.\nAnd this is ",
|
412
|
+
"the last line :P"
|
413
|
+
])
|
414
|
+
body_input = Net::AJP13::Server::BodyInput.new(mock_sock, 0x70)
|
415
|
+
expected = [
|
416
|
+
"123456789ABC\n", "571string\n", "fragment\n",
|
417
|
+
"This is a long line.\n", "This is a more more long line.\n",
|
418
|
+
"And this is the last line :P"
|
419
|
+
]
|
420
|
+
|
421
|
+
i = 0
|
422
|
+
body_input.each_line do |line|
|
423
|
+
assert_equal expected[i], line
|
424
|
+
assert_equal i+1, body_input.lineno
|
425
|
+
i += 1
|
426
|
+
end
|
427
|
+
end
|
428
|
+
|
429
|
+
def test_sync
|
430
|
+
@mock_sock.sync = expected = Object.new
|
431
|
+
assert_equal expected, @body_input.sync
|
432
|
+
|
433
|
+
expected = Object.new
|
434
|
+
assert_equal expected, (@body_input.sync = expected)
|
435
|
+
assert_equal expected, @mock_sock.sync
|
436
|
+
end
|
437
|
+
|
438
|
+
def test_ungetc
|
439
|
+
c = @body_input.getc
|
440
|
+
assert_nil @body_input.ungetc(c)
|
441
|
+
assert_equal c, @body_input.getc
|
442
|
+
|
443
|
+
assert_equal CONTENTS[0][1,9], @body_input.read(9)
|
444
|
+
assert_nil @body_input.ungetc(c)
|
445
|
+
assert_equal c, @body_input.getc
|
446
|
+
|
447
|
+
assert_equal CONTENTS[1,9].join, @body_input.read(90)
|
448
|
+
assert_nil @body_input.ungetc(c)
|
449
|
+
assert_equal c, @body_input.getc
|
450
|
+
assert_nil @body_input.getc
|
451
|
+
end
|
452
|
+
end
|
453
|
+
|
454
|
+
|
455
|
+
class Net::AJP13::ServerTest < Test::Unit::TestCase
|
456
|
+
TEST_PORT = 3009
|
457
|
+
def setup
|
458
|
+
@serv = Net::AJP13::Server.new('localhost', TEST_PORT)
|
459
|
+
end
|
460
|
+
|
461
|
+
def test_new
|
462
|
+
assert_equal 'localhost', @serv.host
|
463
|
+
assert_equal TEST_PORT, @serv.service
|
464
|
+
|
465
|
+
serv = Net::AJP13::Server.new(TEST_PORT)
|
466
|
+
assert_nil serv.host
|
467
|
+
assert_equal TEST_PORT, serv.service
|
468
|
+
|
469
|
+
serv = Net::AJP13::Server.new
|
470
|
+
assert_nil serv.host
|
471
|
+
assert_equal Net::AJP13::Constants::DEFAULT_PORT, serv.service
|
472
|
+
|
473
|
+
assert_raise(ArgumentError, 'wrong number of arguments (3 for 0..2)') {
|
474
|
+
serv = Net::AJP13::Server.new 'localhost', 3009, 'extra arg'
|
475
|
+
}
|
476
|
+
end
|
477
|
+
|
478
|
+
def test_process_ping
|
479
|
+
ping = "\x12\x34\x00\x01\x0A" # CPING
|
480
|
+
io = StringIO.new(ping.dup)
|
481
|
+
@serv.fcall(:process, io)
|
482
|
+
io.pos = ping.length
|
483
|
+
assert_equal "\x41\x42\x00\x01\x09", io.read
|
484
|
+
end
|
485
|
+
|
486
|
+
def test_process_shutdown
|
487
|
+
shutdown = "\x12\x34\x00\x01\x07" # SHUTDOWN
|
488
|
+
io = StringIO.new(shutdown.dup)
|
489
|
+
def io.addr
|
490
|
+
['AF_INET', 3009, 'localhost.localdomain', '127.0.0.1']
|
491
|
+
end
|
492
|
+
def io.peeraddr
|
493
|
+
['AF_INET', 12345, 'localhost.localdomain', '127.0.0.1']
|
494
|
+
end
|
495
|
+
|
496
|
+
@serv.fcall(:process, io)
|
497
|
+
|
498
|
+
io.pos = shutdown.length
|
499
|
+
assert_equal "", io.read
|
500
|
+
end
|
501
|
+
|
502
|
+
def test_process_request
|
503
|
+
req = "" +
|
504
|
+
"\x12\x34\x00\x5c" + # payload
|
505
|
+
"\x02\x03" + # FORWARD_REQUEST HEAD
|
506
|
+
"\x00\x08HTTP/1.1\x00" + # protocol = HTTP/1.1
|
507
|
+
"\x00\x01/\x00" + # request_path = /
|
508
|
+
"\x00\x09127.0.0.1\x00" + # remote_addr = 127.0.0.1
|
509
|
+
"\x00\x09localhost\x00" + # remote_host = localhost
|
510
|
+
"\x00\x09localhost\x00" + # server_name = localhost
|
511
|
+
"\x00\x50" + # server_port = 80
|
512
|
+
"\x00" + # is_ssl = false
|
513
|
+
"\x00\x01" + # num_headers = 1
|
514
|
+
"\xA0\x0B" + # Host:
|
515
|
+
"\x00\x09localhost\0" + # localhost
|
516
|
+
"\x05" + # QUERY_STRING =
|
517
|
+
"\x00\x0Fq=something&a=1\x00"+# "q=something&a=1"
|
518
|
+
"\xFF" + # TERMINATOR
|
519
|
+
""
|
520
|
+
io = StringIO.new(req.dup)
|
521
|
+
|
522
|
+
assert_raise(Net::AJP13::Server::ProcessRequestNotImplementedError) {
|
523
|
+
@serv.fcall(:process, io)
|
524
|
+
}
|
525
|
+
|
526
|
+
io = StringIO.new(req.dup)
|
527
|
+
class << @serv
|
528
|
+
def process_request(req)
|
529
|
+
res = Net::AJP13::Response.new(204)
|
530
|
+
end
|
531
|
+
end
|
532
|
+
|
533
|
+
@serv.fcall(:process, io)
|
534
|
+
io.pos = req.length
|
535
|
+
assert_equal "" +
|
536
|
+
"\x41\x42\x00\x12" + # prefix length
|
537
|
+
"\x04" + # SEND_HEADERS
|
538
|
+
"\x00\xCC\x00\x0ANo Content\x00" + # 204 No Content
|
539
|
+
"\x00\x00" + # num_headers = 0
|
540
|
+
"" +
|
541
|
+
"\x41\x42\x00\x02" + # prefix length
|
542
|
+
"\x05" + # END_RESPONSE
|
543
|
+
"\x01" + # reuse = true
|
544
|
+
"",
|
545
|
+
io.read
|
546
|
+
end
|
547
|
+
end
|
548
|
+
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.8.11
|
3
|
+
specification_version: 1
|
4
|
+
name: ruby-ajp
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.1.5
|
7
|
+
date: 2006-01-09 00:00:00 +09:00
|
8
|
+
summary: An implementation of Apache Jserv Protocol 1.3 in Ruby
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: yugui@yugui.sakura.ne.jp
|
12
|
+
homepage:
|
13
|
+
rubyforge_project: ruby-ajp
|
14
|
+
description:
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.8.3
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
authors:
|
29
|
+
- Yugui
|
30
|
+
files:
|
31
|
+
- lib/net/ajp13server.rb
|
32
|
+
- lib/net/ajp13.rb
|
33
|
+
- lib/net/ajp13client.rb
|
34
|
+
- test/net/test_ajp13request.rb
|
35
|
+
- test/net/test_ajp13server.rb
|
36
|
+
- test/net/test_ajp13response.rb
|
37
|
+
- test/net/test_ajp13client.rb
|
38
|
+
- test/net/test_ajp13packet.rb
|
39
|
+
- test/net/data/rand
|
40
|
+
- test/net/data/ajp13request-data.1
|
41
|
+
- test/net/data/ajp13response-header.1
|
42
|
+
- test/net/data/ajp13response-webdav.1
|
43
|
+
- test/net/data/ajp13response-webdav.2
|
44
|
+
- example/error-server.rb
|
45
|
+
- example/dump-server.rb
|
46
|
+
- example/hello-server.rb
|
47
|
+
- NEWS.en
|
48
|
+
- NEWS.ja
|
49
|
+
- Install.en
|
50
|
+
- Install.ja
|
51
|
+
- README.en
|
52
|
+
- README.ja
|
53
|
+
- Rakefile
|
54
|
+
- ruby-ajp.gemspec
|
55
|
+
- setup.rb
|
56
|
+
- COPYING
|
57
|
+
test_files:
|
58
|
+
- test/net/test_ajp13packet.rb
|
59
|
+
- test/net/test_ajp13request.rb
|
60
|
+
- test/net/test_ajp13response.rb
|
61
|
+
- test/net/test_ajp13client.rb
|
62
|
+
rdoc_options: []
|
63
|
+
|
64
|
+
extra_rdoc_files: []
|
65
|
+
|
66
|
+
executables: []
|
67
|
+
|
68
|
+
extensions: []
|
69
|
+
|
70
|
+
requirements: []
|
71
|
+
|
72
|
+
dependencies: []
|
73
|
+
|