Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/agoragames/ruby-openid
Browse files Browse the repository at this point in the history
Conflicts:
	lib/openid.rb
	lib/openid/store/memcache.rb
	lib/openid/util.rb
	ruby-openid.gemspec
	test/test_accept.rb
	test/test_association.rb
	test/test_associationmanager.rb

Reverted Mike Mell's changes to memcached store in favor of agoragames memcached Dalli changes.
  • Loading branch information
Joseph Chen committed Mar 23, 2012
1 parent 1c1aa19 commit 6c9189d
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 23 deletions.
9 changes: 5 additions & 4 deletions lib/openid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
1 change: 1 addition & 0 deletions lib/openid/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<form "

Expand Down
22 changes: 14 additions & 8 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.write(key, serialized, :expires_in => association.lifetime.seconds.to_i)
@cache_client.set(key, serialized, expiry(association.lifetime))
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.read(assoc_key(server_url, handle))
serialized = @cache_client.get(assoc_key(server_url, handle))
if serialized
return deserialize(serialized)
else
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
13 changes: 6 additions & 7 deletions lib/openid/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand All @@ -97,9 +96,9 @@ def Util.auto_submit_html(form, title='OpenID transaction in progress')
<style>form { visibility: hidden }</style>
<script>
var server_proceed = setTimeout(function() {
if (typeof document.forms[0] == 'object') {
if (typeof document.getElementById('#{HTML_FORM_ID}') == 'object') {
clearTimeout(server_proceed);
document.forms[0].submit();
document.getElementById('#{HTML_FORM_ID}').submit();
}
}, 100);
</script>
Expand Down
7 changes: 3 additions & 4 deletions ruby-openid.gemspec
Original file line number Diff line number Diff line change
@@ -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 = '[email protected]'
s.homepage = 'http://github.com/openid/ruby-openid'
Expand Down
1 change: 1 addition & 0 deletions test/test_message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,7 @@ def setup
'accept-charset' => 'UTF-8',
'enctype' => 'application/x-www-form-urlencoded',
'method' => 'post',
'id' => Util::HTML_FORM_ID
}
end

Expand Down
10 changes: 10 additions & 0 deletions test/test_util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6c9189d

Please sign in to comment.