diff --git a/lib/openid.rb b/lib/openid.rb index ccb3ad91..d3758157 100644 --- a/lib/openid.rb +++ b/lib/openid.rb @@ -12,11 +12,12 @@ # implied. See the License for the specific language governing # permissions and limitations under the License. +module OpenID + VERSION = "2.1.9.3" +end + require "openid/version" require 'openid/store' require 'openid/yadis' require "openid/consumer" -require 'openid/server' - -module OpenID -end +require 'openid/server' \ No newline at end of file diff --git a/lib/openid/message.rb b/lib/openid/message.rb index c494f469..282497bd 100644 --- a/lib/openid/message.rb +++ b/lib/openid/message.rb @@ -278,6 +278,7 @@ def to_form_markup(action_url, form_tag_attrs=nil, submit_text='Continue') form_tag_attr_map['method'] = 'post' form_tag_attr_map['accept-charset'] = 'UTF-8' form_tag_attr_map['enctype'] = 'application/x-www-form-urlencoded' + form_tag_attr_map['id'] = OpenID::Util::HTML_FORM_ID markup = "
association.lifetime.seconds.to_i) + @cache_client.set(key, serialized, expiry(association.lifetime)) 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.read(assoc_key(server_url, handle)) + serialized = @cache_client.get(assoc_key(server_url, handle)) if serialized return deserialize(serialized) else @@ -62,9 +62,12 @@ 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.read(nonce_key) - @cache_client.write(nonce_key, nonce_key, :expires_in => (Nonce.skew() + 5)) - result.nil? + result = @cache_client.add(nonce_key, '', expiry(Nonce.skew + 5)) + if result.is_a? String + return !!(result =~ /^STORED/) + else + return result == true + end end def assoc_key(server_url, assoc_handle=nil) @@ -87,9 +90,12 @@ def cleanup_associations protected def delete(key) - # result = @cache_client.delete(key) # memcached delete seems to be broken - # return !!(result =~ /^DELETED/) - @cache_client.write(key, nil, :expires_in => 0) + result = @cache_client.delete(key) + if result.is_a? String + return !!(result =~ /^DELETED/) + else + return result == true + end end def serialize(assoc) diff --git a/lib/openid/util.rb b/lib/openid/util.rb index 8c243124..40d84c7f 100644 --- a/lib/openid/util.rb +++ b/lib/openid/util.rb @@ -29,6 +29,8 @@ module Util [#{BASE64_CHARS}]{3}=)? \\Z", Regexp::EXTENDED) + HTML_FORM_ID = 'openid_transaction_in_progress' + def Util.assert(value, message=nil) if not value raise AssertionError, message or value @@ -74,20 +76,17 @@ def Util.append_args(url, args) url << Util.urlencode(args) end - @@logger = Logger.new(STDERR) - @@logger.progname = "OpenID" - def Util.logger=(logger) @@logger = logger end def Util.logger - @@logger + @@logger ||= Logger.new(STDERR, { :progname => 'OpenID' }) end # change the message below to do whatever you like for logging def Util.log(message) - logger.info(message) + Util.logger.info(message) end def Util.auto_submit_html(form, title='OpenID transaction in progress') @@ -97,9 +96,9 @@ def Util.auto_submit_html(form, title='OpenID transaction in progress') diff --git a/ruby-openid.gemspec b/ruby-openid.gemspec index c3896672..a48cba07 100644 --- a/ruby-openid.gemspec +++ b/ruby-openid.gemspec @@ -1,9 +1,8 @@ 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.9.2' +spec = Gem::Specification.new do |s| + s.name = 'ruby-openid' + s.version = '2.1.9.3' s.author = 'JanRain, Inc' s.email = 'openid@janrain.com' s.homepage = 'http://github.com/openid/ruby-openid' diff --git a/test/test_message.rb b/test/test_message.rb index 412b8bf3..b84818ab 100644 --- a/test/test_message.rb +++ b/test/test_message.rb @@ -918,6 +918,7 @@ def setup 'accept-charset' => 'UTF-8', 'enctype' => 'application/x-www-form-urlencoded', 'method' => 'post', + 'id' => Util::HTML_FORM_ID } end diff --git a/test/test_util.rb b/test/test_util.rb index e19cf125..26565f75 100644 --- a/test/test_util.rb +++ b/test/test_util.rb @@ -140,6 +140,16 @@ def test_append_args() def test_parse_query assert_equal({'foo'=>'bar'}, Util.parse_query('foo=bar')) end + + def test_defines_html_form_id + assert Util::HTML_FORM_ID + end + + def test_auto_submit_html_looks_for_html_form_id_to_submit + auto_submit_html_output = Util.auto_submit_html('form_data') + assert auto_submit_html_output =~ Regexp.new(Regexp.escape("document.getElementById('#{Util::HTML_FORM_ID}')")) + assert auto_submit_html_output =~ Regexp.new(Regexp.escape("document.getElementById('#{Util::HTML_FORM_ID}').submit();")) + end end end