rubysspi 1.0.0-i386-mswin32 → 1.0.3-i386-mswin32

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,11 +1,12 @@
1
1
  require 'rubygems'
2
2
  Gem::manage_gems
3
3
  require 'rake/gempackagetask'
4
+ require 'rake/testtask'
4
5
 
5
6
  spec = Gem::Specification.new do |s|
6
7
  s.name = "rubysspi"
7
8
  s.summary = "A library which implements Ruby bindings to the Win32 SSPI library. Also includes a module to add Negotate authentication support to Net::HTTP."
8
- s.version = "1.0.0"
9
+ s.version = "1.0.3"
9
10
  s.author = "Justin Bailey"
10
11
  s.email = "jgbailey @nospam@ gmail.com"
11
12
  s.homepage = "http://rubyforge.org/projects/rubysspi/"
@@ -1,7 +1,6 @@
1
1
  require 'net/http'
2
2
  require 'rubysspi'
3
3
 
4
-
5
4
  module Net
6
5
  # Replaces Net::HTTP.request to understand Negotiate HTTP proxy authorization. Uses native Win32
7
6
  # libraries to authentic as the current user (as defined by the ENV["USERNAME"] and ENV["USERDOMAIN"]
@@ -28,20 +27,28 @@ module Net
28
27
  end while res.kind_of?(HTTPContinue)
29
28
  # If proxy was specified, and the server is demanding authentication, negotiate with it
30
29
  if res.kind_of?(HTTPProxyAuthenticationRequired) && proxy? && res["Proxy-Authenticate"].include?("Negotiate")
31
- n = SSPI::NegotiateAuth.new
32
- res.reading_body(@socket, req.response_body_permitted?) { }
33
- req["Proxy-Authorization"] = "Negotiate #{n.get_initial_token}"
34
- req.exec @socket, @curr_http_version, edit_path(req.path)
35
30
  begin
36
- res = HTTPResponse.read_new(@socket)
37
- end while res.kind_of?(HTTPContinue)
38
- if res["Proxy-Authenticate"]
31
+ n = SSPI::NegotiateAuth.new
39
32
  res.reading_body(@socket, req.response_body_permitted?) { }
40
- req["Proxy-Authorization"] = "Negotiate #{n.complete_authentication res["Proxy-Authenticate"]}"
33
+ end_transport req, res
34
+ begin_transport req
35
+ req["Proxy-Authorization"] = "Negotiate #{n.get_initial_token}"
41
36
  req.exec @socket, @curr_http_version, edit_path(req.path)
42
37
  begin
43
38
  res = HTTPResponse.read_new(@socket)
44
39
  end while res.kind_of?(HTTPContinue)
40
+ if res["Proxy-Authenticate"]
41
+ res.reading_body(@socket, req.response_body_permitted?) { }
42
+ req["Proxy-Authorization"] = "Negotiate #{n.complete_authentication res["Proxy-Authenticate"]}"
43
+ req.exec @socket, @curr_http_version, edit_path(req.path)
44
+ begin
45
+ res = HTTPResponse.read_new(@socket)
46
+ end while res.kind_of?(HTTPContinue)
47
+ end
48
+ rescue
49
+ exc = $!.exception("Error occurred during proxy negotiation. socket.io: #{@socket.inspect}; socket.closed? #{@socket.closed?}; req: #{req.inspect}; res: #{res.inspect}; Original message: #{$!.message}")
50
+ exc.set_backtrace $!.backtrace
51
+ raise exc
45
52
  end
46
53
  end
47
54
  res.reading_body(@socket, req.response_body_permitted?) {
@@ -15,9 +15,11 @@ class NTLMTest < Test::Unit::TestCase
15
15
  nego_auth = SSPI::NegotiateAuth.new
16
16
  sr = http.request_get "/", { "Proxy-Authorization" => "Negotiate " + nego_auth.get_initial_token }
17
17
  resp = http.get "/", { "Proxy-Authorization" => "Negotiate " + nego_auth.complete_authentication(sr["Proxy-Authenticate"].split(" ").last.strip) }
18
- assert resp.code.to_i == 200, "Resposne code not as expected: #{resp.inspect}"
18
+ # Google redirects to country of origins domain if not US.
19
+ assert success_or_redirect(resp.code), "Response code not as expected: #{resp.inspect}"
19
20
  resp = http.get "/foobar.html"
20
- assert resp.code.to_i == 404, "Response code not as expected: #{resp.inspect}"
21
+ # Some proxy servers don't return 404 but 407.
22
+ assert(resp.code.to_i == 404 || resp.code.to_i == 407, "Response code not as expected: #{resp.inspect}")
21
23
  end
22
24
  end
23
25
 
@@ -26,7 +28,7 @@ class NTLMTest < Test::Unit::TestCase
26
28
 
27
29
  Net::HTTP.Proxy(proxy.host, proxy.port).start("www.google.com") do |http|
28
30
  resp = SSPI::NegotiateAuth.proxy_auth_get http, "/"
29
- assert resp.code.to_i == 200, "Response code not as expected: #{resp.inspect}"
31
+ assert success_or_redirect(resp.code), "Response code not as expected: #{resp.inspect}"
30
32
  end
31
33
  end
32
34
 
@@ -37,7 +39,7 @@ class NTLMTest < Test::Unit::TestCase
37
39
  nego_auth = SSPI::NegotiateAuth.new
38
40
  sr = http.request_get "/", { "Proxy-Authorization" => "Negotiate " + nego_auth.get_initial_token }
39
41
  resp = http.get "/", { "Proxy-Authorization" => "Negotiate " + nego_auth.complete_authentication(sr["Proxy-Authenticate"].split(" ").last.strip) }
40
- assert resp.code.to_i == 200, "Response code not as expected: #{resp.inspect}"
42
+ assert success_or_redirect(resp.code), "Response code not as expected: #{resp.inspect}"
41
43
  assert_raises(RuntimeError, "Should not be able to call complete_authentication again") do
42
44
  nego_auth.complete_authentication "foo"
43
45
  end
@@ -54,7 +56,7 @@ class NTLMTest < Test::Unit::TestCase
54
56
  token = Base64.decode64(sr["Proxy-Authenticate"].split(" ").last.strip)
55
57
  completed_token = nego_auth.complete_authentication(token)
56
58
  resp = http.get "/", { "Proxy-Authorization" => "Negotiate " + completed_token }
57
- assert resp.code.to_i == 200, "Response code not as expected: #{resp.inspect}"
59
+ assert success_or_redirect(resp.code), "Response code not as expected: #{resp.inspect}"
58
60
  end
59
61
 
60
62
  # Test that token w/ "Negotiate" header included works
@@ -62,7 +64,7 @@ class NTLMTest < Test::Unit::TestCase
62
64
  nego_auth = SSPI::NegotiateAuth.new
63
65
  sr = http.request_get "/", { "Proxy-Authorization" => "Negotiate " + nego_auth.get_initial_token }
64
66
  resp = http.get "/", { "Proxy-Authorization" => "Negotiate " + nego_auth.complete_authentication(sr["Proxy-Authenticate"]) }
65
- assert resp.code.to_i == 200, "Response code not as expected: #{resp.inspect}"
67
+ assert success_or_redirect(resp.code), "Response code not as expected: #{resp.inspect}"
66
68
  end
67
69
  end
68
70
 
@@ -77,4 +79,9 @@ private
77
79
  return proxy
78
80
  end
79
81
 
82
+ # Returns true if code given is 200 or 302. I.e. if HTTP request was successful or resulted in redirect.
83
+ def success_or_redirect(code)
84
+ code.to_i == 200 || code.to_i == 302
85
+ end
86
+
80
87
  end
@@ -15,7 +15,7 @@ class NTLMTest < Test::Unit::TestCase
15
15
  def test_gem_list
16
16
  Gem.manage_gems
17
17
  assert_nothing_raised "'gem list --remote rubysspi' failed to execute" do
18
- Gem::GemRunner.new.run(["list", "--remote", "rubysspi"])
18
+ Gem::GemRunner.new.run(%w(list rubysspi --remote --http-proxy ))
19
19
  end
20
20
  end
21
21
  end
@@ -1,3 +1,5 @@
1
+ DISABLE_RUBY_SSPI_PATCH = true
2
+
1
3
  require 'test/unit'
2
4
  require 'net/http'
3
5
  require 'pathname'
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: rubysspi
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.0.0
7
- date: 2006-09-28 00:00:00 -07:00
6
+ version: 1.0.3
7
+ date: 2006-10-16 00:00:00 -07:00
8
8
  summary: A library which implements Ruby bindings to the Win32 SSPI library. Also includes a module to add Negotate authentication support to Net::HTTP.
9
9
  require_paths:
10
10
  - lib