Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Extensions for StoreRequest and differentiation for ax modes

  • Loading branch information...
commit 4ac2e1192e5317e6fec0cec6407ba740b1c7040d 1 parent ef53840
@dbloete dbloete authored chowells79 committed
Showing with 72 additions and 7 deletions.
  1. +28 −5 lib/openid/extensions/ax.rb
  2. +44 −2 test/test_ax.rb
View
33 lib/openid/extensions/ax.rb
@@ -110,10 +110,12 @@ def self.to_type_uris(namespace_map, alias_list_s)
class FetchRequest < AXMessage
attr_reader :requested_attributes
attr_accessor :update_url
+
+ MODE = 'fetch_request'
def initialize(update_url = nil)
super()
- @mode = 'fetch_request'
+ @mode = MODE
@requested_attributes = {}
@update_url = update_url
end
@@ -180,7 +182,7 @@ def get_required_attrs
def self.from_openid_request(oidreq)
message = oidreq.message
ax_args = message.get_args(NS_URI)
- return nil if ax_args == {}
+ return nil if ax_args == {} or ax_args['mode'] != MODE
req = new
req.parse_extension_args(ax_args)
@@ -467,11 +469,26 @@ def self.from_success_response(success_response, signed=true)
# A store request attribute exchange message representation
class StoreRequest < KeyValueMessage
+
+ MODE = 'store_request'
+
def initialize
super
- @mode = 'store_request'
+ @mode = MODE
end
-
+
+ # Extract a StoreRequest from an OpenID message
+ # message: OpenID::Message
+ # return a StoreRequest or nil if AX arguments are not present
+ def self.from_openid_request(oidreq)
+ message = oidreq.message
+ ax_args = message.get_args(NS_URI)
+ return nil if ax_args.empty? or ax_args['mode'] != MODE
+ req = new
+ req.parse_extension_args(ax_args)
+ req
+ end
+
def get_extension_args(aliases=nil)
ax_args = new_args
kv_args = _get_extension_kv_args(aliases)
@@ -499,7 +516,13 @@ def initialize(succeeded = true, error_message = nil)
end
@error_message = error_message
end
-
+
+ def self.from_success_response(success_response)
+ resp = nil
+ ax_args = success_response.message.get_args(NS_URI)
+ resp = ax_args.key?('error') ? new(false, ax_args['error']) : new
+ end
+
def succeeded?
@mode == SUCCESS_MODE
end
View
46 test/test_ax.rb
@@ -371,7 +371,28 @@ def test_from_openid_request_no_ax
ax_req = FetchRequest.from_openid_request(openid_req)
assert(ax_req.nil?)
end
-
+
+ def test_from_openid_request_wrong_ax_mode
+ uri = 'http://under.the.sea/'
+ name = 'ext0'
+ value = 'snarfblat'
+
+ message = OpenID::Message.from_openid_args({
+ 'mode' => 'id_res',
+ 'ns' => OPENID2_NS,
+ 'ns.ax' => AXMessage::NS_URI,
+ 'ax.update_url' => 'http://example.com/realm/update_path',
+ 'ax.mode' => 'store_request',
+ 'ax.type.' + name => uri,
+ 'ax.count.' + name => '1',
+ 'ax.value.' + name + '.1' => value
+ })
+ openid_req = Server::OpenIDRequest.new
+ openid_req.message = message
+ ax_req = FetchRequest.from_openid_request(openid_req)
+ assert(ax_req.nil?)
+ end
+
def test_openid_update_url_verification_error
openid_req_msg = Message.from_openid_args({
'mode' => 'checkid_setup',
@@ -602,7 +623,28 @@ def test_get_extension_args_empty
}
assert_equal(eargs, @msg.get_extension_args)
end
-
+
+ def test_from_openid_request_wrong_ax_mode
+ uri = 'http://under.the.sea/'
+ name = 'ext0'
+ value = 'snarfblat'
+
+ message = OpenID::Message.from_openid_args({
+ 'mode' => 'id_res',
+ 'ns' => OPENID2_NS,
+ 'ns.ax' => AXMessage::NS_URI,
+ 'ax.update_url' => 'http://example.com/realm/update_path',
+ 'ax.mode' => 'fetch_request',
+ 'ax.type.' + name => uri,
+ 'ax.count.' + name => '1',
+ 'ax.value.' + name + '.1' => value
+ })
+ openid_req = Server::OpenIDRequest.new
+ openid_req.message = message
+ ax_req = StoreRequest.from_openid_request(openid_req)
+ assert(ax_req.nil?)
+ end
+
def test_get_extension_args_nonempty
@msg.set_values(@type_a, ['foo','bar'])
aliases = NamespaceMap.new
Please sign in to comment.
Something went wrong with that request. Please try again.