mechanize-ntlm 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +480 -0
- data/EXAMPLES.rdoc +171 -0
- data/FAQ.rdoc +11 -0
- data/GUIDE.rdoc +122 -0
- data/LICENSE.rdoc +340 -0
- data/Manifest.txt +169 -0
- data/README.rdoc +60 -0
- data/Rakefile +44 -0
- data/examples/flickr_upload.rb +23 -0
- data/examples/mech-dump.rb +7 -0
- data/examples/proxy_req.rb +9 -0
- data/examples/rubyforge.rb +21 -0
- data/examples/spider.rb +11 -0
- data/lib/mechanize-ntlm.rb +7 -0
- data/lib/www/mechanize.rb +582 -0
- data/lib/www/mechanize/chain.rb +34 -0
- data/lib/www/mechanize/chain/auth_headers.rb +82 -0
- data/lib/www/mechanize/chain/body_decoding_handler.rb +43 -0
- data/lib/www/mechanize/chain/connection_resolver.rb +78 -0
- data/lib/www/mechanize/chain/custom_headers.rb +23 -0
- data/lib/www/mechanize/chain/handler.rb +9 -0
- data/lib/www/mechanize/chain/header_resolver.rb +48 -0
- data/lib/www/mechanize/chain/parameter_resolver.rb +23 -0
- data/lib/www/mechanize/chain/post_connect_hook.rb +0 -0
- data/lib/www/mechanize/chain/pre_connect_hook.rb +22 -0
- data/lib/www/mechanize/chain/request_resolver.rb +32 -0
- data/lib/www/mechanize/chain/response_body_parser.rb +40 -0
- data/lib/www/mechanize/chain/response_header_handler.rb +51 -0
- data/lib/www/mechanize/chain/response_reader.rb +41 -0
- data/lib/www/mechanize/chain/ssl_resolver.rb +36 -0
- data/lib/www/mechanize/chain/uri_resolver.rb +73 -0
- data/lib/www/mechanize/content_type_error.rb +16 -0
- data/lib/www/mechanize/cookie.rb +72 -0
- data/lib/www/mechanize/cookie_jar.rb +191 -0
- data/lib/www/mechanize/file.rb +73 -0
- data/lib/www/mechanize/file_response.rb +62 -0
- data/lib/www/mechanize/file_saver.rb +39 -0
- data/lib/www/mechanize/form.rb +359 -0
- data/lib/www/mechanize/form/button.rb +8 -0
- data/lib/www/mechanize/form/check_box.rb +13 -0
- data/lib/www/mechanize/form/field.rb +28 -0
- data/lib/www/mechanize/form/file_upload.rb +24 -0
- data/lib/www/mechanize/form/image_button.rb +23 -0
- data/lib/www/mechanize/form/multi_select_list.rb +69 -0
- data/lib/www/mechanize/form/option.rb +51 -0
- data/lib/www/mechanize/form/radio_button.rb +38 -0
- data/lib/www/mechanize/form/select_list.rb +45 -0
- data/lib/www/mechanize/headers.rb +12 -0
- data/lib/www/mechanize/history.rb +67 -0
- data/lib/www/mechanize/inspect.rb +90 -0
- data/lib/www/mechanize/monkey_patch.rb +37 -0
- data/lib/www/mechanize/page.rb +145 -0
- data/lib/www/mechanize/page/base.rb +10 -0
- data/lib/www/mechanize/page/frame.rb +22 -0
- data/lib/www/mechanize/page/link.rb +50 -0
- data/lib/www/mechanize/page/meta.rb +10 -0
- data/lib/www/mechanize/pluggable_parsers.rb +103 -0
- data/lib/www/mechanize/redirect_limit_reached_error.rb +18 -0
- data/lib/www/mechanize/redirect_not_get_or_head_error.rb +20 -0
- data/lib/www/mechanize/response_code_error.rb +25 -0
- data/lib/www/mechanize/unsupported_scheme_error.rb +10 -0
- data/lib/www/mechanize/util.rb +76 -0
- data/lib/www/ntlm-http/lib/net/ntlm_http.rb +854 -0
- data/mechanize.gemspec +24 -0
- data/test/chain/test_argument_validator.rb +14 -0
- data/test/chain/test_custom_headers.rb +18 -0
- data/test/chain/test_parameter_resolver.rb +35 -0
- data/test/chain/test_request_resolver.rb +29 -0
- data/test/chain/test_response_reader.rb +24 -0
- data/test/data/htpasswd +1 -0
- data/test/data/server.crt +16 -0
- data/test/data/server.csr +12 -0
- data/test/data/server.key +15 -0
- data/test/data/server.pem +15 -0
- data/test/helper.rb +127 -0
- data/test/htdocs/alt_text.html +10 -0
- data/test/htdocs/bad_form_test.html +9 -0
- data/test/htdocs/button.jpg +0 -0
- data/test/htdocs/empty_form.html +6 -0
- data/test/htdocs/file_upload.html +26 -0
- data/test/htdocs/find_link.html +41 -0
- data/test/htdocs/form_multi_select.html +16 -0
- data/test/htdocs/form_multival.html +37 -0
- data/test/htdocs/form_no_action.html +18 -0
- data/test/htdocs/form_no_input_name.html +16 -0
- data/test/htdocs/form_select.html +16 -0
- data/test/htdocs/form_select_all.html +16 -0
- data/test/htdocs/form_select_none.html +17 -0
- data/test/htdocs/form_select_noopts.html +10 -0
- data/test/htdocs/form_set_fields.html +14 -0
- data/test/htdocs/form_test.html +188 -0
- data/test/htdocs/frame_test.html +30 -0
- data/test/htdocs/google.html +13 -0
- data/test/htdocs/iframe_test.html +16 -0
- data/test/htdocs/index.html +6 -0
- data/test/htdocs/link with space.html +5 -0
- data/test/htdocs/meta_cookie.html +11 -0
- data/test/htdocs/no_title_test.html +6 -0
- data/test/htdocs/relative/tc_relative_links.html +21 -0
- data/test/htdocs/tc_bad_links.html +5 -0
- data/test/htdocs/tc_base_link.html +8 -0
- data/test/htdocs/tc_blank_form.html +11 -0
- data/test/htdocs/tc_checkboxes.html +19 -0
- data/test/htdocs/tc_encoded_links.html +5 -0
- data/test/htdocs/tc_follow_meta.html +8 -0
- data/test/htdocs/tc_form_action.html +48 -0
- data/test/htdocs/tc_links.html +18 -0
- data/test/htdocs/tc_no_attributes.html +16 -0
- data/test/htdocs/tc_pretty_print.html +17 -0
- data/test/htdocs/tc_radiobuttons.html +17 -0
- data/test/htdocs/tc_referer.html +10 -0
- data/test/htdocs/tc_relative_links.html +19 -0
- data/test/htdocs/tc_textarea.html +23 -0
- data/test/htdocs/unusual______.html +5 -0
- data/test/servlets.rb +339 -0
- data/test/ssl_server.rb +48 -0
- data/test/test_authenticate.rb +71 -0
- data/test/test_bad_links.rb +25 -0
- data/test/test_blank_form.rb +16 -0
- data/test/test_checkboxes.rb +61 -0
- data/test/test_content_type.rb +13 -0
- data/test/test_cookie_class.rb +338 -0
- data/test/test_cookie_jar.rb +343 -0
- data/test/test_cookies.rb +123 -0
- data/test/test_encoded_links.rb +20 -0
- data/test/test_errors.rb +49 -0
- data/test/test_follow_meta.rb +69 -0
- data/test/test_form_action.rb +44 -0
- data/test/test_form_as_hash.rb +61 -0
- data/test/test_form_button.rb +38 -0
- data/test/test_form_no_inputname.rb +15 -0
- data/test/test_forms.rb +575 -0
- data/test/test_frames.rb +25 -0
- data/test/test_get_headers.rb +52 -0
- data/test/test_gzipping.rb +22 -0
- data/test/test_hash_api.rb +45 -0
- data/test/test_history.rb +142 -0
- data/test/test_history_added.rb +16 -0
- data/test/test_html_unscape_forms.rb +39 -0
- data/test/test_if_modified_since.rb +20 -0
- data/test/test_keep_alive.rb +31 -0
- data/test/test_links.rb +120 -0
- data/test/test_mech.rb +259 -0
- data/test/test_mechanize_file.rb +47 -0
- data/test/test_multi_select.rb +106 -0
- data/test/test_no_attributes.rb +13 -0
- data/test/test_option.rb +18 -0
- data/test/test_page.rb +67 -0
- data/test/test_pluggable_parser.rb +145 -0
- data/test/test_post_form.rb +34 -0
- data/test/test_pretty_print.rb +22 -0
- data/test/test_radiobutton.rb +75 -0
- data/test/test_redirect_limit_reached.rb +41 -0
- data/test/test_redirect_verb_handling.rb +45 -0
- data/test/test_referer.rb +39 -0
- data/test/test_relative_links.rb +40 -0
- data/test/test_request.rb +13 -0
- data/test/test_response_code.rb +52 -0
- data/test/test_save_file.rb +48 -0
- data/test/test_scheme.rb +48 -0
- data/test/test_select.rb +106 -0
- data/test/test_select_all.rb +15 -0
- data/test/test_select_none.rb +15 -0
- data/test/test_select_noopts.rb +16 -0
- data/test/test_set_fields.rb +44 -0
- data/test/test_ssl_server.rb +20 -0
- data/test/test_subclass.rb +14 -0
- data/test/test_textarea.rb +45 -0
- data/test/test_upload.rb +109 -0
- data/test/test_verbs.rb +25 -0
- metadata +284 -0
data/mechanize.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{mechanize-ntlm}
|
5
|
+
s.version = "0.9.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Aaron Patterson", "Mike Dalessio", "Kingsley Hendrickse"]
|
9
|
+
s.date = %q{20-05-2009}
|
10
|
+
s.description = %q{The Mechanize library is used for automating interaction with websites. Mechanize automatically stores and sends cookies, follows redirects, can follow links, and submit forms. Form fields can be populated and submitted. Mechanize also keeps track of the sites that you have visited as a history.}
|
11
|
+
s.email = ["aaronp@rubyforge.org", "mike.dalessio@gmail.com"]
|
12
|
+
s.extra_rdoc_files = ["Manifest.txt", "CHANGELOG.rdoc", "EXAMPLES.rdoc", "FAQ.rdoc", "GUIDE.rdoc", "LICENSE.rdoc", "README.rdoc"]
|
13
|
+
s.files = ["CHANGELOG.rdoc", "EXAMPLES.rdoc", "FAQ.rdoc", "GUIDE.rdoc", "LICENSE.rdoc", "Manifest.txt", "README.rdoc", "Rakefile", "examples/flickr_upload.rb", "examples/mech-dump.rb", "examples/proxy_req.rb", "examples/rubyforge.rb", "examples/spider.rb", "lib/mechanize-ntlm.rb", "lib/www/mechanize.rb", "lib/www/mechanize/chain.rb", "lib/www/mechanize/chain/auth_headers.rb", "lib/www/mechanize/chain/body_decoding_handler.rb", "lib/www/mechanize/chain/connection_resolver.rb", "lib/www/mechanize/chain/custom_headers.rb", "lib/www/mechanize/chain/handler.rb", "lib/www/mechanize/chain/header_resolver.rb", "lib/www/mechanize/chain/parameter_resolver.rb", "lib/www/mechanize/chain/post_connect_hook.rb", "lib/www/mechanize/chain/pre_connect_hook.rb", "lib/www/mechanize/chain/request_resolver.rb", "lib/www/mechanize/chain/response_body_parser.rb", "lib/www/mechanize/chain/response_header_handler.rb", "lib/www/mechanize/chain/response_reader.rb", "lib/www/mechanize/chain/ssl_resolver.rb", "lib/www/mechanize/chain/uri_resolver.rb", "lib/www/mechanize/content_type_error.rb", "lib/www/mechanize/cookie.rb", "lib/www/mechanize/cookie_jar.rb", "lib/www/mechanize/file.rb", "lib/www/mechanize/file_response.rb", "lib/www/mechanize/file_saver.rb", "lib/www/mechanize/form.rb", "lib/www/mechanize/form/button.rb", "lib/www/mechanize/form/check_box.rb", "lib/www/mechanize/form/field.rb", "lib/www/mechanize/form/file_upload.rb", "lib/www/mechanize/form/image_button.rb", "lib/www/mechanize/form/multi_select_list.rb", "lib/www/mechanize/form/option.rb", "lib/www/mechanize/form/radio_button.rb", "lib/www/mechanize/form/select_list.rb", "lib/www/mechanize/headers.rb", "lib/www/mechanize/history.rb", "lib/www/mechanize/inspect.rb", "lib/www/mechanize/monkey_patch.rb", "lib/www/mechanize/page.rb", "lib/www/mechanize/page/base.rb", "lib/www/mechanize/page/frame.rb", "lib/www/mechanize/page/link.rb", "lib/www/mechanize/page/meta.rb", "lib/www/mechanize/pluggable_parsers.rb", "lib/www/mechanize/redirect_limit_reached_error.rb", "lib/www/mechanize/redirect_not_get_or_head_error.rb", "lib/www/mechanize/response_code_error.rb", "lib/www/mechanize/unsupported_scheme_error.rb", "lib/www/mechanize/util.rb", "mechanize.gemspec", "test/chain/test_argument_validator.rb", "test/chain/test_custom_headers.rb", "test/chain/test_parameter_resolver.rb", "test/chain/test_request_resolver.rb", "test/chain/test_response_reader.rb", "test/data/htpasswd", "test/data/server.crt", "test/data/server.csr", "test/data/server.key", "test/data/server.pem", "test/helper.rb", "test/htdocs/alt_text.html", "test/htdocs/bad_form_test.html", "test/htdocs/button.jpg", "test/htdocs/empty_form.html", "test/htdocs/file_upload.html", "test/htdocs/find_link.html", "test/htdocs/form_multi_select.html", "test/htdocs/form_multival.html", "test/htdocs/form_no_action.html", "test/htdocs/form_no_input_name.html", "test/htdocs/form_select.html", "test/htdocs/form_select_all.html", "test/htdocs/form_select_none.html", "test/htdocs/form_select_noopts.html", "test/htdocs/form_set_fields.html", "test/htdocs/form_test.html", "test/htdocs/frame_test.html", "test/htdocs/google.html", "test/htdocs/iframe_test.html", "test/htdocs/index.html", "test/htdocs/link with space.html", "test/htdocs/meta_cookie.html", "test/htdocs/no_title_test.html", "test/htdocs/relative/tc_relative_links.html", "test/htdocs/tc_bad_links.html", "test/htdocs/tc_base_link.html", "test/htdocs/tc_blank_form.html", "test/htdocs/tc_checkboxes.html", "test/htdocs/tc_encoded_links.html", "test/htdocs/tc_follow_meta.html", "test/htdocs/tc_form_action.html", "test/htdocs/tc_links.html", "test/htdocs/tc_no_attributes.html", "test/htdocs/tc_pretty_print.html", "test/htdocs/tc_radiobuttons.html", "test/htdocs/tc_referer.html", "test/htdocs/tc_relative_links.html", "test/htdocs/tc_textarea.html", "test/htdocs/unusual______.html", "test/servlets.rb", "test/ssl_server.rb", "test/test_authenticate.rb", "test/test_bad_links.rb", "test/test_blank_form.rb", "test/test_checkboxes.rb", "test/test_content_type.rb", "test/test_cookie_class.rb", "test/test_cookie_jar.rb", "test/test_cookies.rb", "test/test_encoded_links.rb", "test/test_errors.rb", "test/test_follow_meta.rb", "test/test_form_action.rb", "test/test_form_as_hash.rb", "test/test_form_button.rb", "test/test_form_no_inputname.rb", "test/test_forms.rb", "test/test_frames.rb", "test/test_get_headers.rb", "test/test_gzipping.rb", "test/test_hash_api.rb", "test/test_history.rb", "test/test_history_added.rb", "test/test_html_unscape_forms.rb", "test/test_if_modified_since.rb", "test/test_keep_alive.rb", "test/test_links.rb", "test/test_mech.rb", "test/test_mechanize_file.rb", "test/test_multi_select.rb", "test/test_no_attributes.rb", "test/test_option.rb", "test/test_page.rb", "test/test_pluggable_parser.rb", "test/test_post_form.rb", "test/test_pretty_print.rb", "test/test_radiobutton.rb", "test/test_redirect_limit_reached.rb", "test/test_redirect_verb_handling.rb", "test/test_referer.rb", "test/test_relative_links.rb", "test/test_request.rb", "test/test_response_code.rb", "test/test_save_file.rb", "test/test_scheme.rb", "test/test_select.rb", "test/test_select_all.rb", "test/test_select_none.rb", "test/test_select_noopts.rb", "test/test_set_fields.rb", "test/test_ssl_server.rb", "test/test_subclass.rb", "test/test_textarea.rb", "test/test_upload.rb", "test/test_verbs.rb","lib/www/ntlm-http/lib/net/ntlm_http.rb"]
|
14
|
+
s.has_rdoc = true
|
15
|
+
s.homepage = %q{ http://mechanize.rubyforge.org/}
|
16
|
+
s.rdoc_options = ["--main", "README.rdoc"]
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
s.rubyforge_project = %q{mechanize}
|
19
|
+
s.rubygems_version = %q{1.3.1}
|
20
|
+
s.summary = %q{Mechanize provides automated web-browsing}
|
21
|
+
s.test_files = ["test/chain/test_argument_validator.rb", "test/chain/test_custom_headers.rb", "test/chain/test_parameter_resolver.rb", "test/chain/test_request_resolver.rb", "test/chain/test_response_reader.rb", "test/test_authenticate.rb", "test/test_bad_links.rb", "test/test_blank_form.rb", "test/test_checkboxes.rb", "test/test_content_type.rb", "test/test_cookie_class.rb", "test/test_cookie_jar.rb", "test/test_cookies.rb", "test/test_encoded_links.rb", "test/test_errors.rb", "test/test_follow_meta.rb", "test/test_form_action.rb", "test/test_form_as_hash.rb", "test/test_form_button.rb", "test/test_form_no_inputname.rb", "test/test_forms.rb", "test/test_frames.rb", "test/test_get_headers.rb", "test/test_gzipping.rb", "test/test_hash_api.rb", "test/test_history.rb", "test/test_history_added.rb", "test/test_html_unscape_forms.rb", "test/test_if_modified_since.rb", "test/test_keep_alive.rb", "test/test_links.rb", "test/test_mech.rb", "test/test_mechanize_file.rb", "test/test_multi_select.rb", "test/test_no_attributes.rb", "test/test_option.rb", "test/test_page.rb", "test/test_pluggable_parser.rb", "test/test_post_form.rb", "test/test_pretty_print.rb", "test/test_radiobutton.rb", "test/test_redirect_limit_reached.rb", "test/test_redirect_verb_handling.rb", "test/test_referer.rb", "test/test_relative_links.rb", "test/test_request.rb", "test/test_response_code.rb", "test/test_save_file.rb", "test/test_scheme.rb", "test/test_select.rb", "test/test_select_all.rb", "test/test_select_none.rb", "test/test_select_noopts.rb", "test/test_set_fields.rb", "test/test_ssl_server.rb", "test/test_subclass.rb", "test/test_textarea.rb", "test/test_upload.rb", "test/test_verbs.rb"]
|
22
|
+
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))
|
2
|
+
|
3
|
+
class TestURIResolver < Test::Unit::TestCase
|
4
|
+
def test_handle
|
5
|
+
v = WWW::Mechanize::Chain.new([
|
6
|
+
WWW::Mechanize::Chain::URIResolver.new(Hash.new { |h,k|
|
7
|
+
h[k] = lambda { |u,r| u }
|
8
|
+
})
|
9
|
+
])
|
10
|
+
assert_raises(ArgumentError) { v.handle({}) }
|
11
|
+
assert_nothing_raised { v.handle({:uri => 'http://google.com/'}) }
|
12
|
+
assert_raises(RuntimeError) { v.handle({:uri => 'google'}) }
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))
|
2
|
+
|
3
|
+
class TestCustomHeaders < Test::Unit::TestCase
|
4
|
+
def test_handle
|
5
|
+
v = WWW::Mechanize::Chain.new([
|
6
|
+
WWW::Mechanize::Chain::CustomHeaders.new
|
7
|
+
])
|
8
|
+
url = URI.parse('http://tenderlovemaking.com/')
|
9
|
+
hash = {
|
10
|
+
:request => Net::HTTP::Get.new(url.request_uri),
|
11
|
+
:headers => { 'Content-Length' => 300 }
|
12
|
+
}
|
13
|
+
v.handle(hash)
|
14
|
+
headers = hash[:request].to_hash
|
15
|
+
assert(headers.key?('content-length'))
|
16
|
+
assert_equal([300], headers['content-length'])
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))
|
2
|
+
|
3
|
+
class TestParameterResolver < Test::Unit::TestCase
|
4
|
+
def test_handle_get
|
5
|
+
v = WWW::Mechanize::Chain.new([
|
6
|
+
WWW::Mechanize::Chain::ParameterResolver.new
|
7
|
+
])
|
8
|
+
hash = {
|
9
|
+
:uri => URI.parse('http://google.com/'),
|
10
|
+
:params => { :q => 'hello' },
|
11
|
+
:verb => :get
|
12
|
+
}
|
13
|
+
assert_nothing_raised {
|
14
|
+
v.handle(hash)
|
15
|
+
}
|
16
|
+
assert_equal('q=hello', hash[:uri].query)
|
17
|
+
assert_equal([], hash[:params])
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_handle_post
|
21
|
+
v = WWW::Mechanize::Chain.new([
|
22
|
+
WWW::Mechanize::Chain::ParameterResolver.new
|
23
|
+
])
|
24
|
+
hash = {
|
25
|
+
:uri => URI.parse('http://google.com/'),
|
26
|
+
:params => { :q => 'hello' },
|
27
|
+
:verb => :post
|
28
|
+
}
|
29
|
+
assert_nothing_raised {
|
30
|
+
v.handle(hash)
|
31
|
+
}
|
32
|
+
assert_equal('', hash[:uri].query.to_s)
|
33
|
+
assert_equal({ :q => 'hello' }, hash[:params])
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))
|
2
|
+
|
3
|
+
class TestRequestResolver < Test::Unit::TestCase
|
4
|
+
def test_handle_get
|
5
|
+
v = WWW::Mechanize::Chain.new([
|
6
|
+
WWW::Mechanize::Chain::RequestResolver.new
|
7
|
+
])
|
8
|
+
hash = {
|
9
|
+
:uri => URI.parse('http://google.com'),
|
10
|
+
:verb => :get
|
11
|
+
}
|
12
|
+
assert_nothing_raised { v.handle(hash) }
|
13
|
+
assert_kind_of(Net::HTTP::Get, hash[:request])
|
14
|
+
assert_equal('/', hash[:request].path)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_handle_post
|
18
|
+
v = WWW::Mechanize::Chain.new([
|
19
|
+
WWW::Mechanize::Chain::RequestResolver.new
|
20
|
+
])
|
21
|
+
hash = {
|
22
|
+
:uri => URI.parse('http://google.com'),
|
23
|
+
:verb => :post
|
24
|
+
}
|
25
|
+
assert_nothing_raised { v.handle(hash) }
|
26
|
+
assert_kind_of(Net::HTTP::Post, hash[:request])
|
27
|
+
assert_equal('/', hash[:request].path)
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))
|
2
|
+
|
3
|
+
class TestResponseReader < Test::Unit::TestCase
|
4
|
+
def test_handle_bad_response_code
|
5
|
+
response = Object.new
|
6
|
+
class << response
|
7
|
+
def read_body
|
8
|
+
end
|
9
|
+
def code; 999; end
|
10
|
+
end
|
11
|
+
|
12
|
+
v = WWW::Mechanize::Chain.new([
|
13
|
+
WWW::Mechanize::Chain::ResponseReader.new(response)
|
14
|
+
])
|
15
|
+
assert_raises(WWW::Mechanize::ResponseCodeError) {
|
16
|
+
begin
|
17
|
+
v.handle({})
|
18
|
+
rescue Exception => x
|
19
|
+
assert_equal(999, x.response_code)
|
20
|
+
raise x
|
21
|
+
end
|
22
|
+
}
|
23
|
+
end
|
24
|
+
end
|
data/test/data/htpasswd
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
mech:44E/qORekFV0E
|
@@ -0,0 +1,16 @@
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
2
|
+
MIICmzCCAgQCCQDq2kM3TCIM0DANBgkqhkiG9w0BAQQFADCBkTELMAkGA1UEBhMC
|
3
|
+
VVMxEzARBgNVBAgTCldhc2hpbmd0b24xEDAOBgNVBAcTB1NlYXR0bGUxEjAQBgNV
|
4
|
+
BAoTCU1lY2hhbml6ZTESMBAGA1UECxMJTWVjaGFuaXplMQ4wDAYDVQQDEwVBYXJv
|
5
|
+
bjEjMCEGCSqGSIb3DQEJARYUYWFyb25wQHJ1Ynlmb3JnZS5vcmcwHhcNMDYwODIz
|
6
|
+
MDU0NTMwWhcNMDcwODIzMDU0NTMwWjCBkTELMAkGA1UEBhMCVVMxEzARBgNVBAgT
|
7
|
+
Cldhc2hpbmd0b24xEDAOBgNVBAcTB1NlYXR0bGUxEjAQBgNVBAoTCU1lY2hhbml6
|
8
|
+
ZTESMBAGA1UECxMJTWVjaGFuaXplMQ4wDAYDVQQDEwVBYXJvbj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kpkSl
|
13
|
+
y+FYtDNERpW+BBliwgECQA+Vc7pnxwDIOP8kFumdAUmRmhEZjuwArFcywPzrCUn9
|
14
|
+
4/KBOp5wDN7kanBwNGZCZ/eQtkb6thAS8C9pufHD1lw=
|
15
|
+
-----END RSA PRIVATE KEY-----
|
data/test/helper.rb
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
$:.unshift(File.expand_path(File.join(File.dirname(__FILE__),'..','lib')))
|
3
|
+
require 'rubygems'
|
4
|
+
require 'mechanize'
|
5
|
+
require 'webrick/httputils'
|
6
|
+
require File.join(File.dirname(__FILE__),'servlets')
|
7
|
+
|
8
|
+
BASE_DIR = File.dirname(__FILE__)
|
9
|
+
|
10
|
+
# Move this to a test base class
|
11
|
+
module MechTestHelper
|
12
|
+
def self.fake_page(agent)
|
13
|
+
html = <<-END
|
14
|
+
<html><body>
|
15
|
+
<form><input type="submit" value="submit" /></form>
|
16
|
+
</body></html>
|
17
|
+
END
|
18
|
+
html_response = { 'content-type' => 'text/html' }
|
19
|
+
page = WWW::Mechanize::Page.new( nil, html_response, html, 200, agent )
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class Net::HTTP
|
24
|
+
alias :old_do_start :do_start
|
25
|
+
|
26
|
+
def do_start
|
27
|
+
@started = true
|
28
|
+
end
|
29
|
+
|
30
|
+
SERVLETS = {
|
31
|
+
'/gzip' => GzipServlet,
|
32
|
+
'/form_post' => FormTest,
|
33
|
+
'/basic_auth' => BasicAuthServlet,
|
34
|
+
'/form post' => FormTest,
|
35
|
+
'/response_code' => ResponseCodeTest,
|
36
|
+
'/http_refresh' => HttpRefreshTest,
|
37
|
+
'/bad_content_type' => BadContentTypeTest,
|
38
|
+
'/content_type_test' => ContentTypeTest,
|
39
|
+
'/referer' => RefererServlet,
|
40
|
+
'/file_upload' => FileUploadTest,
|
41
|
+
'/one_cookie' => OneCookieTest,
|
42
|
+
'/one_cookie_no_space' => OneCookieNoSpacesTest,
|
43
|
+
'/many_cookies' => ManyCookiesTest,
|
44
|
+
'/many_cookies_as_string' => ManyCookiesAsStringTest,
|
45
|
+
'/send_cookies' => SendCookiesTest,
|
46
|
+
'/if_modified_since' => ModifiedSinceServlet,
|
47
|
+
'/http_headers' => HeaderServlet,
|
48
|
+
'/infinite_redirect' => InfiniteRedirectTest,
|
49
|
+
'/infinite_refresh' => InfiniteRefreshTest,
|
50
|
+
'/redirect' => RedirectTest,
|
51
|
+
'/digest_auth' => DigestAuthServlet,
|
52
|
+
'/verb' => VerbServlet,
|
53
|
+
}
|
54
|
+
|
55
|
+
PAGE_CACHE = {}
|
56
|
+
|
57
|
+
alias :old_request :request
|
58
|
+
|
59
|
+
def request(request, *data, &block)
|
60
|
+
url = URI.parse(request.path)
|
61
|
+
path = URI.unescape(url.path)
|
62
|
+
|
63
|
+
path = '/index.html' if path == '/'
|
64
|
+
|
65
|
+
res = Response.new
|
66
|
+
request.query = WEBrick::HTTPUtils.parse_query(url.query)
|
67
|
+
request.cookies = WEBrick::Cookie.parse(request['Cookie'])
|
68
|
+
if SERVLETS[path]
|
69
|
+
if request.method == "POST"
|
70
|
+
if request['Content-Type'] =~ /^multipart\/form-data/
|
71
|
+
request.body = data.first
|
72
|
+
else
|
73
|
+
request.query = WEBrick::HTTPUtils.parse_query(data.first)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
SERVLETS[path].new({}).send("do_#{request.method}", request, res)
|
77
|
+
else
|
78
|
+
filename = "htdocs#{path.gsub(/[^\/\\.\w_\s]/, '_')}"
|
79
|
+
unless PAGE_CACHE[filename]
|
80
|
+
File.open("#{BASE_DIR}/#{filename}", 'rb') { |file|
|
81
|
+
PAGE_CACHE[filename] = file.read
|
82
|
+
}
|
83
|
+
end
|
84
|
+
res.body = PAGE_CACHE[filename]
|
85
|
+
end
|
86
|
+
|
87
|
+
res['Content-Type'] ||= 'text/html'
|
88
|
+
res['Content-Length'] ||= res.body.length.to_s
|
89
|
+
res.code ||= "200"
|
90
|
+
|
91
|
+
res.cookies.each do |cookie|
|
92
|
+
res.add_field('Set-Cookie', cookie.to_s)
|
93
|
+
end
|
94
|
+
yield res if block_given?
|
95
|
+
res
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
class Net::HTTPRequest
|
100
|
+
attr_accessor :query, :body, :cookies, :user
|
101
|
+
end
|
102
|
+
|
103
|
+
class Response
|
104
|
+
include Net::HTTPHeader
|
105
|
+
|
106
|
+
attr_reader :code
|
107
|
+
attr_accessor :body, :query, :cookies
|
108
|
+
|
109
|
+
def code=(c)
|
110
|
+
@code = c.to_s
|
111
|
+
end
|
112
|
+
|
113
|
+
alias :status :code
|
114
|
+
alias :status= :code=
|
115
|
+
|
116
|
+
def initialize
|
117
|
+
@header = {}
|
118
|
+
@body = ''
|
119
|
+
@code = nil
|
120
|
+
@query = nil
|
121
|
+
@cookies = []
|
122
|
+
end
|
123
|
+
|
124
|
+
def read_body
|
125
|
+
yield body
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<html>
|
2
|
+
<meta http-equiv="Refresh" content="0; url=http://www.drphil.com/">
|
3
|
+
<body>
|
4
|
+
<a href="alt_text.html"><img alt="alt text" src="hello"></a>
|
5
|
+
<a href="no_alt_text.html"><img src="hello"></a>
|
6
|
+
<a href="nil_alt_text.html"><img alt src="hello"></a>
|
7
|
+
<a href="no_image.html">no image</a>
|
8
|
+
<a href="no_text.html"></a>
|
9
|
+
</body>
|
10
|
+
</html>
|
Binary file
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<title>File Upload Form</title>
|
4
|
+
</head>
|
5
|
+
<body>
|
6
|
+
<h1>File Upload Test</h1>
|
7
|
+
<form enctype="multipart/form-data" action="/file_upload" method="post">
|
8
|
+
Your name: <input type="text" name="name" /><br />
|
9
|
+
File to process: <input name="userfile1" type="file" /><br />
|
10
|
+
<input type="text" name="foo[aaron]" value="test" />
|
11
|
+
<select name="foo">
|
12
|
+
</select>
|
13
|
+
<input type="submit" value="Send File" />
|
14
|
+
</form>
|
15
|
+
<form enctype="multipart/form-data" action="/file_upload" method="post">
|
16
|
+
Your name: <input type="text" name="name" /><br />
|
17
|
+
File to process: <input name="green[eggs]" type="file" /><br />
|
18
|
+
<input type="submit" value="Send File" />
|
19
|
+
</form>
|
20
|
+
<form enctype="multipart/form-data" action="/file_upload" name="value_test" method="post">
|
21
|
+
Your name: <input type="text" name="name" /><br />
|
22
|
+
File to process: <input name="green[eggs]" value="/etc/hosts" type="file" /><br />
|
23
|
+
<input type="submit" value="Send File" />
|
24
|
+
</form>
|
25
|
+
</body>
|
26
|
+
</html>
|
@@ -0,0 +1,41 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<meta http_equiv="Refresh" content="0; url=http://www.incorrect.com">
|
4
|
+
<meta http-equiv="Rfresh" content="0; url=http://www.also-wrong.com">
|
5
|
+
<meta http-equiv="Refresh" content="0; url=http://www.drphil.com/">
|
6
|
+
<meta http-equiv="Refresh" content="0; url='http://tenderlovemaking.com/'">
|
7
|
+
<META HTTP-EQUIV="REFRESH" CONTENT="0; URL=HTTP://WWW.UPCASE.COM/">
|
8
|
+
<TITLE>Testing the links</TITLE>
|
9
|
+
</head>
|
10
|
+
<body>
|
11
|
+
<A HREF="http://blargle.com/">blargle</A>
|
12
|
+
<A HREF="http://a.cpan.org/">CPAN A</A>
|
13
|
+
<A HREF="http://b.cpan.org/">CPAN B</A>
|
14
|
+
<FRAME SRC="foo.html">
|
15
|
+
<FRAME SRC="bar.html">
|
16
|
+
<A HREF="http://c.cpan.org/" NAME="bongo">CPAN C</A>
|
17
|
+
<A HREF="http://d.cpan.org/">CPAN D</A>
|
18
|
+
|
19
|
+
<A HREF="http://www.msnbc.com/">MSNBC</A>
|
20
|
+
<FRAME SRC="http://www.oreilly.com/" NAME="wongo">
|
21
|
+
<A HREF="http://www.cnn.com/">CNN</A>
|
22
|
+
<A HREF="http://www.bbc.co.uk/" NAME="Wilma">BBC</A>
|
23
|
+
<A HREF="http://www.msnbc.com/">News</A>
|
24
|
+
<A HREF="http://www.cnn.com/" NAME="Fred">News</A>
|
25
|
+
<A HREF="http://www.bbc.co.uk/">News</A>
|
26
|
+
<A onmouseover="window.status='Rebuild Files'; return true" href="#" onClick="window.open( '/cgi-bin/MT/mt.cgi', 'rebuild', 'width=400,height=200,resizable=yes')">Rebuild Index</A>
|
27
|
+
|
28
|
+
<MAP NAME="SOME_MAP">
|
29
|
+
<AREA HREF="http://www.msnbc.com/area" COORDS="1,2,3,4"></AREA>
|
30
|
+
<AREA HREF="http://www.cnn.com/area" COORDS="5,6,7,8" NAME="Marty">
|
31
|
+
<AREA HREF="http://www.cpan.org/area" COORDS="10,11,12,13" />
|
32
|
+
</MAP>
|
33
|
+
<IMG SRC="SOME_IMAGE" USEMAP="#SOME_MAP">
|
34
|
+
|
35
|
+
<!-- new stuff -->
|
36
|
+
<A HREF="http://nowhere.org/" Name="Here">NoWhere</A>
|
37
|
+
<A HREF="http://nowhere.org/padded" Name=" Here "> NoWhere </A>
|
38
|
+
<A HREF="blongo.html">Blongo!</A>
|
39
|
+
</body>
|
40
|
+
</html>
|
41
|
+
|