diff -N -u c:\ruby\src\ruby-1.8.4\test\net\http.1.8.5.preview1/ruby_sspi_test.rb c:\ruby\src\ruby-1.8.4\test\net\http/ruby_sspi_test.rb --- c:\ruby\src\ruby-1.8.4\test\net\http.1.8.5.preview1/ruby_sspi_test.rb 1969-12-31 16:00:00.000000000 -0800 +++ c:\ruby\src\ruby-1.8.4\test\net\http/ruby_sspi_test.rb 2006-07-20 15:13:29.611112500 -0700 @@ -0,0 +1,87 @@ +# +# = test/net/http/ruby_sspi_test.rb +# +# Copyright (c) 2006 Justin Bailey +# +# Written and maintained by Justin Bailey . +# +# This program is free software. You can re-distribute and/or +# modify this program under the same terms of ruby itself --- +# Ruby Distribution License or GNU General Public License. + +require 'test/unit' +require 'net/http' +require 'net/rubysspi' + +# These tests use the SSPI library directly. +class NTLMTest < Test::Unit::TestCase + def test_auth + proxy = get_proxy + + Net::HTTP.start(proxy.host, proxy.port) do |http| + nego_auth = SSPI::NegotiateAuth.new + sr = http.request_get "http://www.google.com/", { "Proxy-Authorization" => "Negotiate " + nego_auth.get_initial_token } + resp = http.get "http://www.google.com/", { "Proxy-Authorization" => "Negotiate " + nego_auth.complete_authentication(sr["Proxy-Authenticate"].split(" ").last.strip) } + assert resp.code.to_i == 200, "Resposne code not as expected: #{resp.inspect}" + resp = http.get "http://www.google.com/foobar.html" + assert resp.code.to_i == 404, "Response code not as expected: #{resp.inspect}" + end + end + + def test_proxy_auth_get + proxy = get_proxy + + Net::HTTP.start(proxy.host, proxy.port) do |http| + resp = SSPI::NegotiateAuth.proxy_auth_get http, "http://www.google.com/" + assert resp.code.to_i == 200, "Response code not as expected: #{resp.inspect}" + end + end + + def test_one_time_use_only + proxy = get_proxy + + Net::HTTP.start(proxy.host, proxy.port) do |http| + nego_auth = SSPI::NegotiateAuth.new + sr = http.request_get "http://www.google.com/", { "Proxy-Authorization" => "Negotiate " + nego_auth.get_initial_token } + resp = http.get "http://www.google.com/", { "Proxy-Authorization" => "Negotiate " + nego_auth.complete_authentication(sr["Proxy-Authenticate"].split(" ").last.strip) } + assert resp.code.to_i == 200, "Response code not as expected: #{resp.inspect}" + assert_raises(RuntimeError, "Should not be able to call complete_authentication again") do + nego_auth.complete_authentication "foo" + end + end + end + + def test_token_variations + proxy = get_proxy + + # Test that raw token works + Net::HTTP.start(proxy.host, proxy.port) do |http| + nego_auth = SSPI::NegotiateAuth.new + sr = http.request_get "http://www.google.com/", { "Proxy-Authorization" => "Negotiate " + nego_auth.get_initial_token } + token = Base64.decode64(sr["Proxy-Authenticate"].split(" ").last.strip) + completed_token = nego_auth.complete_authentication(token) + resp = http.get "http://www.google.com/", { "Proxy-Authorization" => "Negotiate " + completed_token } + assert resp.code.to_i == 200, "Response code not as expected: #{resp.inspect}" + end + + # Test that token w/ "Negotiate" header included works + Net::HTTP.start(proxy.host, proxy.port) do |http| + nego_auth = SSPI::NegotiateAuth.new + sr = http.request_get "http://www.google.com/", { "Proxy-Authorization" => "Negotiate " + nego_auth.get_initial_token } + resp = http.get "http://www.google.com/", { "Proxy-Authorization" => "Negotiate " + nego_auth.complete_authentication(sr["Proxy-Authenticate"]) } + assert resp.code.to_i == 200, "Response code not as expected: #{resp.inspect}" + end + end + +private + + # Gets the proxy from the environment and makes some assertions + def get_proxy + assert ENV["http_proxy"], "http_proxy environment variable must be set." + proxy = URI.parse(ENV["http_proxy"]) + assert proxy.host && proxy.port, "Could not parse http_proxy (#{ENV["http_proxy"]}). http_proxy should be a URL with a port (e.g. http://proxy.corp.com:8080)." + + return proxy + end + +end diff -N -u c:\ruby\src\ruby-1.8.4\test\net\http.1.8.5.preview1/test_gem_list.rb c:\ruby\src\ruby-1.8.4\test\net\http/test_gem_list.rb --- c:\ruby\src\ruby-1.8.4\test\net\http.1.8.5.preview1/test_gem_list.rb 1969-12-31 16:00:00.000000000 -0800 +++ c:\ruby\src\ruby-1.8.4\test\net\http/test_gem_list.rb 2006-07-20 15:13:23.736037300 -0700 @@ -0,0 +1,30 @@ +# +# = test/net/http/test_gem_list.rb +# +# Copyright (c) 2006 Justin Bailey +# +# Written and maintained by Justin Bailey . +# +# This program is free software. You can re-distribute and/or +# modify this program under the same terms of ruby itself --- +# Ruby Distribution License or GNU General Public License. + +require 'test/unit' +require 'net/http' +require 'rubygems' + +class NTLMTest < Test::Unit::TestCase + def setup + assert ENV["http_proxy"], "http_proxy must be set before running tests." + end + + # Previous implementation of rubysspi used dl/win32 and a + # bug occurred when gem list was executed. This tests to ensure + # bug does not come back. + def test_gem_list + Gem.manage_gems + assert_nothing_raised "'gem list --remote rubysspi' failed to execute" do + Gem::GemRunner.new.run(["list", "--remote", "rubysspi"]) + end + end +end diff -N -u c:\ruby\src\ruby-1.8.4\test\net\http.1.8.5.preview1/test_net_http.rb c:\ruby\src\ruby-1.8.4\test\net\http/test_net_http.rb --- c:\ruby\src\ruby-1.8.4\test\net\http.1.8.5.preview1/test_net_http.rb 1969-12-31 16:00:00.000000000 -0800 +++ c:\ruby\src\ruby-1.8.4\test\net\http/test_net_http.rb 2006-07-20 15:12:36.422931700 -0700 @@ -0,0 +1,31 @@ +# +# = test/net/http/test_net_http.rb +# +# Copyright (c) 2006 Justin Bailey +# +# Written and maintained by Justin Bailey . +# +# This program is free software. You can re-distribute and/or +# modify this program under the same terms of ruby itself --- +# Ruby Distribution License or GNU General Public License. + +require 'test/unit' +require 'net/http' + +class NTLMTest < Test::Unit::TestCase + def setup + assert ENV["http_proxy"], "http_proxy must be set before running tests." + end + + def test_net_http + + assert ENV["http_proxy"], "http_proxy environment variable must be set." + proxy = URI.parse(ENV["http_proxy"]) + assert proxy.host && proxy.port, "Could not parse http_proxy (#{ENV["http_proxy"]}). http_proxy should be a URL with a port (e.g. http://proxy.corp.com:8080)." + + Net::HTTP.Proxy(proxy.host, proxy.port).start("www.google.com") do |http| + resp = http.get("/") + assert resp.code.to_i == 200, "Did not get response from Google as expected." + end + end +end