From c779d1033cf5b674191a123d0d36ca5dc25c17cd Mon Sep 17 00:00:00 2001 From: Mike Mell Date: Fri, 14 May 2010 10:09:18 -0700 Subject: [PATCH 01/22] The method name was incorrect -- should be signed? not singed? --- lib/openid/consumer/responses.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/openid/consumer/responses.rb b/lib/openid/consumer/responses.rb index 91262398..4947c1ca 100644 --- a/lib/openid/consumer/responses.rb +++ b/lib/openid/consumer/responses.rb @@ -83,7 +83,7 @@ def signed?(ns_uri, ns_key) # Return the specified signed field if available, otherwise # return default def get_signed(ns_uri, ns_key, default=nil) - if singed?(ns_uri, ns_key) + if signed?(ns_uri, ns_key) return @message.get_arg(ns_uri, ns_key, default) else return default From e4af6431af12b91e5ef04a6e94ef959ceff692d0 Mon Sep 17 00:00:00 2001 From: Mike Mell Date: Fri, 14 May 2010 10:11:41 -0700 Subject: [PATCH 02/22] When the iname is in the url (e.g. http://example.com/consumer/=mary) the Rails :id must be nullified so that the realm is valid. --- examples/rails_openid/app/controllers/consumer_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/rails_openid/app/controllers/consumer_controller.rb b/examples/rails_openid/app/controllers/consumer_controller.rb index 37dd3bbd..a42b2724 100644 --- a/examples/rails_openid/app/controllers/consumer_controller.rb +++ b/examples/rails_openid/app/controllers/consumer_controller.rb @@ -46,7 +46,7 @@ def start oidreq.return_to_args['force_post']='x'*2048 end return_to = url_for :action => 'complete', :only_path => false - realm = url_for :action => 'index', :only_path => false + realm = url_for :action => 'index', :id => nil, :only_path => false if oidreq.send_redirect?(realm, return_to, params[:immediate]) redirect_to oidreq.redirect_url(realm, return_to, params[:immediate]) From 4a17c08e8496362093e640716026ac332e74a23f Mon Sep 17 00:00:00 2001 From: Mike Mell Date: Fri, 14 May 2010 10:12:45 -0700 Subject: [PATCH 03/22] The local_id is a canonical_id at the OP when the local_id is an iname at the RP. Matching claimed_ids instead of local_ids resolves the incompatibility. --- lib/openid/consumer/idres.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/openid/consumer/idres.rb b/lib/openid/consumer/idres.rb index 8ef9e384..62d62643 100644 --- a/lib/openid/consumer/idres.rb +++ b/lib/openid/consumer/idres.rb @@ -492,10 +492,10 @@ def verify_discovery_single(endpoint, to_match) "#{endpoint.claimed_id}") end - if to_match.get_local_id != endpoint.get_local_id - raise ProtocolError, ("local_id mismatch. Expected "\ - "#{to_match.get_local_id}, got "\ - "#{endpoint.get_local_id}") + if to_match.claimed_id != endpoint.claimed_id + raise ProtocolError, ("claimed_id mismatch. Expected "\ + "#{to_match.claimed_id}, got "\ + "#{endpoint.claimed_id}") end # If the server URL is nil, this must be an OpenID 1 @@ -512,7 +512,7 @@ def verify_discovery_single(endpoint, to_match) "`to_match' endpoint." end elsif to_match.server_url != endpoint.server_url - raise ProtocolError, ("OP Endpoint mismatch. Expected"\ + raise ProtocolError, ("OP Endpoint mismatch. Expected "\ "#{to_match.server_url}, got "\ "#{endpoint.server_url}") end From 9ca25326b4908cb895eb9a9dccc88af6cb58f1ed Mon Sep 17 00:00:00 2001 From: Mike Mell Date: Fri, 14 May 2010 10:15:08 -0700 Subject: [PATCH 04/22] The Rails memcached calls are read/write, not get/set. add and delete do not exist. Expiry is set with the :expires_in option. --- lib/openid/store/memcache.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/openid/store/memcache.rb b/lib/openid/store/memcache.rb index bb4b106a..405d7e82 100644 --- a/lib/openid/store/memcache.rb +++ b/lib/openid/store/memcache.rb @@ -21,7 +21,7 @@ def store_association(server_url, association) serialized = serialize(association) [nil, association.handle].each do |handle| key = assoc_key(server_url, handle) - @cache_client.set(key, serialized, expiry(association.lifetime)) + @cache_client.write(key, serialized, :expires_in => association.lifetime.seconds) end end @@ -30,7 +30,7 @@ def store_association(server_url, association) # the one matching association is expired. (Is allowed to GC expired # associations when found.) def get_association(server_url, handle=nil) - serialized = @cache_client.get(assoc_key(server_url, handle)) + serialized = @cache_client.read(assoc_key(server_url, handle)) if serialized return deserialize(serialized) else @@ -62,8 +62,9 @@ def use_nonce(server_url, timestamp, salt) return false if (timestamp - Time.now.to_i).abs > Nonce.skew ts = timestamp.to_s # base 10 seconds since epoch nonce_key = key_prefix + 'N' + server_url + '|' + ts + '|' + salt - result = @cache_client.add(nonce_key, '', expiry(Nonce.skew + 5)) - return !!(result =~ /^STORED/) + result = @cache_client.read(nonce_key) + @cache_client.write(nonce_key, nonce_key, :expires_in => (Nonce.skew + 5)) + result.nil? end def assoc_key(server_url, assoc_handle=nil) @@ -86,8 +87,9 @@ def cleanup_associations protected def delete(key) - result = @cache_client.delete(key) - return !!(result =~ /^DELETED/) + # result = @cache_client.delete(key) # memcached delete seems to be broken + # return !!(result =~ /^DELETED/) + @cache_client.write(key, nil, :expires_in => 0) end def serialize(assoc) From b6c29b62a741312415ce9c204fc9085dffb3fd2c Mon Sep 17 00:00:00 2001 From: Mike Mell Date: Fri, 14 May 2010 10:20:41 -0700 Subject: [PATCH 05/22] Fetch the XRDS one time for all service types --- lib/openid/consumer/discovery.rb | 3 +-- lib/openid/yadis/xrires.rb | 15 ++++----------- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/lib/openid/consumer/discovery.rb b/lib/openid/consumer/discovery.rb index 01fe0365..f150d6b6 100644 --- a/lib/openid/consumer/discovery.rb +++ b/lib/openid/consumer/discovery.rb @@ -421,8 +421,7 @@ def self.discover_xri(iname) iname = self.normalize_xri(iname) begin - canonical_id, services = Yadis::XRI::ProxyResolver.new().query( - iname, OpenIDServiceEndpoint::OPENID_TYPE_URIS) + canonical_id, services = Yadis::XRI::ProxyResolver.new().query( iname ) if canonical_id.nil? raise Yadis::XRDSError.new(sprintf('No CanonicalID found for XRI %s', iname)) diff --git a/lib/openid/yadis/xrires.rb b/lib/openid/yadis/xrires.rb index 39439119..e2a14dc7 100644 --- a/lib/openid/yadis/xrires.rb +++ b/lib/openid/yadis/xrires.rb @@ -42,34 +42,27 @@ def query_url(xri, service_type=nil) return XRI.append_args(hxri, args) end - def query(xri, service_types) + def query(xri) # these can be query args or http headers, needn't be both. # headers = {'Accept' => 'application/xrds+xml;sep=true'} canonicalID = nil - services = service_types.collect { |service_type| - url = self.query_url(xri, service_type) + url = self.query_url(xri) begin response = OpenID.fetch(url) rescue - raise XRIHTTPError, ["Could not fetch #{xri}", $!] + raise XRIHTTPError, "Could not fetch #{xri}, #{$!}" end raise XRIHTTPError, "Could not fetch #{xri}" if response.nil? xrds = Yadis::parseXRDS(response.body) canonicalID = Yadis::get_canonical_id(xri, xrds) - Yadis::services(xrds) unless xrds.nil? - } + return canonicalID, Yadis::services(xrds) # TODO: # * If we do get hits for multiple service_types, we're almost # certainly going to have duplicated service entries and # broken priority ordering. - services = services.inject([]) { |flatter, some_services| - flatter += some_services unless some_services.nil? - } - - return canonicalID, services end end From 583ab1cbe4640b1d52cef7a63b9ddc133d09dc25 Mon Sep 17 00:00:00 2001 From: Mike Mell Date: Mon, 21 Feb 2011 09:59:22 -0800 Subject: [PATCH 06/22] fix small memcached store bugs --- lib/openid/store/memcache.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/openid/store/memcache.rb b/lib/openid/store/memcache.rb index 405d7e82..1ff600bb 100644 --- a/lib/openid/store/memcache.rb +++ b/lib/openid/store/memcache.rb @@ -21,7 +21,7 @@ def store_association(server_url, association) serialized = serialize(association) [nil, association.handle].each do |handle| key = assoc_key(server_url, handle) - @cache_client.write(key, serialized, :expires_in => association.lifetime.seconds) + @cache_client.write(key, serialized, :expires_in => association.lifetime.seconds.to_i) end end @@ -63,7 +63,7 @@ def use_nonce(server_url, timestamp, salt) ts = timestamp.to_s # base 10 seconds since epoch nonce_key = key_prefix + 'N' + server_url + '|' + ts + '|' + salt result = @cache_client.read(nonce_key) - @cache_client.write(nonce_key, nonce_key, :expires_in => (Nonce.skew + 5)) + @cache_client.write(nonce_key, nonce_key, :expires_in => (Nonce.skew() + 5)) result.nil? end From 1626874238e9929b911f6c9f1852ded7c518b8f7 Mon Sep 17 00:00:00 2001 From: Mike Mell Date: Mon, 21 Feb 2011 10:00:40 -0800 Subject: [PATCH 07/22] fix escaping and ambiguous error message --- lib/openid/yadis/xrires.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/openid/yadis/xrires.rb b/lib/openid/yadis/xrires.rb index e2a14dc7..da4b2f84 100644 --- a/lib/openid/yadis/xrires.rb +++ b/lib/openid/yadis/xrires.rb @@ -30,7 +30,7 @@ def query_url(xri, service_type=nil) # that off again for the QXRI. This is under discussion for # XRI Resolution WD 11. qxri = XRI.to_uri_normal(xri)[6..-1] - hxri = @proxy_url + qxri + hxri = @proxy_url + CGI::escape( qxri ) args = {'_xrd_r' => 'application/xrds+xml'} if service_type args['_xrd_t'] = service_type @@ -53,9 +53,10 @@ def query(xri) rescue raise XRIHTTPError, "Could not fetch #{xri}, #{$!}" end - raise XRIHTTPError, "Could not fetch #{xri}" if response.nil? + raise XRIHTTPError, "Fetching #{xri} returned nothing" if response.nil? xrds = Yadis::parseXRDS(response.body) + raise XRIHTTPError, "Fetching #{xri} did not return an XRDS" if xrds.nil? canonicalID = Yadis::get_canonical_id(xri, xrds) return canonicalID, Yadis::services(xrds) From da8a5b7d49464c0356723f4e9d49a7edeaf796da Mon Sep 17 00:00:00 2001 From: mmell Date: Mon, 21 Feb 2011 15:46:53 -0800 Subject: [PATCH 08/22] Edited gemspec via GitHub --- gemspec | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/gemspec b/gemspec index 68435249..472bce6b 100644 --- a/gemspec +++ b/gemspec @@ -2,11 +2,10 @@ require 'rubygems' SPEC = Gem::Specification.new do |s| s.name = `cat admin/library-name`.strip -# s.version = `darcs changes --tags= | awk '$1 == "tagged" { print $2 }' | head -n 1`.strip s.version = '2.1.8' - s.author = 'JanRain, Inc' - s.email = 'openid@janrain.com' - s.homepage = 'http://github.com/openid/ruby-openid' + s.author = 'JanRain, Inc, Mike Mell' + s.email = 'mike.mell@nthwave.net' + s.homepage = 'https://github.com/mmell/ruby-openid' s.platform = Gem::Platform::RUBY s.summary = 'A library for consuming and serving OpenID identities.' files = Dir.glob("{examples,lib,test}/**/*") From 701c42d39cacee58b39dd5fab0814fbfbb922bf0 Mon Sep 17 00:00:00 2001 From: Mike Mell Date: Mon, 21 Feb 2011 17:17:27 -0800 Subject: [PATCH 09/22] rename gemspec to .gemspec --- gemspec => .gemspec | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename gemspec => .gemspec (100%) diff --git a/gemspec b/.gemspec similarity index 100% rename from gemspec rename to .gemspec From 49f838b20aa681b4b888b8196ae34c7a128bd52f Mon Sep 17 00:00:00 2001 From: mmell Date: Mon, 21 Feb 2011 18:10:28 -0800 Subject: [PATCH 10/22] Allow setting Yadis::XRI::ProxyResolver::DEFAULT_PROXY premptively, outside of the class definition. Useful for iname-based communities running their own resolver. --- lib/openid/yadis/xrires.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/openid/yadis/xrires.rb b/lib/openid/yadis/xrires.rb index da4b2f84..92008438 100644 --- a/lib/openid/yadis/xrires.rb +++ b/lib/openid/yadis/xrires.rb @@ -13,7 +13,7 @@ class XRIHTTPError < StandardError; end class ProxyResolver - DEFAULT_PROXY = 'http://proxy.xri.net/' + DEFAULT_PROXY ||= 'http://proxy.xri.net/' def initialize(proxy_url=nil) if proxy_url From 7ea23fb875451ffd3273d1d8bc5befc26e813f06 Mon Sep 17 00:00:00 2001 From: Mike Mell Date: Wed, 23 Feb 2011 19:25:33 -0800 Subject: [PATCH 11/22] remove ;sep=false option since we want all of the OpenID endpoints in a single request --- lib/openid/yadis/xrires.rb | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/lib/openid/yadis/xrires.rb b/lib/openid/yadis/xrires.rb index 92008438..a80600ea 100644 --- a/lib/openid/yadis/xrires.rb +++ b/lib/openid/yadis/xrires.rb @@ -31,13 +31,8 @@ def query_url(xri, service_type=nil) # XRI Resolution WD 11. qxri = XRI.to_uri_normal(xri)[6..-1] hxri = @proxy_url + CGI::escape( qxri ) - args = {'_xrd_r' => 'application/xrds+xml'} - if service_type - args['_xrd_t'] = service_type - else - # don't perform service endpoint selection - args['_xrd_r'] += ';sep=false' - end + args = {'_xrd_r' => 'application/xrds+xml'} + args['_xrd_t'] = service_type if service_type return XRI.append_args(hxri, args) end @@ -45,25 +40,20 @@ def query_url(xri, service_type=nil) def query(xri) # these can be query args or http headers, needn't be both. # headers = {'Accept' => 'application/xrds+xml;sep=true'} - canonicalID = nil url = self.query_url(xri) - begin - response = OpenID.fetch(url) - rescue - raise XRIHTTPError, "Could not fetch #{xri}, #{$!}" - end + begin + response = OpenID.fetch(url) + rescue + raise XRIHTTPError, "Could not fetch #{xri}, #{$!}" + end raise XRIHTTPError, "Fetching #{xri} returned nothing" if response.nil? - xrds = Yadis::parseXRDS(response.body) + xrds = Yadis::parseXRDS(response.body) raise XRIHTTPError, "Fetching #{xri} did not return an XRDS" if xrds.nil? - canonicalID = Yadis::get_canonical_id(xri, xrds) + canonicalID = Yadis::get_canonical_id(xri, xrds) return canonicalID, Yadis::services(xrds) - # TODO: - # * If we do get hits for multiple service_types, we're almost - # certainly going to have duplicated service entries and - # broken priority ordering. end end From d0638cec4dbef3d296f13b7f2b8d94f56284d800 Mon Sep 17 00:00:00 2001 From: Mike Mell Date: Sun, 30 Oct 2011 11:58:36 -0700 Subject: [PATCH 12/22] add Gemfile, Rakefile, version, move/update the gemspec --- .gemspec | 20 -------------------- Gemfile | 5 +++++ Rakefile | 15 +++++++++++++++ lib/openid.rb | 10 ++++++---- lib/openid/fetchers.rb | 2 +- lib/openid/store.rb | 10 ++++++++++ lib/openid/version.rb | 3 +++ lib/openid/yadis.rb | 15 +++++++++++++++ ruby-openid.gemspec | 24 ++++++++++++++++++++++++ 9 files changed, 79 insertions(+), 25 deletions(-) delete mode 100644 .gemspec create mode 100644 Gemfile create mode 100644 Rakefile create mode 100644 lib/openid/store.rb create mode 100644 lib/openid/version.rb create mode 100644 lib/openid/yadis.rb create mode 100644 ruby-openid.gemspec diff --git a/.gemspec b/.gemspec deleted file mode 100644 index 472bce6b..00000000 --- a/.gemspec +++ /dev/null @@ -1,20 +0,0 @@ -require 'rubygems' - -SPEC = Gem::Specification.new do |s| - s.name = `cat admin/library-name`.strip - s.version = '2.1.8' - s.author = 'JanRain, Inc, Mike Mell' - s.email = 'mike.mell@nthwave.net' - s.homepage = 'https://github.com/mmell/ruby-openid' - s.platform = Gem::Platform::RUBY - s.summary = 'A library for consuming and serving OpenID identities.' - files = Dir.glob("{examples,lib,test}/**/*") - files << 'NOTICE' << 'CHANGELOG' - s.files = files.delete_if {|f| f.include?('_darcs') || f.include?('admin')} - s.require_path = 'lib' - s.autorequire = 'openid' - s.test_file = 'admin/runtests.rb' - s.has_rdoc = true - s.extra_rdoc_files = ['README','INSTALL','LICENSE','UPGRADE'] - s.rdoc_options << '--main' << 'README' -end diff --git a/Gemfile b/Gemfile new file mode 100644 index 00000000..d4cc2446 --- /dev/null +++ b/Gemfile @@ -0,0 +1,5 @@ +source "http://rubygems.org" + +gemspec + +gem "test-unit" diff --git a/Rakefile b/Rakefile new file mode 100644 index 00000000..a824512e --- /dev/null +++ b/Rakefile @@ -0,0 +1,15 @@ +require 'rake' +require 'rake/testtask' +require "bundler/gem_tasks" + +# see http://rake.rubyforge.org/classes/Rake/TestTask.html +# Run tests with: +# $ cd ruby-openid +# $ rake test +# +desc 'Run the ruby-openid tests.' +Rake::TestTask.new(:test) do |t| + t.libs += ["lib", "test"] + t.test_files = FileList['test/test_*.rb'] + t.verbose = true +end diff --git a/lib/openid.rb b/lib/openid.rb index 1024de7c..ccb3ad91 100644 --- a/lib/openid.rb +++ b/lib/openid.rb @@ -12,9 +12,11 @@ # implied. See the License for the specific language governing # permissions and limitations under the License. -module OpenID - VERSION = "2.1.8" -end - +require "openid/version" +require 'openid/store' +require 'openid/yadis' require "openid/consumer" require 'openid/server' + +module OpenID +end diff --git a/lib/openid/fetchers.rb b/lib/openid/fetchers.rb index 22c87ac3..04cbb2a6 100644 --- a/lib/openid/fetchers.rb +++ b/lib/openid/fetchers.rb @@ -111,7 +111,7 @@ def self.fetcher_use_env_http_proxy @fetcher = StandardFetcher.new(proxy_uri.host, proxy_uri.port, proxy_uri.user, proxy_uri.password) end - + class StandardFetcher USER_AGENT = "ruby-openid/#{OpenID::VERSION} (#{RUBY_PLATFORM})" diff --git a/lib/openid/store.rb b/lib/openid/store.rb new file mode 100644 index 00000000..bccade7b --- /dev/null +++ b/lib/openid/store.rb @@ -0,0 +1,10 @@ +require 'openid/store/interface' +require 'openid/store/filesystem' +require 'openid/store/memcache' +require 'openid/store/memory' +require 'openid/store/nonce' + +module OpenID + module Store + end +end \ No newline at end of file diff --git a/lib/openid/version.rb b/lib/openid/version.rb new file mode 100644 index 00000000..ea3598d8 --- /dev/null +++ b/lib/openid/version.rb @@ -0,0 +1,3 @@ +module OpenID + VERSION = "2.1.8" +end diff --git a/lib/openid/yadis.rb b/lib/openid/yadis.rb new file mode 100644 index 00000000..7834d134 --- /dev/null +++ b/lib/openid/yadis.rb @@ -0,0 +1,15 @@ +require 'openid/yadis/accept' +require 'openid/yadis/constants' +require 'openid/yadis/discovery' +require 'openid/yadis/filters' +require 'openid/yadis/htmltokenizer' +require 'openid/yadis/parsehtml' +require 'openid/yadis/services' +require 'openid/yadis/xrds' +require 'openid/yadis/xri' +require 'openid/yadis/xrires' + +module OpenID + module Yadis + end +end diff --git a/ruby-openid.gemspec b/ruby-openid.gemspec new file mode 100644 index 00000000..df9a7156 --- /dev/null +++ b/ruby-openid.gemspec @@ -0,0 +1,24 @@ +# -*- encoding: utf-8 -*- +$:.push File.expand_path("../lib", __FILE__) +require "openid/version" + +Gem::Specification.new do |s| + s.name = "ruby-openid" + s.version = OpenID::VERSION + s.authors = ["JanRain, Inc", "Mike Mell"] + s.email = ["openid@janrain.com", "mike.mell@nthwave.net"] + s.homepage = 'https://github.com/mmell/ruby-openid' + s.summary = 'A library for consuming and serving OpenID identities.' + s.description = %q{TODO: Write a gem description} + + s.rubyforge_project = "ruby-openid" + + s.files = `git ls-files`.split("\n") + s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") + s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } + s.require_paths = ["lib"] + + # specify any dependencies here; for example: + # s.add_development_dependency "rspec" + # s.add_runtime_dependency "rest-client" +end From 9c112b067ee05f579bc6a9288e5bb3105af563a7 Mon Sep 17 00:00:00 2001 From: Mike Mell Date: Thu, 3 Nov 2011 12:43:58 -0700 Subject: [PATCH 13/22] reorganize tests to match current conventions --- .../test_data_mixin.rb} | 2 +- test/{util.rb => support/test_util.rb} | 0 .../yadis_data.rb} | 4 +- test/{data => support/yadis_data}/accept.txt | 0 test/{data => support/yadis_data}/dh.txt | 0 .../yadis_data}/example-xrds.xml | 0 .../yadis_data}/linkparse.txt | 0 test/{data => support/yadis_data}/n2b64 | 0 .../yadis_data}/test1-discover.txt | 0 .../yadis_data}/test1-parsehtml.txt | 0 .../test_discover/malformed_meta_tag.html | 0 .../yadis_data}/test_discover/openid.html | 0 .../yadis_data}/test_discover/openid2.html | 0 .../test_discover/openid2_xrds.xml | 0 .../openid2_xrds_no_local_id.xml | 0 .../test_discover/openid_1_and_2.html | 0 .../test_discover/openid_1_and_2_xrds.xml | 0 .../openid_1_and_2_xrds_bad_delegate.xml | 0 .../test_discover/openid_and_yadis.html | 0 .../test_discover/openid_no_delegate.html | 0 .../test_discover/yadis_0entries.xml | 0 .../test_discover/yadis_2_bad_local_id.xml | 0 .../test_discover/yadis_2entries_delegate.xml | 0 .../test_discover/yadis_2entries_idp.xml | 0 .../test_discover/yadis_another_delegate.xml | 0 .../yadis_data}/test_discover/yadis_idp.xml | 0 .../test_discover/yadis_idp_delegate.xml | 0 .../test_discover/yadis_no_delegate.xml | 0 .../test_xrds/=j3h.2007.11.14.xrds | 0 .../yadis_data}/test_xrds/README | 0 .../test_xrds/delegated-20060809-r1.xrds | 0 .../test_xrds/delegated-20060809-r2.xrds | 0 .../test_xrds/delegated-20060809.xrds | 0 .../yadis_data}/test_xrds/no-xrd.xml | 0 .../yadis_data}/test_xrds/not-xrds.xml | 0 .../test_xrds/prefixsometimes.xrds | 0 .../yadis_data}/test_xrds/ref.xrds | 0 .../test_xrds/sometimesprefix.xrds | 0 .../yadis_data}/test_xrds/spoof1.xrds | 0 .../yadis_data}/test_xrds/spoof2.xrds | 0 .../yadis_data}/test_xrds/spoof3.xrds | 0 .../yadis_data}/test_xrds/status222.xrds | 0 .../yadis_data}/test_xrds/subsegments.xrds | 0 .../test_xrds/valid-populated-xrds.xml | 0 .../yadis_data}/trustroot.txt | 0 test/{data => support/yadis_data}/urinorm.txt | 0 test/test_accept.rb | 3 +- test/test_association.rb | 3 +- test/test_associationmanager.rb | 4 +- test/test_checkid_request.rb | 5 +- test/test_consumer.rb | 4 +- test/test_cryptutil.rb | 180 +++++++++--------- test/test_dh.rb | 3 +- test/test_discover.rb | 10 +- test/test_discovery_manager.rb | 7 +- test/test_extension.rb | 4 +- test/test_extras.rb | 2 +- test/test_fetchers.rb | 20 +- test/test_filters.rb | 11 +- test/test_helper.rb | 4 + test/test_idres.rb | 38 ++-- test/test_kvform.rb | 3 +- test/test_kvpost.rb | 3 +- test/test_linkparse.rb | 5 +- test/test_message.rb | 6 +- test/test_nonce.rb | 4 +- test/test_oauth.rb | 5 +- test/test_openid_yadis.rb | 3 +- test/test_pape.rb | 13 +- test/test_parsehtml.rb | 3 +- test/test_responses.rb | 2 +- test/test_server.rb | 24 ++- test/test_sreg.rb | 16 +- test/test_stores.rb | 10 +- test/test_trustroot.rb | 20 +- test/test_urinorm.rb | 3 +- test/test_util.rb | 2 +- test/test_xrds.rb | 4 +- test/test_xri.rb | 2 +- test/test_xrires.rb | 30 +-- test/test_yadis_discovery.rb | 14 +- 81 files changed, 221 insertions(+), 255 deletions(-) rename test/{testutil.rb => support/test_data_mixin.rb} (98%) rename test/{util.rb => support/test_util.rb} (100%) rename test/{discoverdata.rb => support/yadis_data.rb} (99%) rename test/{data => support/yadis_data}/accept.txt (100%) rename test/{data => support/yadis_data}/dh.txt (100%) rename test/{data => support/yadis_data}/example-xrds.xml (100%) rename test/{data => support/yadis_data}/linkparse.txt (100%) rename test/{data => support/yadis_data}/n2b64 (100%) rename test/{data => support/yadis_data}/test1-discover.txt (100%) rename test/{data => support/yadis_data}/test1-parsehtml.txt (100%) rename test/{data => support/yadis_data}/test_discover/malformed_meta_tag.html (100%) rename test/{data => support/yadis_data}/test_discover/openid.html (100%) rename test/{data => support/yadis_data}/test_discover/openid2.html (100%) rename test/{data => support/yadis_data}/test_discover/openid2_xrds.xml (100%) rename test/{data => support/yadis_data}/test_discover/openid2_xrds_no_local_id.xml (100%) rename test/{data => support/yadis_data}/test_discover/openid_1_and_2.html (100%) rename test/{data => support/yadis_data}/test_discover/openid_1_and_2_xrds.xml (100%) rename test/{data => support/yadis_data}/test_discover/openid_1_and_2_xrds_bad_delegate.xml (100%) rename test/{data => support/yadis_data}/test_discover/openid_and_yadis.html (100%) rename test/{data => support/yadis_data}/test_discover/openid_no_delegate.html (100%) rename test/{data => support/yadis_data}/test_discover/yadis_0entries.xml (100%) rename test/{data => support/yadis_data}/test_discover/yadis_2_bad_local_id.xml (100%) rename test/{data => support/yadis_data}/test_discover/yadis_2entries_delegate.xml (100%) rename test/{data => support/yadis_data}/test_discover/yadis_2entries_idp.xml (100%) rename test/{data => support/yadis_data}/test_discover/yadis_another_delegate.xml (100%) rename test/{data => support/yadis_data}/test_discover/yadis_idp.xml (100%) rename test/{data => support/yadis_data}/test_discover/yadis_idp_delegate.xml (100%) rename test/{data => support/yadis_data}/test_discover/yadis_no_delegate.xml (100%) rename test/{data => support/yadis_data}/test_xrds/=j3h.2007.11.14.xrds (100%) rename test/{data => support/yadis_data}/test_xrds/README (100%) rename test/{data => support/yadis_data}/test_xrds/delegated-20060809-r1.xrds (100%) rename test/{data => support/yadis_data}/test_xrds/delegated-20060809-r2.xrds (100%) rename test/{data => support/yadis_data}/test_xrds/delegated-20060809.xrds (100%) rename test/{data => support/yadis_data}/test_xrds/no-xrd.xml (100%) rename test/{data => support/yadis_data}/test_xrds/not-xrds.xml (100%) rename test/{data => support/yadis_data}/test_xrds/prefixsometimes.xrds (100%) rename test/{data => support/yadis_data}/test_xrds/ref.xrds (100%) rename test/{data => support/yadis_data}/test_xrds/sometimesprefix.xrds (100%) rename test/{data => support/yadis_data}/test_xrds/spoof1.xrds (100%) rename test/{data => support/yadis_data}/test_xrds/spoof2.xrds (100%) rename test/{data => support/yadis_data}/test_xrds/spoof3.xrds (100%) rename test/{data => support/yadis_data}/test_xrds/status222.xrds (100%) rename test/{data => support/yadis_data}/test_xrds/subsegments.xrds (100%) rename test/{data => support/yadis_data}/test_xrds/valid-populated-xrds.xml (100%) rename test/{data => support/yadis_data}/trustroot.txt (100%) rename test/{data => support/yadis_data}/urinorm.txt (100%) create mode 100644 test/test_helper.rb diff --git a/test/testutil.rb b/test/support/test_data_mixin.rb similarity index 98% rename from test/testutil.rb rename to test/support/test_data_mixin.rb index 7676fb95..6036a649 100644 --- a/test/testutil.rb +++ b/test/support/test_data_mixin.rb @@ -3,7 +3,7 @@ module OpenID module TestDataMixin TESTS_DIR = Pathname.new(__FILE__).dirname - TEST_DATA_DIR = Pathname.new('data') + TEST_DATA_DIR = Pathname.new('yadis_data') def read_data_file(filename, lines=true, data_dir=TEST_DATA_DIR) fname = TESTS_DIR.join(data_dir, filename) diff --git a/test/util.rb b/test/support/test_util.rb similarity index 100% rename from test/util.rb rename to test/support/test_util.rb diff --git a/test/discoverdata.rb b/test/support/yadis_data.rb similarity index 99% rename from test/discoverdata.rb rename to test/support/yadis_data.rb index 7b21749f..a5714eb9 100644 --- a/test/discoverdata.rb +++ b/test/support/yadis_data.rb @@ -7,10 +7,10 @@ module OpenID - module DiscoverData + module YadisData include TestDataMixin - include Util + include TestUtil TESTLIST = [ # success, input_name, id_name, result_name diff --git a/test/data/accept.txt b/test/support/yadis_data/accept.txt similarity index 100% rename from test/data/accept.txt rename to test/support/yadis_data/accept.txt diff --git a/test/data/dh.txt b/test/support/yadis_data/dh.txt similarity index 100% rename from test/data/dh.txt rename to test/support/yadis_data/dh.txt diff --git a/test/data/example-xrds.xml b/test/support/yadis_data/example-xrds.xml similarity index 100% rename from test/data/example-xrds.xml rename to test/support/yadis_data/example-xrds.xml diff --git a/test/data/linkparse.txt b/test/support/yadis_data/linkparse.txt similarity index 100% rename from test/data/linkparse.txt rename to test/support/yadis_data/linkparse.txt diff --git a/test/data/n2b64 b/test/support/yadis_data/n2b64 similarity index 100% rename from test/data/n2b64 rename to test/support/yadis_data/n2b64 diff --git a/test/data/test1-discover.txt b/test/support/yadis_data/test1-discover.txt similarity index 100% rename from test/data/test1-discover.txt rename to test/support/yadis_data/test1-discover.txt diff --git a/test/data/test1-parsehtml.txt b/test/support/yadis_data/test1-parsehtml.txt similarity index 100% rename from test/data/test1-parsehtml.txt rename to test/support/yadis_data/test1-parsehtml.txt diff --git a/test/data/test_discover/malformed_meta_tag.html b/test/support/yadis_data/test_discover/malformed_meta_tag.html similarity index 100% rename from test/data/test_discover/malformed_meta_tag.html rename to test/support/yadis_data/test_discover/malformed_meta_tag.html diff --git a/test/data/test_discover/openid.html b/test/support/yadis_data/test_discover/openid.html similarity index 100% rename from test/data/test_discover/openid.html rename to test/support/yadis_data/test_discover/openid.html diff --git a/test/data/test_discover/openid2.html b/test/support/yadis_data/test_discover/openid2.html similarity index 100% rename from test/data/test_discover/openid2.html rename to test/support/yadis_data/test_discover/openid2.html diff --git a/test/data/test_discover/openid2_xrds.xml b/test/support/yadis_data/test_discover/openid2_xrds.xml similarity index 100% rename from test/data/test_discover/openid2_xrds.xml rename to test/support/yadis_data/test_discover/openid2_xrds.xml diff --git a/test/data/test_discover/openid2_xrds_no_local_id.xml b/test/support/yadis_data/test_discover/openid2_xrds_no_local_id.xml similarity index 100% rename from test/data/test_discover/openid2_xrds_no_local_id.xml rename to test/support/yadis_data/test_discover/openid2_xrds_no_local_id.xml diff --git a/test/data/test_discover/openid_1_and_2.html b/test/support/yadis_data/test_discover/openid_1_and_2.html similarity index 100% rename from test/data/test_discover/openid_1_and_2.html rename to test/support/yadis_data/test_discover/openid_1_and_2.html diff --git a/test/data/test_discover/openid_1_and_2_xrds.xml b/test/support/yadis_data/test_discover/openid_1_and_2_xrds.xml similarity index 100% rename from test/data/test_discover/openid_1_and_2_xrds.xml rename to test/support/yadis_data/test_discover/openid_1_and_2_xrds.xml diff --git a/test/data/test_discover/openid_1_and_2_xrds_bad_delegate.xml b/test/support/yadis_data/test_discover/openid_1_and_2_xrds_bad_delegate.xml similarity index 100% rename from test/data/test_discover/openid_1_and_2_xrds_bad_delegate.xml rename to test/support/yadis_data/test_discover/openid_1_and_2_xrds_bad_delegate.xml diff --git a/test/data/test_discover/openid_and_yadis.html b/test/support/yadis_data/test_discover/openid_and_yadis.html similarity index 100% rename from test/data/test_discover/openid_and_yadis.html rename to test/support/yadis_data/test_discover/openid_and_yadis.html diff --git a/test/data/test_discover/openid_no_delegate.html b/test/support/yadis_data/test_discover/openid_no_delegate.html similarity index 100% rename from test/data/test_discover/openid_no_delegate.html rename to test/support/yadis_data/test_discover/openid_no_delegate.html diff --git a/test/data/test_discover/yadis_0entries.xml b/test/support/yadis_data/test_discover/yadis_0entries.xml similarity index 100% rename from test/data/test_discover/yadis_0entries.xml rename to test/support/yadis_data/test_discover/yadis_0entries.xml diff --git a/test/data/test_discover/yadis_2_bad_local_id.xml b/test/support/yadis_data/test_discover/yadis_2_bad_local_id.xml similarity index 100% rename from test/data/test_discover/yadis_2_bad_local_id.xml rename to test/support/yadis_data/test_discover/yadis_2_bad_local_id.xml diff --git a/test/data/test_discover/yadis_2entries_delegate.xml b/test/support/yadis_data/test_discover/yadis_2entries_delegate.xml similarity index 100% rename from test/data/test_discover/yadis_2entries_delegate.xml rename to test/support/yadis_data/test_discover/yadis_2entries_delegate.xml diff --git a/test/data/test_discover/yadis_2entries_idp.xml b/test/support/yadis_data/test_discover/yadis_2entries_idp.xml similarity index 100% rename from test/data/test_discover/yadis_2entries_idp.xml rename to test/support/yadis_data/test_discover/yadis_2entries_idp.xml diff --git a/test/data/test_discover/yadis_another_delegate.xml b/test/support/yadis_data/test_discover/yadis_another_delegate.xml similarity index 100% rename from test/data/test_discover/yadis_another_delegate.xml rename to test/support/yadis_data/test_discover/yadis_another_delegate.xml diff --git a/test/data/test_discover/yadis_idp.xml b/test/support/yadis_data/test_discover/yadis_idp.xml similarity index 100% rename from test/data/test_discover/yadis_idp.xml rename to test/support/yadis_data/test_discover/yadis_idp.xml diff --git a/test/data/test_discover/yadis_idp_delegate.xml b/test/support/yadis_data/test_discover/yadis_idp_delegate.xml similarity index 100% rename from test/data/test_discover/yadis_idp_delegate.xml rename to test/support/yadis_data/test_discover/yadis_idp_delegate.xml diff --git a/test/data/test_discover/yadis_no_delegate.xml b/test/support/yadis_data/test_discover/yadis_no_delegate.xml similarity index 100% rename from test/data/test_discover/yadis_no_delegate.xml rename to test/support/yadis_data/test_discover/yadis_no_delegate.xml diff --git a/test/data/test_xrds/=j3h.2007.11.14.xrds b/test/support/yadis_data/test_xrds/=j3h.2007.11.14.xrds similarity index 100% rename from test/data/test_xrds/=j3h.2007.11.14.xrds rename to test/support/yadis_data/test_xrds/=j3h.2007.11.14.xrds diff --git a/test/data/test_xrds/README b/test/support/yadis_data/test_xrds/README similarity index 100% rename from test/data/test_xrds/README rename to test/support/yadis_data/test_xrds/README diff --git a/test/data/test_xrds/delegated-20060809-r1.xrds b/test/support/yadis_data/test_xrds/delegated-20060809-r1.xrds similarity index 100% rename from test/data/test_xrds/delegated-20060809-r1.xrds rename to test/support/yadis_data/test_xrds/delegated-20060809-r1.xrds diff --git a/test/data/test_xrds/delegated-20060809-r2.xrds b/test/support/yadis_data/test_xrds/delegated-20060809-r2.xrds similarity index 100% rename from test/data/test_xrds/delegated-20060809-r2.xrds rename to test/support/yadis_data/test_xrds/delegated-20060809-r2.xrds diff --git a/test/data/test_xrds/delegated-20060809.xrds b/test/support/yadis_data/test_xrds/delegated-20060809.xrds similarity index 100% rename from test/data/test_xrds/delegated-20060809.xrds rename to test/support/yadis_data/test_xrds/delegated-20060809.xrds diff --git a/test/data/test_xrds/no-xrd.xml b/test/support/yadis_data/test_xrds/no-xrd.xml similarity index 100% rename from test/data/test_xrds/no-xrd.xml rename to test/support/yadis_data/test_xrds/no-xrd.xml diff --git a/test/data/test_xrds/not-xrds.xml b/test/support/yadis_data/test_xrds/not-xrds.xml similarity index 100% rename from test/data/test_xrds/not-xrds.xml rename to test/support/yadis_data/test_xrds/not-xrds.xml diff --git a/test/data/test_xrds/prefixsometimes.xrds b/test/support/yadis_data/test_xrds/prefixsometimes.xrds similarity index 100% rename from test/data/test_xrds/prefixsometimes.xrds rename to test/support/yadis_data/test_xrds/prefixsometimes.xrds diff --git a/test/data/test_xrds/ref.xrds b/test/support/yadis_data/test_xrds/ref.xrds similarity index 100% rename from test/data/test_xrds/ref.xrds rename to test/support/yadis_data/test_xrds/ref.xrds diff --git a/test/data/test_xrds/sometimesprefix.xrds b/test/support/yadis_data/test_xrds/sometimesprefix.xrds similarity index 100% rename from test/data/test_xrds/sometimesprefix.xrds rename to test/support/yadis_data/test_xrds/sometimesprefix.xrds diff --git a/test/data/test_xrds/spoof1.xrds b/test/support/yadis_data/test_xrds/spoof1.xrds similarity index 100% rename from test/data/test_xrds/spoof1.xrds rename to test/support/yadis_data/test_xrds/spoof1.xrds diff --git a/test/data/test_xrds/spoof2.xrds b/test/support/yadis_data/test_xrds/spoof2.xrds similarity index 100% rename from test/data/test_xrds/spoof2.xrds rename to test/support/yadis_data/test_xrds/spoof2.xrds diff --git a/test/data/test_xrds/spoof3.xrds b/test/support/yadis_data/test_xrds/spoof3.xrds similarity index 100% rename from test/data/test_xrds/spoof3.xrds rename to test/support/yadis_data/test_xrds/spoof3.xrds diff --git a/test/data/test_xrds/status222.xrds b/test/support/yadis_data/test_xrds/status222.xrds similarity index 100% rename from test/data/test_xrds/status222.xrds rename to test/support/yadis_data/test_xrds/status222.xrds diff --git a/test/data/test_xrds/subsegments.xrds b/test/support/yadis_data/test_xrds/subsegments.xrds similarity index 100% rename from test/data/test_xrds/subsegments.xrds rename to test/support/yadis_data/test_xrds/subsegments.xrds diff --git a/test/data/test_xrds/valid-populated-xrds.xml b/test/support/yadis_data/test_xrds/valid-populated-xrds.xml similarity index 100% rename from test/data/test_xrds/valid-populated-xrds.xml rename to test/support/yadis_data/test_xrds/valid-populated-xrds.xml diff --git a/test/data/trustroot.txt b/test/support/yadis_data/trustroot.txt similarity index 100% rename from test/data/trustroot.txt rename to test/support/yadis_data/trustroot.txt diff --git a/test/data/urinorm.txt b/test/support/yadis_data/urinorm.txt similarity index 100% rename from test/data/urinorm.txt rename to test/support/yadis_data/urinorm.txt diff --git a/test/test_accept.rb b/test/test_accept.rb index 06db85bf..ce1cf159 100644 --- a/test/test_accept.rb +++ b/test/test_accept.rb @@ -1,5 +1,4 @@ - -require 'test/unit' +require "test_helper" require 'openid/yadis/accept' require 'openid/extras' require 'openid/util' diff --git a/test/test_association.rb b/test/test_association.rb index 1b273321..3a390ee7 100644 --- a/test/test_association.rb +++ b/test/test_association.rb @@ -1,4 +1,5 @@ -require "test/unit" +require 'test_helper' +require 'support/test_util' require "openid/association" module OpenID diff --git a/test/test_associationmanager.rb b/test/test_associationmanager.rb index 041449ff..d9743297 100644 --- a/test/test_associationmanager.rb +++ b/test/test_associationmanager.rb @@ -1,3 +1,5 @@ +require 'test_helper' +require 'support/test_util' require "openid/consumer/associationmanager" require "openid/association" require "openid/dh" @@ -5,8 +7,6 @@ require "openid/cryptutil" require "openid/message" require "openid/store/memory" -require "test/unit" -require "util" require "time" module OpenID diff --git a/test/test_checkid_request.rb b/test/test_checkid_request.rb index e1d95c91..6c06249c 100644 --- a/test/test_checkid_request.rb +++ b/test/test_checkid_request.rb @@ -1,8 +1,7 @@ +require 'test_helper' +require 'support/test_util' require "openid/consumer/checkid_request" require "openid/message" -require "test/unit" -require "testutil" -require "util" module OpenID class Consumer diff --git a/test/test_consumer.rb b/test/test_consumer.rb index dc4a09e6..52604c76 100644 --- a/test/test_consumer.rb +++ b/test/test_consumer.rb @@ -1,6 +1,6 @@ +require 'test_helper' +require 'support/test_util' require "openid/consumer" -require "test/unit" -require "testutil" module OpenID class Consumer diff --git a/test/test_cryptutil.rb b/test/test_cryptutil.rb index f6a38a0d..312350b2 100644 --- a/test/test_cryptutil.rb +++ b/test/test_cryptutil.rb @@ -1,119 +1,119 @@ # coding: ASCII-8BIT -require 'test/unit' +require "test_helper" require "openid/cryptutil" require "pathname" -class CryptUtilTestCase < Test::Unit::TestCase - BIG = 2 ** 256 +module OpenID + class CryptUtilTestCase < Test::Unit::TestCase + include TestDataMixin - def test_rand - # If this is not true, the rest of our test won't work - assert(BIG.is_a?(Bignum)) + BIG = 2 ** 256 - # It's possible that these will be small enough for fixnums, but - # extraorindarily unlikely. - a = OpenID::CryptUtil.rand(BIG) - b = OpenID::CryptUtil.rand(BIG) - assert(a.is_a?(Bignum)) - assert(b.is_a?(Bignum)) - assert_not_equal(a, b) - end + def test_rand + # If this is not true, the rest of our test won't work + assert(BIG.is_a?(Bignum)) - def test_rand_doesnt_depend_on_srand - Kernel.srand(1) - a = OpenID::CryptUtil.rand(BIG) - Kernel.srand(1) - b = OpenID::CryptUtil.rand(BIG) - assert_not_equal(a, b) - end + # It's possible that these will be small enough for fixnums, but + # extraorindarily unlikely. + a = OpenID::CryptUtil.rand(BIG) + b = OpenID::CryptUtil.rand(BIG) + assert(a.is_a?(Bignum)) + assert(b.is_a?(Bignum)) + assert_not_equal(a, b) + end - def test_random_binary_convert - (0..500).each do - n = (0..10).inject(0) {|sum, element| sum + OpenID::CryptUtil.rand(BIG) } - s = OpenID::CryptUtil.num_to_binary n - assert(s.is_a?(String)) - n_converted_back = OpenID::CryptUtil.binary_to_num(s) - assert_equal(n, n_converted_back) + def test_rand_doesnt_depend_on_srand + Kernel.srand(1) + a = OpenID::CryptUtil.rand(BIG) + Kernel.srand(1) + b = OpenID::CryptUtil.rand(BIG) + assert_not_equal(a, b) end - end - def test_enumerated_binary_convert - { - "\x00" => 0, - "\x01" => 1, - "\x7F" => 127, - "\x00\xFF" => 255, - "\x00\x80" => 128, - "\x00\x81" => 129, - "\x00\x80\x00" => 32768, - "OpenID is cool" => 1611215304203901150134421257416556, - }.each do |str, num| - num_prime = OpenID::CryptUtil.binary_to_num(str) - str_prime = OpenID::CryptUtil.num_to_binary(num) - assert_equal(num, num_prime) - assert_equal(str, str_prime) + def test_random_binary_convert + (0..500).each do + n = (0..10).inject(0) {|sum, element| sum + OpenID::CryptUtil.rand(BIG) } + s = OpenID::CryptUtil.num_to_binary n + assert(s.is_a?(String)) + n_converted_back = OpenID::CryptUtil.binary_to_num(s) + assert_equal(n, n_converted_back) + end + end + + def test_enumerated_binary_convert + { + "\x00" => 0, + "\x01" => 1, + "\x7F" => 127, + "\x00\xFF" => 255, + "\x00\x80" => 128, + "\x00\x81" => 129, + "\x00\x80\x00" => 32768, + "OpenID is cool" => 1611215304203901150134421257416556, + }.each do |str, num| + num_prime = OpenID::CryptUtil.binary_to_num(str) + str_prime = OpenID::CryptUtil.num_to_binary(num) + assert_equal(num, num_prime) + assert_equal(str, str_prime) + end end - end - def with_n2b64 - test_dir = Pathname.new(__FILE__).dirname - filename = test_dir.join('data', 'n2b64') - File.open(filename) do |file| - file.each_line do |line| + def with_n2b64 + read_data_file( 'n2b64').each do |line| base64, base10 = line.chomp.split yield base64, base10.to_i end end - end - def test_base64_to_num - with_n2b64 do |base64, num| - assert_equal(num, OpenID::CryptUtil.base64_to_num(base64)) + def test_base64_to_num + with_n2b64 do |base64, num| + assert_equal(num, OpenID::CryptUtil.base64_to_num(base64)) + end end - end - def test_base64_to_num_invalid - assert_raises(ArgumentError) { - OpenID::CryptUtil.base64_to_num('!@#$') - } - end + def test_base64_to_num_invalid + assert_raises(ArgumentError) { + OpenID::CryptUtil.base64_to_num('!@#$') + } + end - def test_num_to_base64 - with_n2b64 do |base64, num| - assert_equal(base64, OpenID::CryptUtil.num_to_base64(num)) + def test_num_to_base64 + with_n2b64 do |base64, num| + assert_equal(base64, OpenID::CryptUtil.num_to_base64(num)) + end end - end - def test_randomstring - s1 = OpenID::CryptUtil.random_string(42) - assert_equal(42, s1.length) - s2 = OpenID::CryptUtil.random_string(42) - assert_equal(42, s2.length) - assert_not_equal(s1, s2) - end + def test_randomstring + s1 = OpenID::CryptUtil.random_string(42) + assert_equal(42, s1.length) + s2 = OpenID::CryptUtil.random_string(42) + assert_equal(42, s2.length) + assert_not_equal(s1, s2) + end - def test_randomstring_population - s1 = OpenID::CryptUtil.random_string(42, "XO") - assert_match(/[XO]{42}/, s1) - end + def test_randomstring_population + s1 = OpenID::CryptUtil.random_string(42, "XO") + assert_match(/[XO]{42}/, s1) + end - def test_sha1 - assert_equal("\x11\xf6\xad\x8e\xc5*)\x84\xab\xaa\xfd|;Qe\x03x\\ r", - OpenID::CryptUtil.sha1('x')) - end + def test_sha1 + assert_equal("\x11\xf6\xad\x8e\xc5*)\x84\xab\xaa\xfd|;Qe\x03x\\ r", + OpenID::CryptUtil.sha1('x')) + end - def test_hmac_sha1 - assert_equal("\x8bo\xf7O\xa7\x18*\x90\xac ah\x16\xf7\xb8\x81JB\x9f|", - OpenID::CryptUtil.hmac_sha1('x', 'x')) - end + def test_hmac_sha1 + assert_equal("\x8bo\xf7O\xa7\x18*\x90\xac ah\x16\xf7\xb8\x81JB\x9f|", + OpenID::CryptUtil.hmac_sha1('x', 'x')) + end - def test_sha256 - assert_equal("-q\x16B\xb7&\xb0D\x01b|\xa9\xfb\xac2\xf5\xc8S\x0f\xb1\x90<\xc4\xdb\x02%\x87\x17\x92\x1aH\x81", - OpenID::CryptUtil.sha256('x')) - end + def test_sha256 + assert_equal("-q\x16B\xb7&\xb0D\x01b|\xa9\xfb\xac2\xf5\xc8S\x0f\xb1\x90<\xc4\xdb\x02%\x87\x17\x92\x1aH\x81", + OpenID::CryptUtil.sha256('x')) + end - def test_hmac_sha256 - assert_equal("\x94{\xd2w\xb2\xd3\\\xfc\x07\xfb\xc7\xe3b\xf2iuXz1\xf8:}\xffx\x8f\xda\xc1\xfaC\xc4\xb2\x87", - OpenID::CryptUtil.hmac_sha256('x', 'x')) + def test_hmac_sha256 + assert_equal("\x94{\xd2w\xb2\xd3\\\xfc\x07\xfb\xc7\xe3b\xf2iuXz1\xf8:}\xffx\x8f\xda\xc1\xfaC\xc4\xb2\x87", + OpenID::CryptUtil.hmac_sha256('x', 'x')) + end end end diff --git a/test/test_dh.rb b/test/test_dh.rb index 397c15e5..e60e3a99 100644 --- a/test/test_dh.rb +++ b/test/test_dh.rb @@ -1,6 +1,5 @@ -require 'test/unit' +require "test_helper" require 'openid/dh' -require 'testutil' module OpenID class DiffieHellmanExposed < OpenID::DiffieHellman diff --git a/test/test_discover.rb b/test/test_discover.rb index 13b115ce..fd01f310 100644 --- a/test/test_discover.rb +++ b/test/test_discover.rb @@ -1,8 +1,4 @@ - -require 'testutil' -require 'util' - -require 'test/unit' +require 'test_helper' require 'openid/fetchers' require 'openid/yadis/discovery' require 'openid/consumer/discovery' @@ -48,7 +44,7 @@ def test_discovery_failure @responses.each { |response_set| @url = response_set[0].final_url OpenID.fetcher = SimpleMockFetcher.new(self, response_set) - + expected_status = response_set[-1].code begin OpenID.discover(@url) @@ -228,7 +224,7 @@ def test_blank # def readDataFile(filename): # module_directory = os.path.dirname(os.path.abspath(__file__)) # filename = os.path.join( -# module_directory, 'data', 'test_discover', filename) +# module_directory, 'yadis_data', 'test_discover', filename) # return file(filename).read() class TestDiscovery < BaseTestDiscovery diff --git a/test/test_discovery_manager.rb b/test/test_discovery_manager.rb index da966f38..6465f1e1 100644 --- a/test/test_discovery_manager.rb +++ b/test/test_discovery_manager.rb @@ -1,10 +1,7 @@ - -require 'test/unit' +require "test_helper" require 'openid/consumer/discovery_manager' require 'openid/extras' -require 'testutil' - module OpenID class TestDiscoveredServices < Test::Unit::TestCase def setup @@ -41,7 +38,7 @@ def test_started @disco_services.next assert(@disco_services.started?) @disco_services.next - assert(@disco_services.started?) + assert(@disco_services.started?) @disco_services.next assert(!@disco_services.started?) end diff --git a/test/test_extension.rb b/test/test_extension.rb index bfe14e9b..47cbfc75 100644 --- a/test/test_extension.rb +++ b/test/test_extension.rb @@ -1,6 +1,6 @@ +require 'test_helper' require 'openid/extension' require 'openid/message' -require 'test/unit' module OpenID class DummyExtension < OpenID::Extension @@ -29,7 +29,7 @@ def test_OpenID1 assert_equal(DummyExtension::TEST_ALIAS, namespaces.get_alias(DummyExtension::TEST_URI)) end - + def test_OpenID2 oid2_msg = Message.new(OPENID2_NS) ext = DummyExtension.new diff --git a/test/test_extras.rb b/test/test_extras.rb index c30861cc..4228f8fb 100644 --- a/test/test_extras.rb +++ b/test/test_extras.rb @@ -1,4 +1,4 @@ -require 'test/unit' +require "test_helper" require 'openid/extras' class StartsWithTestCase < Test::Unit::TestCase diff --git a/test/test_fetchers.rb b/test/test_fetchers.rb index 7130da55..61b5f9cf 100644 --- a/test/test_fetchers.rb +++ b/test/test_fetchers.rb @@ -1,12 +1,7 @@ -require 'test/unit' +require "test_helper" require 'net/http' require 'webrick' - -require 'testutil' -require 'util' - require 'openid/fetchers' - require 'stringio' begin @@ -112,7 +107,7 @@ def _redirect_loop assert_block("Fetched too many times.") { @_redirect_counter < 10 } } end - + def setup @fetcher = OpenID::StandardFetcher.new @logfile = StringIO.new @@ -375,17 +370,12 @@ def start(&block) def test_fetchingerror f = OpenID::StandardFetcher.new - f.extend(OpenID::InstanceDefExtension) - f.instance_def(:make_connection) do |uri| - TimeoutConnection.new - end - assert_raise(OpenID::FetchingError) { - f.fetch("https://bogus.com/") + f.fetch("https://bogus2010.com/") } end - + class TestingException < OpenID::FetchingError; end class NoSSLSupportConnection @@ -516,7 +506,7 @@ def test_proxy_unreachable def test_proxy_env ENV['http_proxy'] = 'http://127.0.0.1:3128/' OpenID.fetcher_use_env_http_proxy - + # make_http just to give us something with readable attributes to inspect. conn = OpenID.fetcher.make_http(URI.parse('http://127.0.0.2')) assert_equal('127.0.0.1', conn.proxy_address) diff --git a/test/test_filters.rb b/test/test_filters.rb index 990201f0..3602ec15 100644 --- a/test/test_filters.rb +++ b/test/test_filters.rb @@ -1,5 +1,4 @@ - -require 'test/unit' +require "test_helper" require 'openid/yadis/filters' module OpenID @@ -166,7 +165,7 @@ class MakeFilterTest < Test::Unit::TestCase def test_parts_nil result = Yadis.make_filter(nil) assert(result.is_a?(Yadis::TransformFilterMaker), - result) + result.to_s) end def test_parts_array @@ -175,7 +174,7 @@ def test_parts_array result = Yadis.make_filter([e1, e2]) assert(result.is_a?(Yadis::TransformFilterMaker), - result) + result.to_s) assert(result.filter_procs[0] == e1.method('from_basic_service_endpoint')) assert(result.filter_procs[1] == e2.method('from_basic_service_endpoint')) end @@ -184,7 +183,7 @@ def test_parts_single e = Yadis::BasicServiceEndpoint.new(nil, [], nil, nil) result = Yadis.make_filter(e) assert(result.is_a?(Yadis::TransformFilterMaker), - result) + result.to_s) end end @@ -208,7 +207,7 @@ def test_single_endpoint # from_basic_service_endpoint on the endpoint filter = result.filter_procs[0] assert(filter == e.method('from_basic_service_endpoint'), - filter) + filter.to_s) end def test_single_proc diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 00000000..bb627e5e --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,4 @@ +require 'test/unit' +require 'openid' +require 'support/test_data_mixin' +require 'support/test_util' diff --git a/test/test_idres.rb b/test/test_idres.rb index 9d7364f4..bd67521d 100644 --- a/test/test_idres.rb +++ b/test/test_idres.rb @@ -1,6 +1,4 @@ -require "testutil" -require "util" -require "test/unit" +require 'test_helper' require "openid/consumer/idres" require "openid/protocolerror" require "openid/store/memory" @@ -103,21 +101,21 @@ def mkMsg(ns, fields, signed_fields) end def test_112 - args = {'openid.assoc_handle' => 'fa1f5ff0-cde4-11dc-a183-3714bfd55ca8', - 'openid.claimed_id' => 'http://binkley.lan/user/test01', - 'openid.identity' => 'http://test01.binkley.lan/', - 'openid.mode' => 'id_res', - 'openid.ns' => 'http://specs.openid.net/auth/2.0', - 'openid.ns.pape' => 'http://specs.openid.net/extensions/pape/1.0', - 'openid.op_endpoint' => 'http://binkley.lan/server', - 'openid.pape.auth_policies' => 'none', - 'openid.pape.auth_time' => '2008-01-28T20:42:36Z', - 'openid.pape.nist_auth_level' => '0', - 'openid.response_nonce' => '2008-01-28T21:07:04Z99Q=', - 'openid.return_to' => 'http://binkley.lan:8001/process?janrain_nonce=2008-01-28T21%3A07%3A02Z0tMIKx', - 'openid.sig' => 'YJlWH4U6SroB1HoPkmEKx9AyGGg=', - 'openid.signed' => 'assoc_handle,identity,response_nonce,return_to,claimed_id,op_endpoint,pape.auth_time,ns.pape,pape.nist_auth_level,pape.auth_policies' - } + args = {'openid.assoc_handle' => 'fa1f5ff0-cde4-11dc-a183-3714bfd55ca8', + 'openid.claimed_id' => 'http://binkley.lan/user/test01', + 'openid.identity' => 'http://test01.binkley.lan/', + 'openid.mode' => 'id_res', + 'openid.ns' => 'http://specs.openid.net/auth/2.0', + 'openid.ns.pape' => 'http://specs.openid.net/extensions/pape/1.0', + 'openid.op_endpoint' => 'http://binkley.lan/server', + 'openid.pape.auth_policies' => 'none', + 'openid.pape.auth_time' => '2008-01-28T20:42:36Z', + 'openid.pape.nist_auth_level' => '0', + 'openid.response_nonce' => '2008-01-28T21:07:04Z99Q=', + 'openid.return_to' => 'http://binkley.lan:8001/process?janrain_nonce=2008-01-28T21%3A07%3A02Z0tMIKx', + 'openid.sig' => 'YJlWH4U6SroB1HoPkmEKx9AyGGg=', + 'openid.signed' => 'assoc_handle,identity,response_nonce,return_to,claimed_id,op_endpoint,pape.auth_time,ns.pape,pape.nist_auth_level,pape.auth_policies' + } assert_equal(args['openid.ns'], OPENID2_NS) incoming = Message.from_post_args(args) assert(incoming.is_openid2) @@ -129,7 +127,7 @@ def test_112 assert(expected.is_openid2) assert_equal(expected, car) assert_equal(expected_args, car.to_post_args) - end + end def test_no_signed_list msg = Message.new(OPENID2_NS) @@ -845,7 +843,7 @@ def test_openid2_fragment @endpoint.type_uris = [OPENID_2_0_TYPE] result = assert_log_matches() { - call_verify({'ns' => OPENID2_NS, + call_verify({'ns' => OPENID2_NS, 'identity' => @endpoint.local_id, 'claimed_id' => claimed_id_frag, 'op_endpoint' => @endpoint.server_url}) diff --git a/test/test_kvform.rb b/test/test_kvform.rb index 92260573..b8f11968 100644 --- a/test/test_kvform.rb +++ b/test/test_kvform.rb @@ -1,7 +1,6 @@ -require 'test/unit' +require "test_helper" require 'openid/kvform' require 'openid/util' -require 'util' include OpenID diff --git a/test/test_kvpost.rb b/test/test_kvpost.rb index 8f648049..c0facf97 100644 --- a/test/test_kvpost.rb +++ b/test/test_kvpost.rb @@ -1,8 +1,7 @@ +require 'test_helper' require "openid/kvpost" require "openid/kvform" require "openid/message" -require "test/unit" -require 'testutil' module OpenID class KVPostTestCase < Test::Unit::TestCase diff --git a/test/test_linkparse.rb b/test/test_linkparse.rb index 6360d507..0283b728 100644 --- a/test/test_linkparse.rb +++ b/test/test_linkparse.rb @@ -1,5 +1,4 @@ -require 'test/unit' -require 'testutil' +require "test_helper" require 'openid/consumer/html_parse' class LinkParseTestCase < Test::Unit::TestCase @@ -85,7 +84,7 @@ def test_linkparse end } links = OpenID::parse_link_attrs(html) - + found = links.dup expected = expected_links.dup while(fl = found.shift) diff --git a/test/test_message.rb b/test/test_message.rb index f8ef9187..3169f008 100644 --- a/test/test_message.rb +++ b/test/test_message.rb @@ -1,7 +1,5 @@ -# last synced with Python openid.test.test_message on 6/29/2007. - -require 'test/unit' -require 'util' +require 'test_helper' +require 'support/test_util' require 'openid/message' require 'rexml/document' diff --git a/test/test_nonce.rb b/test/test_nonce.rb index b8a1a054..f8ff41c2 100644 --- a/test/test_nonce.rb +++ b/test/test_nonce.rb @@ -1,4 +1,4 @@ -require 'test/unit' +require "test_helper" require 'openid/store/nonce' module OpenID @@ -78,7 +78,7 @@ def test_check_timestamp # malformed nonce string ['monkeys', 0, 0, false], ] - + cases.each{|c| (nonce_str, allowed_skew, now, expected) = c actual = Nonce::check_timestamp(nonce_str, allowed_skew, now) diff --git a/test/test_oauth.rb b/test/test_oauth.rb index 8c07dfb2..05d904d0 100644 --- a/test/test_oauth.rb +++ b/test/test_oauth.rb @@ -1,3 +1,4 @@ +require 'test_helper' require 'openid/extensions/oauth' require 'openid/message' require 'openid/server' @@ -8,7 +9,7 @@ module OpenID module OAuthTest class OAuthRequestTestCase < Test::Unit::TestCase def setup - @req = OAuth::Request.new + @req = OAuth::Request.new end def test_construct @@ -137,7 +138,7 @@ def test_parse_extension_args_empty end def test_from_success_response - + openid_req_msg = Message.from_openid_args({ 'mode' => 'id_res', 'ns' => OPENID2_NS, diff --git a/test/test_openid_yadis.rb b/test/test_openid_yadis.rb index fb8c71e6..5927b306 100644 --- a/test/test_openid_yadis.rb +++ b/test/test_openid_yadis.rb @@ -1,5 +1,4 @@ - -require 'test/unit' +require "test_helper" require 'openid/consumer/discovery' require 'openid/yadis/services' diff --git a/test/test_pape.rb b/test/test_pape.rb index bd8289c4..9d6a474a 100644 --- a/test/test_pape.rb +++ b/test/test_pape.rb @@ -1,3 +1,4 @@ +require 'test_helper' require 'openid/extensions/pape' require 'openid/message' require 'openid/server' @@ -170,11 +171,11 @@ def test_parse_extension_args_empty assert_equal(nil, @req.auth_time) assert_equal([], @req.auth_policies) end - + def test_parse_extension_args_strict_bogus1 args = {'auth_policies' => 'http://foo http://bar', 'auth_time' => 'this one time'} - assert_raises(ArgumentError) { + assert_raises(ArgumentError) { @req.parse_extension_args(args, true) } end @@ -183,11 +184,11 @@ def test_parse_extension_args_strict_bogus2 args = {'auth_policies' => 'http://foo http://bar', 'auth_time' => '1983-11-05T12:30:24Z', 'nist_auth_level' => 'some'} - assert_raises(ArgumentError) { + assert_raises(ArgumentError) { @req.parse_extension_args(args, true) } end - + def test_parse_extension_args_strict_good args = {'auth_policies' => 'http://foo http://bar', 'auth_time' => '2007-10-11T05:25:18Z', @@ -208,9 +209,9 @@ def test_parse_extension_args_nostrict_bogus assert_equal(nil, @req.nist_auth_level) end - + def test_from_success_response - + openid_req_msg = Message.from_openid_args({ 'mode' => 'id_res', 'ns' => OPENID2_NS, diff --git a/test/test_parsehtml.rb b/test/test_parsehtml.rb index 49542a6a..176cb26d 100644 --- a/test/test_parsehtml.rb +++ b/test/test_parsehtml.rb @@ -1,6 +1,5 @@ -require 'test/unit' +require "test_helper" require "openid/yadis/parsehtml" -require "testutil" module OpenID class ParseHTMLTestCase < Test::Unit::TestCase diff --git a/test/test_responses.rb b/test/test_responses.rb index 61a0e4c1..9ac1daba 100644 --- a/test/test_responses.rb +++ b/test/test_responses.rb @@ -1,4 +1,4 @@ -require "test/unit" +require "test_helper" require "openid/consumer/discovery" require "openid/consumer/responses" diff --git a/test/test_server.rb b/test/test_server.rb index 11d0f567..570169d2 100644 --- a/test/test_server.rb +++ b/test/test_server.rb @@ -1,3 +1,4 @@ +require "test_helper" require 'openid/server' require 'openid/cryptutil' require 'openid/association' @@ -6,10 +7,7 @@ require 'openid/store/memory' require 'openid/dh' require 'openid/consumer/associationmanager' -require 'util' -require "testutil" - -require 'test/unit' +require 'support/test_util' require 'uri' # In general, if you edit or add tests here, try to move in the @@ -208,7 +206,7 @@ def test_dictOfLists begin result = @decode.call(args) rescue ArgumentError => err - assert(!err.to_s.index('values').nil?, err) + assert(!err.to_s.index('values').nil?, err.to_s) else flunk("Expected ArgumentError, but got result #{result}") end @@ -1008,7 +1006,7 @@ def test_cancel assert(webresponse.headers.has_key?('location')) location = webresponse.headers['location'] query = Util.parse_query(URI::parse(location).query) - assert(!query.has_key?('openid.sig'), response.fields.to_post_args()) + assert(!query.has_key?('openid.sig')) end def test_assocReply @@ -1530,7 +1528,7 @@ def test_addField {'blue' => 'star', 'mode' => 'id_res', }) - + assert_equal(@response.fields.get_args(namespace), {'bright' => 'potato'}) end @@ -1613,7 +1611,7 @@ def test_invalid r = @request.answer(@signatory) assert_equal({'is_valid' => 'false'}, r.fields.get_args(OPENID_NS)) - + end def test_replay @@ -1750,7 +1748,7 @@ def test_protoError invalid_s1, invalid_s1_2, ] - + bad_request_argss.each { |request_args| message = Message.from_post_args(request_args) assert_raise(Server::ProtocolError) { @@ -2340,7 +2338,7 @@ def test_getAssocExpired silence_logging { assoc = @signatory.get_association(assoc_handle, true) } - assert(!assoc, assoc) + assert(!assoc) # assert(@messages) end @@ -2428,7 +2426,7 @@ def test_openid1_assoc_checkid 'openid.assoc_type' => 'HMAC-SHA1'} areq = @server.decode_request(assoc_args) aresp = @server.handle_request(areq) - + amess = aresp.fields assert(amess.is_openid1) ahandle = amess.get_arg(OPENID_NS, 'assoc_handle') @@ -2441,7 +2439,7 @@ def test_openid1_assoc_checkid 'openid.return_to' => 'http://example.com/openid/consumer', 'openid.assoc_handle' => ahandle, 'openid.identity' => 'http://foo.com/'} - + cireq = @server.decode_request(checkid_args) ciresp = cireq.answer(true) @@ -2449,7 +2447,7 @@ def test_openid1_assoc_checkid assert_equal(assoc.get_message_signature(signed_resp.fields), signed_resp.fields.get_arg(OPENID_NS, 'sig')) - + assert(assoc.check_message_signature(signed_resp.fields)) end diff --git a/test/test_sreg.rb b/test/test_sreg.rb index 7438d592..ac10c6aa 100644 --- a/test/test_sreg.rb +++ b/test/test_sreg.rb @@ -1,7 +1,7 @@ +require "test_helper" require 'openid/extensions/sreg' require 'openid/message' require 'openid/server' -require 'test/unit' module OpenID module SReg @@ -71,7 +71,7 @@ def initialize @openid1 = false @namespaces = NamespaceMap.new end - + def is_openid1 return @openid1 end @@ -95,7 +95,7 @@ def test_openid1_empty assert_equal('sreg', @msg.namespaces.get_alias(ns_uri)) assert_equal(NS_URI, ns_uri) end - + def test_openid1defined_1_0 @msg.openid1 = true @msg.namespaces.add(NS_URI_1_0) @@ -117,7 +117,7 @@ def test_openid1_defined_1_0_override_alias } } end - + def test_openid1_defined_badly @msg.openid1 = true @msg.namespaces.add_alias('http://invalid/', 'sreg') @@ -182,7 +182,7 @@ def test_from_openid_request_message_copied end def test_from_openid_request_ns_1_0 - message = Message.from_openid_args({'ns.sreg' => NS_URI_1_0, + message = Message.from_openid_args({'ns.sreg' => NS_URI_1_0, "sreg.required" => "nickname"}) openid_req = Server::OpenIDRequest.new openid_req.message = message @@ -214,7 +214,7 @@ def test_parse_extension_args_non_strict req.parse_extension_args({'required' => 'stuff'}) assert_equal([], req.required) end - + def test_parse_extension_args_strict req = Request.new assert_raises(ArgumentError) { @@ -351,7 +351,7 @@ def test_request_fields req.request_fields(fields) assert_equal(fields, req.optional) assert_equal([], req.required) - + # By default, adding the same fields over again has no effect req.request_fields(fields) assert_equal(fields, req.optional) @@ -439,7 +439,7 @@ def test_from_success_response_unsigned }) success_resp = DummySuccessResponse.new(message, {}) sreg_resp = Response.from_success_response(success_resp, false) - assert_equal({'nickname' => 'The Mad Stork'}, + assert_equal({'nickname' => 'The Mad Stork'}, sreg_resp.get_extension_args) end end diff --git a/test/test_stores.rb b/test/test_stores.rb index 115bcc43..048f6f7a 100644 --- a/test/test_stores.rb +++ b/test/test_stores.rb @@ -1,10 +1,4 @@ -require 'test/unit' -require 'openid/store/interface' -require 'openid/store/filesystem' -require 'openid/store/memcache' -require 'openid/store/memory' -require 'openid/util' -require 'openid/store/nonce' +require "test_helper" require 'openid/association' module OpenID @@ -120,7 +114,7 @@ def test_store ret_assoc = @store.get_association(server_url, nil) unexpected = [assoc2.handle, assoc3.handle] assert(ret_assoc.nil? || !unexpected.member?(ret_assoc.handle), - ret_assoc) + ret_assoc.to_s) _check_retrieve(server_url, assoc.handle, assoc) _check_retrieve(server_url, assoc2.handle, nil) diff --git a/test/test_trustroot.rb b/test/test_trustroot.rb index 2616021a..28e2b7b7 100644 --- a/test/test_trustroot.rb +++ b/test/test_trustroot.rb @@ -1,8 +1,6 @@ -require 'test/unit' +require "test_helper" require 'openid/trustroot' -require "testutil" - class TrustRootTest < Test::Unit::TestCase include OpenID::TestDataMixin @@ -10,11 +8,11 @@ def _test_sanity(case_, sanity, desc) tr = OpenID::TrustRoot::TrustRoot.parse(case_) if sanity == 'sane' assert(! tr.nil?) - assert(tr.sane?, [case_, desc]) - assert(OpenID::TrustRoot::TrustRoot.check_sanity(case_), [case_, desc]) + assert(tr.sane?) + assert(OpenID::TrustRoot::TrustRoot.check_sanity(case_)) elsif sanity == 'insane' - assert(!tr.sane?, [case_, desc]) - assert(!OpenID::TrustRoot::TrustRoot.check_sanity(case_), [case_, desc]) + assert(!tr.sane?) + assert(!OpenID::TrustRoot::TrustRoot.check_sanity(case_)) else assert(tr.nil?, case_) end @@ -24,10 +22,10 @@ def _test_match(trust_root, url, expected_match) tr = OpenID::TrustRoot::TrustRoot.parse(trust_root) actual_match = tr.validate_url(url) if expected_match - assert(actual_match, [trust_root, url]) + assert(actual_match) assert(OpenID::TrustRoot::TrustRoot.check_url(trust_root, url)) else - assert(!actual_match, [expected_match, actual_match, trust_root, url]) + assert(!actual_match) assert(!OpenID::TrustRoot::TrustRoot.check_url(trust_root, url)) end end @@ -56,7 +54,7 @@ def getTests(grps, head, dat) top = head.strip() gdat = dat.split('-' * 40 + "\n").collect { |i| i.strip() } assert(gdat[0] == '') - assert(gdat.length == (grps.length * 2 + 1), [gdat, grps]) + assert(gdat.length == (grps.length * 2 + 1), "length match failed: gdat #{gdat}, grps #{grps}") i = 1 grps.each { |x| n, desc = gdat[i].split(': ') @@ -107,7 +105,7 @@ def test_build_discovery_url trust_root, expected_disco_url = case_ tr = OpenID::TrustRoot::TrustRoot.parse(trust_root) actual_disco_url = tr.build_discovery_url() - assert(actual_disco_url == expected_disco_url, case_ + [actual_disco_url]) + assert(actual_disco_url == expected_disco_url) } end end diff --git a/test/test_urinorm.rb b/test/test_urinorm.rb index 55c50e1c..39752536 100644 --- a/test/test_urinorm.rb +++ b/test/test_urinorm.rb @@ -1,7 +1,6 @@ -require 'test/unit' +require "test_helper" require "openid/urinorm" -require "testutil" class URINormTestCase < Test::Unit::TestCase include OpenID::TestDataMixin diff --git a/test/test_util.rb b/test/test_util.rb index ce1138ae..e19cf125 100644 --- a/test/test_util.rb +++ b/test/test_util.rb @@ -1,5 +1,5 @@ # coding: ASCII-8BIT -require 'test/unit' +require "test_helper" require "openid/util" diff --git a/test/test_xrds.rb b/test/test_xrds.rb index ced78028..46bdd87c 100644 --- a/test/test_xrds.rb +++ b/test/test_xrds.rb @@ -1,8 +1,6 @@ - -require 'test/unit' +require "test_helper" require 'openid/yadis/xrds' -require 'testutil' module OpenID module Yadis diff --git a/test/test_xri.rb b/test/test_xri.rb index ba20e9c4..deedf368 100644 --- a/test/test_xri.rb +++ b/test/test_xri.rb @@ -1,4 +1,4 @@ -require 'test/unit' +require "test_helper" require 'openid/yadis/xri' module OpenID diff --git a/test/test_xrires.rb b/test/test_xrires.rb index 3959361b..6bf5dbbd 100644 --- a/test/test_xrires.rb +++ b/test/test_xrires.rb @@ -1,5 +1,4 @@ - -require 'test/unit' +require "test_helper" require 'openid/yadis/xrires' module OpenID @@ -27,6 +26,10 @@ def setup @servicetype_enc = 'xri%3A%2F%2F%2Bi-service%2A%28%2Bforwarding%29%2A%28%24v%2A1.0%29' end + def unesc(s) + CGI::unescape(s) + end + def test_proxy_url st = @servicetype ste = @servicetype_enc @@ -34,17 +37,17 @@ def test_proxy_url pqu = @proxy.method('query_url') h = @proxy_url - assert_equal(h + '=foo?' + args_esc, pqu.call('=foo', st)) - assert_equal(h + '=foo/bar?baz&' + args_esc, - pqu.call('=foo/bar?baz', st)) - assert_equal(h + '=foo/bar?baz=quux&' + args_esc, - pqu.call('=foo/bar?baz=quux', st)) - assert_equal(h + '=foo/bar?mi=fa&so=la&' + args_esc, - pqu.call('=foo/bar?mi=fa&so=la', st)) + assert_equal(unesc(h + '=foo?' + args_esc), unesc(pqu.call('=foo', st))) + assert_equal(unesc(h + '=foo/bar?baz&' + args_esc), + unesc(pqu.call('=foo/bar?baz', st))) + assert_equal(unesc(h + '=foo/bar?baz=quux&' + args_esc), + unesc(pqu.call('=foo/bar?baz=quux', st))) + assert_equal(unesc(h + '=foo/bar?mi=fa&so=la&' + args_esc), + unesc(pqu.call('=foo/bar?mi=fa&so=la', st))) # With no service endpoint selection. args_esc = "_xrd_r=application%2Fxrds%2Bxml%3Bsep%3Dfalse" - assert_equal(h + '=foo?' + args_esc, pqu.call('=foo', nil)) + assert_equal(unesc(h + '=foo?' + args_esc), unesc(pqu.call('=foo', nil))) end def test_proxy_url_qmarks @@ -54,9 +57,10 @@ def test_proxy_url_qmarks pqu = @proxy.method('query_url') h = @proxy_url - assert_equal(h + '=foo/bar??' + args_esc, pqu.call('=foo/bar?', st)) - assert_equal(h + '=foo/bar????' + args_esc, - pqu.call('=foo/bar???', st)) + assert_equal(unesc(h + '=foo/bar?' + args_esc), + unesc(pqu.call('=foo/bar??', st))) + assert_equal(unesc(h + '=foo/bar?' + args_esc), + unesc(pqu.call('=foo/bar???', st))) end end end diff --git a/test/test_yadis_discovery.rb b/test/test_yadis_discovery.rb index b0fdd178..31af3c41 100644 --- a/test/test_yadis_discovery.rb +++ b/test/test_yadis_discovery.rb @@ -1,18 +1,16 @@ - -require 'test/unit' +require "test_helper" require 'uri' -require 'testutil' require 'openid/yadis/discovery' require 'openid/fetchers' require 'openid/util' -require 'discoverdata' +require 'support/yadis_data' module OpenID module YadisDiscovery include FetcherMixin - include DiscoverData + include YadisData STATUS_HEADER_RE = /Status: (\d+) .*?$/m @@ -34,7 +32,7 @@ def self.mkResponse(data) end class TestFetcher - include DiscoverData + include YadisData def initialize(base_url) @base_url = base_url @@ -94,7 +92,7 @@ def test_404 end class DiscoveryTestCase - include DiscoverData + include YadisData include FetcherMixin def initialize(testcase, input_name, id_name, result_name, success) @@ -172,7 +170,7 @@ class TestYadisDiscovery < Test::Unit::TestCase include FetcherMixin def test_yadis_discovery - DiscoverData::TESTLIST.each { |success, input_name, id_name, result_name| + YadisData::TESTLIST.each { |success, input_name, id_name, result_name| test = DiscoveryTestCase.new(self, input_name, id_name, result_name, success) test.runCustomTest } From 6131a3eab5efe55ea4c4b2a811163c133927fd2a Mon Sep 17 00:00:00 2001 From: Mike Mell Date: Mon, 31 Oct 2011 17:15:01 -0700 Subject: [PATCH 14/22] fix segfault in ruby 1.9.2-290 --- lib/openid/dh.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/openid/dh.rb b/lib/openid/dh.rb index cbe53114..25b6aa0c 100644 --- a/lib/openid/dh.rb +++ b/lib/openid/dh.rb @@ -56,13 +56,11 @@ def DiffieHellman.strxor(s, t) "Inputs were #{s.inspect} and #{t.inspect}" end - if String.method_defined? :bytes - s.bytes.zip(t.bytes).map{|sb,tb| sb^tb}.pack('C*') - else - indices = 0...(s.length) - chrs = indices.collect {|i| (s[i]^t[i]).chr} - chrs.join("") - end + s.unpack('C*').zip( + t.unpack('C*') + ).map { + |sb, tb| sb^tb + }.pack('C*') end # This code is taken from this post: From eaf8ab6882152d3a58df97516b3acb6de036dda4 Mon Sep 17 00:00:00 2001 From: Mike Mell Date: Mon, 31 Oct 2011 17:18:25 -0700 Subject: [PATCH 15/22] fix problem with existing query marker --- lib/openid/yadis/xrires.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/openid/yadis/xrires.rb b/lib/openid/yadis/xrires.rb index a80600ea..27fe9d1a 100644 --- a/lib/openid/yadis/xrires.rb +++ b/lib/openid/yadis/xrires.rb @@ -80,7 +80,7 @@ def self.append_args(url, args) sep = '?' end - return url + sep + XRI.urlencode(args) + return rstripped + sep + XRI.urlencode(args) end end From e426dd423e91009b56d09da15b056063b0ec3e0c Mon Sep 17 00:00:00 2001 From: Mike Mell Date: Tue, 1 Nov 2011 13:30:02 -0700 Subject: [PATCH 16/22] fix problem with trailing separator --- lib/openid/yadis/xrires.rb | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/openid/yadis/xrires.rb b/lib/openid/yadis/xrires.rb index 27fe9d1a..4aada804 100644 --- a/lib/openid/yadis/xrires.rb +++ b/lib/openid/yadis/xrires.rb @@ -68,14 +68,11 @@ def self.urlencode(args) def self.append_args(url, args) return url if args.length == 0 - # rstrip question marks - rstripped = url.dup - while rstripped[-1].chr == '?' - rstripped = rstripped[0...rstripped.length-1] - end + # strip all trailing question marks + rstripped = url.dup.sub(/\?+\z/, '').sub(/(%3F)+\z/, '') - if rstripped.index('?') - sep = '&' + if rstripped.include?('?') or rstripped.include?('%3F') + sep = ( rstripped[-1] == '&' ? '' : '&' ) else sep = '?' end From 8cd54946bcc43d7be6c8235bdabddef18e5495a1 Mon Sep 17 00:00:00 2001 From: Mike Mell Date: Thu, 3 Nov 2011 10:19:45 -0700 Subject: [PATCH 17/22] clarify error classes --- lib/openid/protocolerror.rb | 4 ++++ lib/openid/util.rb | 3 +++ 2 files changed, 7 insertions(+) diff --git a/lib/openid/protocolerror.rb b/lib/openid/protocolerror.rb index 2aad0e4a..9981353c 100644 --- a/lib/openid/protocolerror.rb +++ b/lib/openid/protocolerror.rb @@ -3,6 +3,10 @@ module OpenID # An error in the OpenID protocol + # + # Note: there is also a OpenID::Server::ProtocolError which is + # a distinct class used exclusively in Server contexts + # class ProtocolError < OpenIDError end end diff --git a/lib/openid/util.rb b/lib/openid/util.rb index c5a6716b..8f8ccc0c 100644 --- a/lib/openid/util.rb +++ b/lib/openid/util.rb @@ -13,6 +13,9 @@ class AssertionError < Exception # exception type, so if you want to catch all exceptions raised by # the library, you can catch OpenIDError class OpenIDError < StandardError + def initialize(*msgs) + super(msgs.join(', ')) + end end module Util From e1be9071207362497c7b04cd55cf4950e6d4a126 Mon Sep 17 00:00:00 2001 From: Mike Mell Date: Thu, 3 Nov 2011 10:33:32 -0700 Subject: [PATCH 18/22] address change in Rails 3 path_parameters key format --- .../rails_openid/app/controllers/consumer_controller.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/rails_openid/app/controllers/consumer_controller.rb b/examples/rails_openid/app/controllers/consumer_controller.rb index a42b2724..cd5553aa 100644 --- a/examples/rails_openid/app/controllers/consumer_controller.rb +++ b/examples/rails_openid/app/controllers/consumer_controller.rb @@ -47,7 +47,7 @@ def start end return_to = url_for :action => 'complete', :only_path => false realm = url_for :action => 'index', :id => nil, :only_path => false - + if oidreq.send_redirect?(realm, return_to, params[:immediate]) redirect_to oidreq.redirect_url(realm, return_to, params[:immediate]) else @@ -58,7 +58,10 @@ def start def complete # FIXME - url_for some action is not necessarily the current URL. current_url = url_for(:action => 'complete', :only_path => false) - parameters = params.reject{|k,v|request.path_parameters[k]} + parameters = params.reject { |k,v| + # params keys are String; Rails 3.1 path_parameters keys are Symbol + request.path_parameters[k.to_sym] + } oidresp = consumer.complete(parameters, current_url) case oidresp.status when OpenID::Consumer::FAILURE From 5f77852cf5e9b5279771d4bfd4e0156345146767 Mon Sep 17 00:00:00 2001 From: Mike Mell Date: Thu, 3 Nov 2011 13:04:38 -0700 Subject: [PATCH 19/22] bump patch version --- lib/openid/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/openid/version.rb b/lib/openid/version.rb index ea3598d8..fc57f357 100644 --- a/lib/openid/version.rb +++ b/lib/openid/version.rb @@ -1,3 +1,3 @@ module OpenID - VERSION = "2.1.8" + VERSION = "2.1.9" end From 3c4ebc068ca47cbd3a3e86ee0792b224fb741b0b Mon Sep 17 00:00:00 2001 From: Mike Mell Date: Thu, 3 Nov 2011 13:30:49 -0700 Subject: [PATCH 20/22] add CHANGES-2.1.9 --- CHANGES-2.1.9 | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 CHANGES-2.1.9 diff --git a/CHANGES-2.1.9 b/CHANGES-2.1.9 new file mode 100644 index 00000000..4ff39457 --- /dev/null +++ b/CHANGES-2.1.9 @@ -0,0 +1,18 @@ +Changes in ruby-openid 2.1.9 + +* added Gemfile and Rakefile. Tests are easily run with + $ rake test + +* Renamed the gemspec file and fixed a deprecation warning about "SPEC" + +* restructured the test directory to match current practices + +* fixed SEGFAULT in lib/openid/dh.rb running in Ruby 1.9.2-290 + +* fixed bugs in lib/openid/yadis/xrires.rb. Tests were failing. + +* fixed problem in Rails 3 with example consumer code handing Rails path_parameters to Consumer.complete + examples/rails_openid/app/controllers/consumer_controller.rb + Existing clients migrating to Rails 3 need to match this change: + parameters = params.reject{ |k,v| request.path_parameters[k.to_sym] } # params keys are String; path_parameters keys are Symbol + See: https://rails.lighthouseapp.com/projects/8994/tickets/3738-breaking-change-in-requestpath_parameters From 27372f2e72f63d1c59b792c11932dcbad00e0c9f Mon Sep 17 00:00:00 2001 From: Mike Mell Date: Thu, 3 Nov 2011 14:39:31 -0700 Subject: [PATCH 21/22] fix the gemspec description --- ruby-openid.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruby-openid.gemspec b/ruby-openid.gemspec index df9a7156..b1d1045d 100644 --- a/ruby-openid.gemspec +++ b/ruby-openid.gemspec @@ -9,7 +9,7 @@ Gem::Specification.new do |s| s.email = ["openid@janrain.com", "mike.mell@nthwave.net"] s.homepage = 'https://github.com/mmell/ruby-openid' s.summary = 'A library for consuming and serving OpenID identities.' - s.description = %q{TODO: Write a gem description} + s.description = s.summary s.rubyforge_project = "ruby-openid" From f77dd9e9d056f1d30c0f9f4b0b3d451f415478e7 Mon Sep 17 00:00:00 2001 From: Courtenay Date: Wed, 22 Feb 2012 21:20:45 -0800 Subject: [PATCH 22/22] Make this work on ruby 1.8 and 1.9 both. --- lib/openid/yadis/xrires.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/openid/yadis/xrires.rb b/lib/openid/yadis/xrires.rb index 233826b1..c9cf6e6c 100644 --- a/lib/openid/yadis/xrires.rb +++ b/lib/openid/yadis/xrires.rb @@ -13,7 +13,7 @@ class XRIHTTPError < StandardError; end class ProxyResolver - DEFAULT_PROXY ||= 'http://proxy.xri.net/' + DEFAULT_PROXY = 'http://proxy.xri.net/' unless defined?(DEFAULT_PROXY) def initialize(proxy_url=nil) if proxy_url