2
2
require 'test/unit'
3
3
require 'open-uri'
4
4
require_relative 'utils'
5
- require 'webrick'
6
- require 'webrick/httpproxy'
7
- begin
8
- require 'zlib'
9
- rescue LoadError
10
- end
11
5
12
6
class TestOpenURIProxy < Test ::Unit ::TestCase
13
7
include TestOpenURIUtils
14
8
15
- NullLog = Object . new
16
- def NullLog . <<( arg )
17
- #puts arg if / INFO / !~ arg
18
- end
19
-
20
9
def with_env ( h )
21
10
begin
22
11
old = { }
@@ -41,18 +30,12 @@ def teardown
41
30
def test_proxy
42
31
with_http { |srv , url |
43
32
proxy_log = StringIO . new ( '' . dup )
44
- proxy_logger = WEBrick ::Log . new ( proxy_log , WEBrick ::BasicLog ::WARN )
45
33
proxy_auth_log = '' . dup
46
- proxy = WEBrick ::HTTPProxyServer . new ( {
47
- :ServerType => Thread ,
48
- :Logger => proxy_logger ,
49
- :AccessLog => [ [ NullLog , "" ] ] ,
50
- :ProxyAuthProc => lambda { |req , res |
34
+ proxy_host = '127.0.0.1'
35
+ proxy = SimpleHTTPProxyServer . new ( proxy_host , 0 , lambda { |req , res |
51
36
proxy_auth_log << req . request_line
52
- } ,
53
- :BindAddress => '127.0.0.1' ,
54
- :Port => 0 } )
55
- _ , proxy_port , _ , proxy_host = proxy . listeners [ 0 ] . addr
37
+ } , proxy_log )
38
+ proxy_port = proxy . instance_variable_get ( :@server ) . addr [ 1 ]
56
39
proxy_url = "http://#{ proxy_host } :#{ proxy_port } /"
57
40
begin
58
41
proxy_thread = proxy . start
@@ -95,21 +78,15 @@ def test_proxy
95
78
def test_proxy_http_basic_authentication_failure
96
79
with_http { |srv , url |
97
80
proxy_log = StringIO . new ( '' . dup )
98
- proxy_logger = WEBrick ::Log . new ( proxy_log , WEBrick ::BasicLog ::WARN )
99
81
proxy_auth_log = '' . dup
100
- proxy = WEBrick ::HTTPProxyServer . new ( {
101
- :ServerType => Thread ,
102
- :Logger => proxy_logger ,
103
- :AccessLog => [ [ NullLog , "" ] ] ,
104
- :ProxyAuthProc => lambda { |req , res |
82
+ proxy_host = '127.0.0.1'
83
+ proxy = SimpleHTTPProxyServer . new ( proxy_host , 0 , lambda { |req , res |
105
84
proxy_auth_log << req . request_line
106
85
if req [ "Proxy-Authorization" ] != "Basic #{ [ 'user:pass' ] . pack ( 'm' ) . chomp } "
107
- raise WEBrick :: HTTPStatus :: ProxyAuthenticationRequired
86
+ raise ProxyAuthenticationRequired
108
87
end
109
- } ,
110
- :BindAddress => '127.0.0.1' ,
111
- :Port => 0 } )
112
- _ , proxy_port , _ , proxy_host = proxy . listeners [ 0 ] . addr
88
+ } , proxy_log )
89
+ proxy_port = proxy . instance_variable_get ( :@server ) . addr [ 1 ]
113
90
proxy_url = "http://#{ proxy_host } :#{ proxy_port } /"
114
91
begin
115
92
th = proxy . start
@@ -121,28 +98,22 @@ def test_proxy_http_basic_authentication_failure
121
98
proxy . shutdown
122
99
th . join
123
100
end
124
- assert_match ( /ERROR WEBrick::HTTPStatus:: ProxyAuthenticationRequired/ , proxy_log . string )
101
+ assert_match ( /ERROR ProxyAuthenticationRequired/ , proxy_log . string )
125
102
}
126
103
end
127
104
128
105
def test_proxy_http_basic_authentication_success
129
106
with_http { |srv , url |
130
107
proxy_log = StringIO . new ( '' . dup )
131
- proxy_logger = WEBrick ::Log . new ( proxy_log , WEBrick ::BasicLog ::WARN )
132
108
proxy_auth_log = '' . dup
133
- proxy = WEBrick ::HTTPProxyServer . new ( {
134
- :ServerType => Thread ,
135
- :Logger => proxy_logger ,
136
- :AccessLog => [ [ NullLog , "" ] ] ,
137
- :ProxyAuthProc => lambda { |req , res |
109
+ proxy_host = '127.0.0.1'
110
+ proxy = SimpleHTTPProxyServer . new ( proxy_host , 0 , lambda { |req , res |
138
111
proxy_auth_log << req . request_line
139
112
if req [ "Proxy-Authorization" ] != "Basic #{ [ 'user:pass' ] . pack ( 'm' ) . chomp } "
140
- raise WEBrick :: HTTPStatus :: ProxyAuthenticationRequired
113
+ raise ProxyAuthenticationRequired
141
114
end
142
- } ,
143
- :BindAddress => '127.0.0.1' ,
144
- :Port => 0 } )
145
- _ , proxy_port , _ , proxy_host = proxy . listeners [ 0 ] . addr
115
+ } , proxy_log )
116
+ proxy_port = proxy . instance_variable_get ( :@server ) . addr [ 1 ]
146
117
proxy_url = "http://#{ proxy_host } :#{ proxy_port } /"
147
118
begin
148
119
th = proxy . start
@@ -169,21 +140,15 @@ def test_proxy_http_basic_authentication_success
169
140
def test_authenticated_proxy_http_basic_authentication_success
170
141
with_http { |srv , url |
171
142
proxy_log = StringIO . new ( '' . dup )
172
- proxy_logger = WEBrick ::Log . new ( proxy_log , WEBrick ::BasicLog ::WARN )
173
143
proxy_auth_log = '' . dup
174
- proxy = WEBrick ::HTTPProxyServer . new ( {
175
- :ServerType => Thread ,
176
- :Logger => proxy_logger ,
177
- :AccessLog => [ [ NullLog , "" ] ] ,
178
- :ProxyAuthProc => lambda { |req , res |
144
+ proxy_host = '127.0.0.1'
145
+ proxy = SimpleHTTPProxyServer . new ( proxy_host , 0 , lambda { |req , res |
179
146
proxy_auth_log << req . request_line
180
147
if req [ "Proxy-Authorization" ] != "Basic #{ [ 'user:pass' ] . pack ( 'm' ) . chomp } "
181
- raise WEBrick :: HTTPStatus :: ProxyAuthenticationRequired
148
+ raise ProxyAuthenticationRequired
182
149
end
183
- } ,
184
- :BindAddress => '127.0.0.1' ,
185
- :Port => 0 } )
186
- _ , proxy_port , _ , proxy_host = proxy . listeners [ 0 ] . addr
150
+ } , proxy_log )
151
+ proxy_port = proxy . instance_variable_get ( :@server ) . addr [ 1 ]
187
152
proxy_url = "http://user:pass@#{ proxy_host } :#{ proxy_port } /"
188
153
begin
189
154
th = proxy . start
0 commit comments