Skip to content

Commit

Permalink
Merge branch 'mmell-master'
Browse files Browse the repository at this point in the history
Conflicts:
	lib/openid/dh.rb
	lib/openid/store/memcache.rb
	ruby-openid.gemspec
  • Loading branch information
courtenay committed Feb 23, 2012
2 parents 30f3d65 + f77dd9e commit 4aaff96
Show file tree
Hide file tree
Showing 95 changed files with 338 additions and 308 deletions.
18 changes: 18 additions & 0 deletions CHANGES-2.1.9
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source "http://rubygems.org"

gemspec

gem "test-unit"
15 changes: 15 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -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
7 changes: 5 additions & 2 deletions examples/rails_openid/app/controllers/consumer_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 6 additions & 4 deletions lib/openid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 5 additions & 5 deletions lib/openid/consumer/idres.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/openid/fetchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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})"
Expand Down
4 changes: 4 additions & 0 deletions lib/openid/protocolerror.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 10 additions & 0 deletions lib/openid/store.rb
Original file line number Diff line number Diff line change
@@ -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
22 changes: 8 additions & 14 deletions lib/openid/store/memcache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.to_i)
end
end

Expand All @@ -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
Expand Down Expand Up @@ -62,12 +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))
if result.is_a? String
return !!(result =~ /^STORED/)
else
return result == true
end
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)
Expand All @@ -90,12 +87,9 @@ def cleanup_associations
protected

def delete(key)
result = @cache_client.delete(key)
if result.is_a? String
return !!(result =~ /^DELETED/)
else
return result == true
end
# 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)
Expand Down
3 changes: 3 additions & 0 deletions lib/openid/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions lib/openid/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module OpenID
VERSION = "2.1.9"
end
15 changes: 15 additions & 0 deletions lib/openid/yadis.rb
Original file line number Diff line number Diff line change
@@ -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
42 changes: 17 additions & 25 deletions lib/openid/yadis/xrires.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,33 +30,28 @@ 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
else
# don't perform service endpoint selection
args['_xrd_r'] += ';sep=false'
end
args['_xrd_t'] = service_type if service_type

return XRI.append_args(hxri, args)
end

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
raise XRIHTTPError, "Could not fetch #{xri}" if response.nil?
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)
canonicalID = Yadis::get_canonical_id(xri, xrds)
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)
# TODO:
Expand All @@ -77,19 +72,16 @@ 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

return url + sep + XRI.urlencode(args)
return rstripped + sep + XRI.urlencode(args)
end

end
Expand Down
2 changes: 1 addition & 1 deletion test/testutil.rb → test/support/test_data_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions test/discoverdata.rb → test/support/yadis_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

module OpenID

module DiscoverData
module YadisData

include TestDataMixin
include Util
include TestUtil

TESTLIST = [
# success, input_name, id_name, result_name
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 2 additions & 3 deletions test/test_accept.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@

require 'test/unit'
require "test_helper"
require 'openid/yadis/accept'
require 'openid/extras'
require 'openid/util'
require 'testutil'
require 'test_util'

module OpenID

Expand Down
5 changes: 3 additions & 2 deletions test/test_association.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require "test/unit"
require 'test_helper'
require 'support/test_util'
require "openid/association"
require 'testutil'
require 'test_util'

module OpenID
class AssociationTestCase < Test::Unit::TestCase
Expand Down
6 changes: 3 additions & 3 deletions test/test_associationmanager.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
require 'test_helper'
require 'support/test_util'
require "openid/consumer/associationmanager"
require "openid/association"
require "openid/dh"
require "openid/util"
require "openid/cryptutil"
require "openid/message"
require "openid/store/memory"
require "test/unit"
require "util"
require "time"
require 'testutil'
require 'test_util'

module OpenID
class DHAssocSessionTest < Test::Unit::TestCase
Expand Down
5 changes: 2 additions & 3 deletions test/test_checkid_request.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/test_consumer.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'
require 'support/test_util'
require "openid/consumer"
require "test/unit"
require "testutil"

module OpenID
class Consumer
Expand Down
Loading

0 comments on commit 4aaff96

Please sign in to comment.