ruby-openid 2.0.3 → 2.0.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of ruby-openid might be problematic. Click here for more details.

data/CHANGELOG CHANGED
@@ -1,60 +1,41 @@
1
- Fri Jan 11 11:31:29 PST 2008 cygnus@janrain.com
2
- tagged 2.0.3
3
-
4
- Fri Jan 11 11:29:57 PST 2008 cygnus@janrain.com
5
- * Set version to 2.0.3
6
-
7
- Thu Jan 10 15:23:31 PST 2008 Kevin Turner <kevin@janrain.com>
8
- * UPGRADE: formatting
9
-
10
- Thu Jan 10 15:18:17 PST 2008 Kevin Turner <kevin@janrain.com>
11
- * Consumer.Response: documentation for identity_url and display_identifier
12
-
13
- Too bad that rdoc doesn't automatically display this in the documentation for
14
- SuccessResponse; you have to follow the link to the Response docs.
15
-
16
- Tue Jan 8 16:14:56 PST 2008 Kevin Turner <kevin@janrain.com>
17
- * examples/discover: correct namespace of DiscoveryFailure
1
+ Tue Feb 12 18:02:31 PST 2008 Kevin Turner <kevin@janrain.com>
2
+ tagged 2.0.4
18
3
 
19
- Thu Jan 10 10:15:04 PST 2008 cygnus@janrain.com
20
- * Catch HTTPStatusError when making KV post in association manager
4
+ Tue Feb 12 18:01:44 PST 2008 Kevin Turner <kevin@janrain.com>
5
+ * set version to 2.0.4
21
6
 
22
- Wed Jan 9 17:39:53 PST 2008 cygnus@janrain.com
23
- * Fix FetchRequest.ns_uri
7
+ Tue Feb 12 17:49:53 PST 2008 Kevin Turner <kevin@janrain.com>
8
+ * HTMLTokenizer: raise OpenIDError instead of RuntimeError
24
9
 
25
- Wed Jan 9 17:02:49 PST 2008 cygnus@janrain.com
26
- * Fix FetchResponse.from_success_response, assign correct NS_URI value for AX messages
10
+ Thu Jan 31 11:34:11 PST 2008 Kevin Turner <kevin@janrain.com>
11
+ * Consumer.IdResHandler.verify_return_to_args: include more details in exception messages.
27
12
 
28
- Tue Jan 8 15:46:43 PST 2008 Kevin Turner <kevin@janrain.com>
29
- * examples/rails_openid/app/controllers: render_text was deprecated, use render :text.
13
+ Mon Jan 21 15:50:54 PST 2008 Kevin Turner <kevin@janrain.com>
14
+ * StandardFetcher.fetch: catch more exceptions to wrap in to FetchingErrors.
30
15
 
31
- Tue Jan 8 13:56:39 PST 2008 Kevin Turner <kevin@janrain.com>
32
- * Yadis.discover: add more information to exception messages.
16
+ Mon Jan 21 14:23:10 PST 2008 Kevin Turner <kevin@janrain.com>
17
+ * OpenID::normalize_url: urinorm raises URI::Error, not ArgumentError.
33
18
 
34
- Mon Jan 7 18:48:50 PST 2008 Kevin Turner <kevin@janrain.com>
35
- * OpenIDServiceEndpoint.display_identifier: leave off the fragment from claimed_id. [#99]
19
+ Tue Jan 15 11:48:49 PST 2008 rubys@intertwingly.net
20
+ * The following set of changes gets ruby-openid to work with Ruby 1.9,
21
+ revision 15006 and REXML revision 1301. The codebase with this
22
+ patch continues to work on Ruby 1.8.6.
36
23
 
37
- Tue Jan 8 09:32:27 PST 2008 http://j3h.us/
38
- * MalformedTrustRoot raised by the library now gets passed the OpenID Message object instead of nil
39
-
40
- Fri Dec 21 15:05:32 PST 2007 http://j3h.us/
41
- * whitespace
42
-
43
- Mon Jan 7 17:40:45 PST 2008 Kevin Turner <kevin@janrain.com>
44
- * Yadis: remove mkXRDTag, mkXRDSTag. These don't seem to make as much sense with REXML as they did with ElementTree.
45
-
46
- Mon Jan 7 17:33:41 PST 2008 Kevin Turner <kevin@janrain.com>
47
- * remove comment applicable to Python
24
+ Mon Jan 14 18:06:29 PST 2008 Kevin Turner <kevin@janrain.com>
25
+ * Consumer.complete_id_res: catch all OpenIDError instead of just DiscoveryFailure and ProtocolError. Fixes #104.
26
+
27
+ This seems to be the desired behavior.
28
+
29
+ IdResHandler.check_auth: don't bother casting an OpenIDError to another OpenIDError.
48
30
 
49
- Mon Jan 7 17:00:17 PST 2008 Kevin Turner <kevin@janrain.com>
50
- * test_xrds: add test for Yadis.get_canonical_id with subsegments [#93]
31
+ Mon Jan 14 17:59:38 PST 2008 Kevin Turner <kevin@janrain.com>
32
+ * OpenID::ServerError: add server_url to attributes.
51
33
 
52
- Fri Dec 28 16:25:19 PST 2007 Kevin Turner <kevin@janrain.com>
53
- * Yadis::get_canonical_id: fixes for delegated xris [#93]
54
- patch contributed by =masaki
34
+ Mon Jan 14 17:21:10 PST 2008 Kevin Turner <kevin@janrain.com>
35
+ * ProtocolError, ServerError: subclass OpenIDError
55
36
 
56
- Thu Jan 3 14:46:44 PST 2008 Kevin Turner <kevin@janrain.com>
57
- * examples/discover: correct fetcher_use_env_http_proxy
37
+ Mon Jan 14 17:20:01 PST 2008 Kevin Turner <kevin@janrain.com>
38
+ * UPGRADE: fix typo in example path
58
39
 
59
- Fri Dec 21 20:44:22 PST 2007 Kevin Turner <kevin@janrain.com>
60
- tagged 2.0.2
40
+ Fri Jan 11 11:31:29 PST 2008 cygnus@janrain.com
41
+ tagged 2.0.3
data/UPGRADE CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  The flow is largely the same, however there are a number of significant
6
6
  changes. The consumer example is helpful to look at:
7
- examples/ruby_openid/app/controllers/consumer_controller.rb
7
+ examples/rails_openid/app/controllers/consumer_controller.rb
8
8
 
9
9
 
10
10
  === Stores
@@ -223,7 +223,7 @@ module OpenID
223
223
  self.class.check_session_type(assoc_type, session_type)
224
224
  session_types = [session_type]
225
225
  end
226
- session_types.each do |session_type|
226
+ for session_type in session_types do
227
227
  @allowed_types << [assoc_type, session_type]
228
228
  end
229
229
  end
@@ -383,7 +383,7 @@ module OpenID
383
383
 
384
384
  begin
385
385
  idres = handle_idres(message, current_url)
386
- rescue DiscoveryFailure, ProtocolError => why
386
+ rescue OpenIDError => why
387
387
  return FailureResponse.new(last_requested_endpoint, why.message)
388
388
  else
389
389
  return SuccessResponse.new(idres.endpoint, message,
@@ -287,7 +287,7 @@ module OpenID
287
287
  expires_in = self.class.extract_expires_in(assoc_response)
288
288
 
289
289
  # OpenID 1 has funny association session behaviour.
290
- if assoc_response.is_openid1:
290
+ if assoc_response.is_openid1
291
291
  session_type = get_openid1_session_type(assoc_response)
292
292
  else
293
293
  session_type = assoc_response.get_arg(OPENID2_NS, 'session_type',
@@ -284,8 +284,8 @@ module OpenID
284
284
  # DiscoveryFailure
285
285
  begin
286
286
  normalized = URINorm.urinorm(url)
287
- rescue ArgumentError => why
288
- raise DiscoveryFailure.new(sprintf('Normalizing identifier: %s', why[0]), nil)
287
+ rescue URI::Error => why
288
+ raise DiscoveryFailure.new("Error normalizing #{url}: #{why.message}", nil)
289
289
  else
290
290
  defragged = URI::parse(normalized)
291
291
  defragged.fragment = nil
@@ -2,10 +2,8 @@ require "openid/yadis/htmltokenizer"
2
2
 
3
3
  module OpenID
4
4
 
5
- REFLAGS = Regexp::MULTILINE | Regexp::IGNORECASE | Regexp::EXTENDED
6
-
7
5
  # Stuff to remove before we start looking for tags
8
- REMOVED_RE = Regexp.compile('
6
+ REMOVED_RE = /
9
7
  # Comments
10
8
  <!--.*?-->
11
9
 
@@ -18,9 +16,9 @@ module OpenID
18
16
  # make sure script is not an XML namespace
19
17
  (?!:)
20
18
 
21
- [^>]*>.*?</script>
19
+ [^>]*>.*?<\/script>
22
20
 
23
- ', REFLAGS, 'u')
21
+ /mixu
24
22
 
25
23
  def OpenID.openid_unescape(s)
26
24
  s.gsub('&amp;','&').gsub('&lt;','<').gsub('&gt;','>').gsub('&quot;','"')
@@ -75,7 +73,7 @@ module OpenID
75
73
  end
76
74
 
77
75
  end
78
- rescue RuntimeError # just stop parsing if there's an error
76
+ rescue Exception # just stop parsing if there's an error
79
77
  end
80
78
  return links
81
79
  end
@@ -160,17 +160,28 @@ module OpenID
160
160
  return_to_parsed_query.each_pair do |rt_key, rt_val|
161
161
  msg_val = query[rt_key]
162
162
  if msg_val.nil?
163
- raise ProtocolError, "Message missing return_to argument #{rt_key}"
163
+ raise ProtocolError, "Message missing return_to argument '#{rt_key}'"
164
164
  elsif msg_val != rt_val
165
- raise ProtocolError, ("Parameter #{rt_key} value "\
165
+ raise ProtocolError, ("Parameter '#{rt_key}' value "\
166
166
  "#{msg_val.inspect} does not match "\
167
167
  "return_to's value #{rt_val.inspect}")
168
168
  end
169
169
  end
170
170
  @message.get_args(BARE_NS).each_pair do |bare_key, bare_val|
171
- if return_to_parsed_query[bare_key] != bare_val
172
- raise ProtocolError, ("Parameter #{bare_key} does not match "\
173
- "return_to URL")
171
+ rt_val = return_to_parsed_query[bare_key]
172
+ if not return_to_parsed_query.has_key? bare_key
173
+ # This may be caused by your web framework throwing extra
174
+ # entries in to your parameters hash that were not GET or
175
+ # POST parameters. For example, Rails has been known to
176
+ # add "controller" and "action" keys; another server adds
177
+ # at least a "format" key.
178
+ raise ProtocolError, ("Unexpected parameter (not on return_to): "\
179
+ "'#{bare_key}'=#{rt_val.inspect})")
180
+ end
181
+ if rt_val != bare_val
182
+ raise ProtocolError, ("Parameter '#{bare_key}' value "\
183
+ "#{bare_val.inspect} does not match "\
184
+ "return_to's value #{rt_val.inspect}")
174
185
  end
175
186
  end
176
187
  end
@@ -222,12 +233,7 @@ module OpenID
222
233
  "request: #{why.message}"
223
234
  end
224
235
 
225
- begin
226
- response = OpenID.make_kv_post(request, server_url)
227
- rescue ServerError => why
228
- raise ProtocolError, "Error from #{server_url} during "\
229
- "check_authentication: #{why.message}"
230
- end
236
+ response = OpenID.make_kv_post(request, server_url)
231
237
 
232
238
  process_check_auth_response(response)
233
239
  end
@@ -1,8 +1,12 @@
1
1
  require "openid/util"
2
2
  require "digest/sha1"
3
3
  require "digest/sha2"
4
- require "hmac/sha1"
5
- require "hmac/sha2"
4
+ begin
5
+ require "digest/hmac"
6
+ rescue LoadError
7
+ require "hmac/sha1"
8
+ require "hmac/sha2"
9
+ end
6
10
 
7
11
  module OpenID
8
12
  # This module contains everything needed to perform low-level
@@ -26,7 +30,11 @@ module OpenID
26
30
  end
27
31
 
28
32
  def CryptUtil.hmac_sha1(key, text)
29
- return HMAC::SHA1.digest(key, text)
33
+ if Digest.const_defined? :HMAC
34
+ Digest::HMAC.new(key,Digest::SHA1).update(text).digest
35
+ else
36
+ return HMAC::SHA1.digest(key, text)
37
+ end
30
38
  end
31
39
 
32
40
  def CryptUtil.sha256(text)
@@ -34,7 +42,11 @@ module OpenID
34
42
  end
35
43
 
36
44
  def CryptUtil.hmac_sha256(key, text)
37
- return HMAC::SHA256.digest(key, text)
45
+ if Digest.const_defined? :HMAC
46
+ Digest::HMAC.new(key,Digest::SHA256).update(text).digest
47
+ else
48
+ return HMAC::SHA256.digest(key, text)
49
+ end
38
50
  end
39
51
 
40
52
  # Generate a random string of the given length, composed of the
data/lib/openid/dh.rb CHANGED
@@ -56,9 +56,13 @@ module OpenID
56
56
  "Inputs were #{s.inspect} and #{t.inspect}"
57
57
  end
58
58
 
59
- indices = 0...(s.length)
60
- chrs = indices.collect {|i| (s[i]^t[i]).chr}
61
- chrs.join("")
59
+ if String.method_defined? :bytes
60
+ s.bytes.zip(t.bytes).map{|sb,tb| sb^tb}.pack('C*')
61
+ else
62
+ indices = 0...(s.length)
63
+ chrs = indices.collect {|i| (s[i]^t[i]).chr}
64
+ chrs.join("")
65
+ end
62
66
  end
63
67
 
64
68
  # This code is taken from this post:
@@ -133,7 +133,7 @@ module OpenID
133
133
  end
134
134
  if nist_level and nist_level >= 0 and nist_level < 5
135
135
  @nist_auth_level = nist_level
136
- elsif strict:
136
+ elsif strict
137
137
  raise ArgumentError, "nist_auth_level must be an integer 0 through 4, not #{nist_level_str.inspect}"
138
138
  end
139
139
  end
@@ -194,7 +194,8 @@ module OpenID
194
194
 
195
195
  # Add the given list of fields to the request.
196
196
  def request_fields(field_names, required = false, strict = false)
197
- raise ArgumentError unless field_names[0].is_a?(String)
197
+ raise ArgumentError unless field_names.respond_to?(:each) and
198
+ field_names[0].is_a?(String)
198
199
  field_names.each{|fn|request_field(fn, required, strict)}
199
200
  end
200
201
 
@@ -112,7 +112,7 @@ module OpenID
112
112
 
113
113
  class StandardFetcher
114
114
 
115
- USER_AGENT = "ruby-openid/#{OpenID::VERSION} (#{PLATFORM})"
115
+ USER_AGENT = "ruby-openid/#{OpenID::VERSION} (#{RUBY_PLATFORM})"
116
116
 
117
117
  REDIRECT_LIMIT = 5
118
118
 
@@ -196,6 +196,12 @@ module OpenID
196
196
  }
197
197
  rescue OpenSSL::SSL::SSLError => why
198
198
  raise SSLFetchingError, "Error connecting to SSL URL #{url}: #{why}"
199
+ rescue FetchingError => why
200
+ raise why
201
+ rescue Exception => why
202
+ # Things we've caught here include a Timeout::Error, which descends
203
+ # from SignalException.
204
+ raise FetchingError, "Error fetching #{url}: #{why}"
199
205
  end
200
206
 
201
207
  case response
data/lib/openid/kvpost.rb CHANGED
@@ -4,21 +4,22 @@ require "openid/fetchers"
4
4
  module OpenID
5
5
  # Exception that is raised when the server returns a 400 response
6
6
  # code to a direct request.
7
- class ServerError < Exception
7
+ class ServerError < OpenIDError
8
8
  attr_reader :error_text, :error_code, :message
9
9
 
10
- def initialize(error_text, error_code, message)
10
+ def initialize(error_text, error_code, message, server_url)
11
11
  super(error_text)
12
12
  @error_text = error_text
13
13
  @error_code = error_code
14
+ @server_url = server_url
14
15
  @message = message
15
16
  end
16
17
 
17
- def self.from_message(msg)
18
+ def self.from_message(msg, server_url)
18
19
  error_text = msg.get_arg(OPENID_NS, 'error',
19
20
  '<no error message supplied>')
20
21
  error_code = msg.get_arg(OPENID_NS, 'error_code')
21
- return self.new(error_text, error_code, msg)
22
+ return self.new(error_text, error_code, msg, server_url)
22
23
  end
23
24
  end
24
25
 
@@ -34,7 +35,7 @@ module OpenID
34
35
  when 200
35
36
  return msg
36
37
  when 400
37
- raise ServerError.from_message(msg)
38
+ raise ServerError.from_message(msg, server_url)
38
39
  else
39
40
  error_message = "bad status code from server #{server_url}: "\
40
41
  "#{response.code}"
@@ -1,6 +1,8 @@
1
+ require 'openid/util'
2
+
1
3
  module OpenID
2
4
 
3
5
  # An error in the OpenID protocol
4
- class ProtocolError < Exception
6
+ class ProtocolError < OpenIDError
5
7
  end
6
8
  end
data/lib/openid/server.rb CHANGED
@@ -430,7 +430,7 @@ module OpenID
430
430
  # mode:: +checkid_immediate+ or +checkid_setup+
431
431
  attr_accessor :mode
432
432
 
433
- attr_accessor :return_to, :op_endpoint
433
+ attr_accessor :op_endpoint
434
434
 
435
435
  # These parameters are assigned directly as attributes,
436
436
  # see the #CheckIDRequest class documentation for their
@@ -174,7 +174,7 @@ module OpenID
174
174
  end
175
175
 
176
176
  def cleanup_associations
177
- association_filenames = Dir[@association_dir.join("*")]
177
+ association_filenames = Dir[@association_dir.join("*").to_s]
178
178
  count = 0
179
179
  association_filenames.each do |af|
180
180
  begin
@@ -204,7 +204,7 @@ module OpenID
204
204
  end
205
205
 
206
206
  def cleanup_nonces
207
- nonces = Dir[@nonce_dir.join("*")]
207
+ nonces = Dir[@nonce_dir.join("*").to_s]
208
208
  now = Time.now.to_i
209
209
 
210
210
  count = 0
data/lib/openid/util.rb CHANGED
@@ -1,4 +1,3 @@
1
- require "base64"
2
1
  require "cgi"
3
2
  require "uri"
4
3
  require "logger"
@@ -12,7 +11,7 @@ module OpenID
12
11
  class AssertionError < Exception
13
12
  end
14
13
 
15
- VERSION = "2.0.3"
14
+ VERSION = "2.0.4"
16
15
 
17
16
  # Exceptions that are raised by the library are subclasses of this
18
17
  # exception type, so if you want to catch all exceptions raised by
@@ -38,7 +37,7 @@ module OpenID
38
37
  end
39
38
 
40
39
  def Util.to_base64(s)
41
- Base64.encode64(s).gsub("\n", "")
40
+ [s].pack('m').gsub("\n", "")
42
41
  end
43
42
 
44
43
  def Util.from_base64(s)
@@ -46,7 +45,7 @@ module OpenID
46
45
  if !BASE64_RE.match(without_newlines)
47
46
  raise ArgumentError, "Malformed input: #{s.inspect}"
48
47
  end
49
- Base64.decode64(without_newlines)
48
+ without_newlines.unpack('m').first
50
49
  end
51
50
 
52
51
  def Util.urlencode(args)
@@ -74,7 +74,7 @@ class HTMLTokenizer
74
74
  # Token is a comment
75
75
  tag_end = @page.index('-->', (@cur_pos + 1))
76
76
  if tag_end.nil?
77
- raise "No end found to started comment:\n#{@page[@cur_pos,80]}"
77
+ raise OpenIDError, "No end found to started comment:\n#{@page[@cur_pos,80]}"
78
78
  end
79
79
  # p @page[@cur_pos .. (tag_end+2)]
80
80
  HTMLComment.new(@page[@cur_pos .. (tag_end + 2)])
@@ -82,7 +82,7 @@ class HTMLTokenizer
82
82
  # Token is a html tag
83
83
  tag_end = @page.index('>', (@cur_pos + 1))
84
84
  if tag_end.nil?
85
- raise "No end found to started tag:\n#{@page[@cur_pos,80]}"
85
+ raise OpenIDError, "No end found to started tag:\n#{@page[@cur_pos,80]}"
86
86
  end
87
87
  # p @page[@cur_pos .. tag_end]
88
88
  HTMLTag.new(@page[@cur_pos .. tag_end])
@@ -209,7 +209,7 @@ class HTMLComment < HTMLToken
209
209
  super(text)
210
210
  temp_arr = text.scan(/^<!--\s*(.*?)\s*-->$/m)
211
211
  if temp_arr[0].nil?
212
- raise "Text passed to HTMLComment.initialize is not a comment"
212
+ raise OpenIDError, "Text passed to HTMLComment.initialize is not a comment"
213
213
  end
214
214
 
215
215
  @contents = temp_arr[0][0]
@@ -222,7 +222,7 @@ class HTMLTag < HTMLToken
222
222
  def initialize(text)
223
223
  super(text)
224
224
  if ?< != text[0] or ?> != text[-1]
225
- raise "Text passed to HTMLComment.initialize is not a comment"
225
+ raise OpenIDError, "Text passed to HTMLComment.initialize is not a comment"
226
226
  end
227
227
 
228
228
  @attr_hash = Hash.new
@@ -230,7 +230,7 @@ class HTMLTag < HTMLToken
230
230
 
231
231
  tag_name = text.scan(/[\w:-]+/)[0]
232
232
  if tag_name.nil?
233
- raise "Error, tag is nil: #{tag_name}"
233
+ raise OpenIDError, "Error, tag is nil: #{tag_name}"
234
234
  end
235
235
 
236
236
  if ?/ == text[1]
@@ -15,7 +15,7 @@ module OpenID
15
15
  return nil if ['/head', 'body', '/body'].member?(el.tag_name)
16
16
 
17
17
  if el.tag_name == 'head'
18
- unless el.to_s[-2] == 47 # tag ends with a /: a short tag
18
+ unless el.to_s[-2] == ?/ # tag ends with a /: a short tag
19
19
  in_head = true
20
20
  end
21
21
  end
@@ -279,7 +279,7 @@ module OpenID
279
279
  def request_association(assoc_type, session_type)
280
280
  m = @responses.shift
281
281
  if m.is_a?(Message)
282
- raise ServerError.from_message(m)
282
+ raise ServerError.from_message(m, nil)
283
283
  else
284
284
  return m
285
285
  end
@@ -7,9 +7,6 @@ require "util"
7
7
  module OpenID
8
8
  class Consumer
9
9
  class CheckIDRequest
10
- # For testing
11
- attr_reader :message
12
-
13
10
  class DummyEndpoint
14
11
  attr_accessor :preferred_namespace, :local_id, :server_url,
15
12
  :is_op_identifier, :claimed_id
@@ -100,7 +100,7 @@ module OpenID
100
100
 
101
101
  consumer = Consumer.new(@session, nil)
102
102
  consumer.extend(InstanceDefExtension)
103
- consumer.instance_def(:association_manager) do
103
+ consumer.instance_def(:association_manager) do |service|
104
104
  assoc_manager
105
105
  end
106
106
  consumer
@@ -1,5 +1,7 @@
1
+ # coding: ASCII-8BIT
1
2
  require 'test/unit'
2
3
  require "openid/cryptutil"
4
+ require "pathname"
3
5
 
4
6
  class CryptUtilTestCase < Test::Unit::TestCase
5
7
  BIG = 2 ** 256
@@ -777,4 +777,13 @@ module OpenID
777
777
  assert_equal 'http://recycled.invalid/', @endpoint.display_identifier
778
778
  end
779
779
  end
780
+
781
+
782
+ class TestNormalizeURL < Test::Unit::TestCase
783
+ def test_no_host
784
+ assert_raise(DiscoveryFailure) {
785
+ OpenID::normalize_url('http:///too-many.invalid/slashes')
786
+ }
787
+ end
788
+ end
780
789
  end
@@ -266,6 +266,11 @@ EOF
266
266
  class FakeConnection < Net::HTTP
267
267
  attr_reader :use_ssl, :ca_file
268
268
 
269
+ def initialize *args
270
+ super
271
+ @ca_file = nil
272
+ end
273
+
269
274
  def use_ssl=(v)
270
275
  @use_ssl = v
271
276
  end
@@ -362,7 +367,26 @@ EOF
362
367
  }
363
368
  end
364
369
 
365
- class TestingException < Exception; end
370
+ class TimeoutConnection
371
+ def start(&block)
372
+ raise Timeout::Error
373
+ end
374
+ end
375
+
376
+ def test_fetchingerror
377
+ f = OpenID::StandardFetcher.new
378
+
379
+ f.extend(OpenID::InstanceDefExtension)
380
+ f.instance_def(:make_connection) do |uri|
381
+ TimeoutConnection.new
382
+ end
383
+
384
+ assert_raise(OpenID::FetchingError) {
385
+ f.fetch("https://bogus.com/")
386
+ }
387
+ end
388
+
389
+ class TestingException < OpenID::FetchingError; end
366
390
 
367
391
  class NoSSLSupportConnection
368
392
  def supports_ssl?
@@ -420,7 +444,7 @@ EOF
420
444
  }
421
445
  end
422
446
 
423
- class PostConnectionCheckException < Exception; end
447
+ class PostConnectionCheckException < OpenID::FetchingError; end
424
448
 
425
449
  class UseSSLConnection < NoSSLSupportConnection
426
450
  def use_ssl?
@@ -473,13 +497,20 @@ end
473
497
 
474
498
  class ProxyTest < Test::Unit::TestCase
475
499
  def test_proxy_unreachable
476
- assert_raise(Errno::ECONNREFUSED) {
500
+ begin
477
501
  f = OpenID::StandardFetcher.new('127.0.0.1', 1)
478
502
  # If this tries to connect to the proxy (on port 1), I expect
479
503
  # a 'connection refused' error. If it tries to contact the below
480
504
  # URI first, it will get some other sort of error.
481
505
  f.fetch("http://unittest.invalid")
482
- }
506
+ rescue OpenID::FetchingError => why
507
+ # XXX: Is this a translatable string that is going to break?
508
+ if why.message =~ /Connection refused/
509
+ return
510
+ end
511
+ raise why
512
+ end
513
+ flunk "expected Connection Refused, but it passed."
483
514
  end
484
515
 
485
516
  def test_proxy_env
data/test/test_filters.rb CHANGED
@@ -84,28 +84,28 @@ module OpenID
84
84
 
85
85
  def test_nil_filter
86
86
  # A transform filter with a single nil filter should return nil.
87
- endpoint = "unused"
88
87
  nil_filter = Proc.new { |endpoint| nil }
89
88
  t = Yadis::TransformFilterMaker.new([nil_filter])
89
+ endpoint = "unused"
90
90
  assert(t.apply_filters(endpoint).nil?)
91
91
  end
92
92
 
93
93
  def test_identity_filter
94
94
  # A transform filter with an identity filter should return the
95
95
  # input.
96
- endpoint = "unused"
97
96
  identity_filter = Proc.new { |endpoint| endpoint }
98
97
  t = Yadis::TransformFilterMaker.new([identity_filter])
98
+ endpoint = "unused"
99
99
  assert(t.apply_filters(endpoint) == endpoint)
100
100
  end
101
101
 
102
102
  def test_return_different_endpoint
103
103
  # Make sure the result of the filter is returned, rather than
104
104
  # the input.
105
- endpoint = "unused"
106
105
  returned_endpoint = "returned endpoint"
107
106
  filter = Proc.new { |endpoint| returned_endpoint }
108
107
  t = Yadis::TransformFilterMaker.new([filter])
108
+ endpoint = "unused"
109
109
  assert(t.apply_filters(endpoint) == returned_endpoint)
110
110
  end
111
111
 
data/test/test_idres.rb CHANGED
@@ -145,7 +145,7 @@ module OpenID
145
145
  end
146
146
 
147
147
  def test_unexpected_arg_okay
148
- assert_bad_args("Parameter foo does", {
148
+ assert_bad_args("Unexpected parameter", {
149
149
  'openid.mode' => 'id_res',
150
150
  'openid.return_to' => 'http://example.com/',
151
151
  'foo' => 'bar',
@@ -158,7 +158,7 @@ module OpenID
158
158
  'openid.return_to' => 'http://example.com/?foo=bar',
159
159
  })
160
160
 
161
- assert_bad_args('Parameter foo val', {
161
+ assert_bad_args("Parameter 'foo' val", {
162
162
  'openid.mode' => 'id_res',
163
163
  'openid.return_to' => 'http://example.com/?foo=bar',
164
164
  'foo' => 'foos',
@@ -314,22 +314,6 @@ module OpenID
314
314
  }
315
315
  end
316
316
 
317
- def test_kv_server_error
318
- OpenID.extend(OverrideMethodMixin)
319
- send_error = lambda do |req, server_url|
320
- msg = Message.new(OPENID2_NS)
321
- raise ServerError.from_message(msg), 'For you!'
322
- end
323
-
324
- OpenID.with_method_overridden(:make_kv_post, send_error) do
325
- assert_protocol_error("Error from") {
326
- call_check_auth do |idres|
327
- idres.instance_def(:create_check_auth_request) { nil }
328
- end
329
- }
330
- end
331
- end
332
-
333
317
  def test_check_auth_okay
334
318
  OpenID.extend(OverrideMethodMixin)
335
319
  me = self
@@ -619,7 +603,9 @@ module OpenID
619
603
  'identity' => 'sour grapes',
620
604
  'claimed_id' => 'monkeysoft',
621
605
  'op_endpoint' => 'Phone Home'}) do |idres|
622
- idres.instance_def(:discover_and_verify) {@endpoint = endpoint}
606
+ idres.instance_def(:discover_and_verify) do |to_match|
607
+ @endpoint = endpoint
608
+ end
623
609
  end
624
610
  }
625
611
  assert(endpoint.equal?(result))
@@ -640,7 +626,9 @@ module OpenID
640
626
  'claimed_id' => 'monkeysoft',
641
627
  'op_endpoint' => 'Green Cheese'}) do |idres|
642
628
  idres.extend(InstanceDefExtension)
643
- idres.instance_def(:discover_and_verify) {@endpoint = endpoint}
629
+ idres.instance_def(:discover_and_verify) do |to_match|
630
+ @endpoint = endpoint
631
+ end
644
632
  end
645
633
  }
646
634
  assert(endpoint.equal?(result))
@@ -721,7 +709,7 @@ module OpenID
721
709
  assert_raises(verified_error) {
722
710
  call_verify_modify({'ns' => OPENID1_NS,
723
711
  'identity' => @endpoint.local_id}) { |idres|
724
- idres.instance_def(:discover_and_verify) do
712
+ idres.instance_def(:discover_and_verify) do |to_match|
725
713
  raise verified_error
726
714
  end
727
715
  }
@@ -6,8 +6,8 @@ class LinkParseTestCase < Test::Unit::TestCase
6
6
  include OpenID::TestDataMixin
7
7
 
8
8
  def attr_cmp(expected, found)
9
- e = expected.to_a
10
- f = found.to_a
9
+ e = expected.to_a.sort
10
+ f = found.to_a.sort
11
11
  while (ep = e.shift)
12
12
  ek, ev = ep
13
13
  fk, fv = f.shift
data/test/test_server.rb CHANGED
@@ -1784,7 +1784,7 @@ module OpenID
1784
1784
  monkeycalled = Counter.new()
1785
1785
 
1786
1786
  @server.extend(InstanceDefExtension)
1787
- @server.instance_def(:openid_monkeymode) do
1787
+ @server.instance_def(:openid_monkeymode) do |request|
1788
1788
  raise UnhandledError
1789
1789
  end
1790
1790
 
data/test/test_sreg.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'openid/extensions/sreg'
2
2
  require 'openid/message'
3
3
  require 'openid/server'
4
+ require 'test/unit'
4
5
 
5
6
  module OpenID
6
7
  module SReg
data/test/test_util.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # coding: ASCII-8BIT
1
2
  require 'test/unit'
2
3
 
3
4
  require "openid/util"
data/test/testutil.rb CHANGED
@@ -63,12 +63,20 @@ module OpenID
63
63
  def with_method_overridden(method_name, proc)
64
64
  original = method(method_name)
65
65
  begin
66
+ # TODO: find a combination of undef calls which prevent the warning
67
+ verbose, $VERBOSE = $VERBOSE, false
66
68
  define_method(method_name, proc)
67
69
  module_function(method_name)
70
+ $VERBOSE = verbose
68
71
  yield
69
72
  ensure
70
- define_method(method_name, original)
71
- module_function(method_name)
73
+ if original.respond_to? :owner
74
+ original.owner.send(:undef_method, method_name)
75
+ original.owner.send :define_method, method_name, original
76
+ else
77
+ define_method(method_name, original)
78
+ module_function(method_name)
79
+ end
72
80
  end
73
81
  end
74
82
  end
@@ -84,7 +92,10 @@ module OpenID
84
92
  module InstanceDefExtension
85
93
  def instance_def(method_name, &proc)
86
94
  (class << self;self;end).instance_eval do
95
+ # TODO: find a combination of undef calls which prevent the warning
96
+ verbose, $VERBOSE = $VERBOSE, false
87
97
  define_method(method_name, proc)
98
+ $VERBOSE = verbose
88
99
  end
89
100
  end
90
101
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: ruby-openid
5
5
  version: !ruby/object:Gem::Version
6
- version: 2.0.3
7
- date: 2008-01-11 00:00:00 -08:00
6
+ version: 2.0.4
7
+ date: 2008-02-13 00:00:00 -08:00
8
8
  summary: A library for consuming and serving OpenID identities.
9
9
  require_paths:
10
10
  - lib