nov-ruby-openid 2.1.9
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +215 -0
- data/CHANGES-2.1.0 +36 -0
- data/INSTALL +47 -0
- data/LICENSE +210 -0
- data/NOTICE +2 -0
- data/README +81 -0
- data/Rakefile +98 -0
- data/UPGRADE +127 -0
- data/VERSION +1 -0
- data/contrib/google/ruby-openid-apps-discovery-1.0.gem +0 -0
- data/contrib/google/ruby-openid-apps-discovery-1.01.gem +0 -0
- data/examples/README +32 -0
- data/examples/active_record_openid_store/README +58 -0
- data/examples/active_record_openid_store/XXX_add_open_id_store_to_db.rb +24 -0
- data/examples/active_record_openid_store/XXX_upgrade_open_id_store.rb +26 -0
- data/examples/active_record_openid_store/init.rb +8 -0
- data/examples/active_record_openid_store/lib/association.rb +10 -0
- data/examples/active_record_openid_store/lib/nonce.rb +3 -0
- data/examples/active_record_openid_store/lib/open_id_setting.rb +4 -0
- data/examples/active_record_openid_store/lib/openid_ar_store.rb +57 -0
- data/examples/active_record_openid_store/test/store_test.rb +212 -0
- data/examples/discover +49 -0
- data/examples/rails_openid/README +153 -0
- data/examples/rails_openid/Rakefile +10 -0
- data/examples/rails_openid/app/controllers/application.rb +4 -0
- data/examples/rails_openid/app/controllers/consumer_controller.rb +122 -0
- data/examples/rails_openid/app/controllers/login_controller.rb +45 -0
- data/examples/rails_openid/app/controllers/server_controller.rb +265 -0
- data/examples/rails_openid/app/helpers/application_helper.rb +3 -0
- data/examples/rails_openid/app/helpers/login_helper.rb +2 -0
- data/examples/rails_openid/app/helpers/server_helper.rb +9 -0
- data/examples/rails_openid/app/views/consumer/index.rhtml +81 -0
- data/examples/rails_openid/app/views/layouts/server.rhtml +68 -0
- data/examples/rails_openid/app/views/login/index.rhtml +56 -0
- data/examples/rails_openid/app/views/server/decide.rhtml +26 -0
- data/examples/rails_openid/config/boot.rb +19 -0
- data/examples/rails_openid/config/database.yml +74 -0
- data/examples/rails_openid/config/environment.rb +54 -0
- data/examples/rails_openid/config/environments/development.rb +19 -0
- data/examples/rails_openid/config/environments/production.rb +19 -0
- data/examples/rails_openid/config/environments/test.rb +19 -0
- data/examples/rails_openid/config/routes.rb +24 -0
- data/examples/rails_openid/doc/README_FOR_APP +2 -0
- data/examples/rails_openid/public/.htaccess +40 -0
- data/examples/rails_openid/public/404.html +8 -0
- data/examples/rails_openid/public/500.html +8 -0
- data/examples/rails_openid/public/dispatch.cgi +12 -0
- data/examples/rails_openid/public/dispatch.fcgi +26 -0
- data/examples/rails_openid/public/dispatch.rb +12 -0
- data/examples/rails_openid/public/favicon.ico +0 -0
- data/examples/rails_openid/public/images/openid_login_bg.gif +0 -0
- data/examples/rails_openid/public/javascripts/controls.js +750 -0
- data/examples/rails_openid/public/javascripts/dragdrop.js +584 -0
- data/examples/rails_openid/public/javascripts/effects.js +854 -0
- data/examples/rails_openid/public/javascripts/prototype.js +1785 -0
- data/examples/rails_openid/public/robots.txt +1 -0
- data/examples/rails_openid/script/about +3 -0
- data/examples/rails_openid/script/breakpointer +3 -0
- data/examples/rails_openid/script/console +3 -0
- data/examples/rails_openid/script/destroy +3 -0
- data/examples/rails_openid/script/generate +3 -0
- data/examples/rails_openid/script/performance/benchmarker +3 -0
- data/examples/rails_openid/script/performance/profiler +3 -0
- data/examples/rails_openid/script/plugin +3 -0
- data/examples/rails_openid/script/process/reaper +3 -0
- data/examples/rails_openid/script/process/spawner +3 -0
- data/examples/rails_openid/script/process/spinner +3 -0
- data/examples/rails_openid/script/runner +3 -0
- data/examples/rails_openid/script/server +3 -0
- data/examples/rails_openid/test/functional/login_controller_test.rb +18 -0
- data/examples/rails_openid/test/functional/server_controller_test.rb +18 -0
- data/examples/rails_openid/test/test_helper.rb +28 -0
- data/lib/hmac/hmac.rb +112 -0
- data/lib/hmac/sha1.rb +11 -0
- data/lib/hmac/sha2.rb +25 -0
- data/lib/openid.rb +20 -0
- data/lib/openid/association.rb +249 -0
- data/lib/openid/consumer.rb +395 -0
- data/lib/openid/consumer/associationmanager.rb +344 -0
- data/lib/openid/consumer/checkid_request.rb +186 -0
- data/lib/openid/consumer/discovery.rb +497 -0
- data/lib/openid/consumer/discovery_manager.rb +123 -0
- data/lib/openid/consumer/html_parse.rb +134 -0
- data/lib/openid/consumer/idres.rb +523 -0
- data/lib/openid/consumer/responses.rb +148 -0
- data/lib/openid/cryptutil.rb +115 -0
- data/lib/openid/dh.rb +89 -0
- data/lib/openid/extension.rb +39 -0
- data/lib/openid/extensions/ax.rb +539 -0
- data/lib/openid/extensions/oauth.rb +91 -0
- data/lib/openid/extensions/pape.rb +179 -0
- data/lib/openid/extensions/sreg.rb +277 -0
- data/lib/openid/extensions/ui.rb +53 -0
- data/lib/openid/extras.rb +11 -0
- data/lib/openid/fetchers.rb +258 -0
- data/lib/openid/kvform.rb +136 -0
- data/lib/openid/kvpost.rb +58 -0
- data/lib/openid/message.rb +553 -0
- data/lib/openid/protocolerror.rb +8 -0
- data/lib/openid/server.rb +1544 -0
- data/lib/openid/store/filesystem.rb +271 -0
- data/lib/openid/store/interface.rb +75 -0
- data/lib/openid/store/memcache.rb +107 -0
- data/lib/openid/store/memory.rb +84 -0
- data/lib/openid/store/nonce.rb +68 -0
- data/lib/openid/trustroot.rb +349 -0
- data/lib/openid/urinorm.rb +75 -0
- data/lib/openid/util.rb +110 -0
- data/lib/openid/yadis/accept.rb +148 -0
- data/lib/openid/yadis/constants.rb +21 -0
- data/lib/openid/yadis/discovery.rb +153 -0
- data/lib/openid/yadis/filters.rb +205 -0
- data/lib/openid/yadis/htmltokenizer.rb +305 -0
- data/lib/openid/yadis/parsehtml.rb +45 -0
- data/lib/openid/yadis/services.rb +42 -0
- data/lib/openid/yadis/xrds.rb +155 -0
- data/lib/openid/yadis/xri.rb +90 -0
- data/lib/openid/yadis/xrires.rb +99 -0
- data/setup.rb +1551 -0
- data/test/data/accept.txt +124 -0
- data/test/data/dh.txt +29 -0
- data/test/data/example-xrds.xml +14 -0
- data/test/data/linkparse.txt +587 -0
- data/test/data/n2b64 +650 -0
- data/test/data/test1-discover.txt +137 -0
- data/test/data/test1-parsehtml.txt +152 -0
- data/test/data/test_discover/malformed_meta_tag.html +19 -0
- data/test/data/test_discover/openid.html +11 -0
- data/test/data/test_discover/openid2.html +11 -0
- data/test/data/test_discover/openid2_xrds.xml +12 -0
- data/test/data/test_discover/openid2_xrds_no_local_id.xml +11 -0
- data/test/data/test_discover/openid_1_and_2.html +11 -0
- data/test/data/test_discover/openid_1_and_2_xrds.xml +16 -0
- data/test/data/test_discover/openid_1_and_2_xrds_bad_delegate.xml +17 -0
- data/test/data/test_discover/openid_and_yadis.html +12 -0
- data/test/data/test_discover/openid_no_delegate.html +10 -0
- data/test/data/test_discover/openid_utf8.html +11 -0
- data/test/data/test_discover/yadis_0entries.xml +12 -0
- data/test/data/test_discover/yadis_2_bad_local_id.xml +15 -0
- data/test/data/test_discover/yadis_2entries_delegate.xml +22 -0
- data/test/data/test_discover/yadis_2entries_idp.xml +21 -0
- data/test/data/test_discover/yadis_another_delegate.xml +14 -0
- data/test/data/test_discover/yadis_idp.xml +12 -0
- data/test/data/test_discover/yadis_idp_delegate.xml +13 -0
- data/test/data/test_discover/yadis_no_delegate.xml +11 -0
- data/test/data/test_xrds/=j3h.2007.11.14.xrds +25 -0
- data/test/data/test_xrds/README +12 -0
- data/test/data/test_xrds/delegated-20060809-r1.xrds +34 -0
- data/test/data/test_xrds/delegated-20060809-r2.xrds +34 -0
- data/test/data/test_xrds/delegated-20060809.xrds +34 -0
- data/test/data/test_xrds/no-xrd.xml +7 -0
- data/test/data/test_xrds/not-xrds.xml +2 -0
- data/test/data/test_xrds/prefixsometimes.xrds +34 -0
- data/test/data/test_xrds/ref.xrds +109 -0
- data/test/data/test_xrds/sometimesprefix.xrds +34 -0
- data/test/data/test_xrds/spoof1.xrds +25 -0
- data/test/data/test_xrds/spoof2.xrds +25 -0
- data/test/data/test_xrds/spoof3.xrds +37 -0
- data/test/data/test_xrds/status222.xrds +9 -0
- data/test/data/test_xrds/subsegments.xrds +58 -0
- data/test/data/test_xrds/valid-populated-xrds.xml +39 -0
- data/test/data/trustroot.txt +153 -0
- data/test/data/urinorm.txt +79 -0
- data/test/discoverdata.rb +131 -0
- data/test/test_accept.rb +170 -0
- data/test/test_association.rb +266 -0
- data/test/test_associationmanager.rb +917 -0
- data/test/test_ax.rb +690 -0
- data/test/test_checkid_request.rb +294 -0
- data/test/test_consumer.rb +257 -0
- data/test/test_cryptutil.rb +119 -0
- data/test/test_dh.rb +86 -0
- data/test/test_discover.rb +852 -0
- data/test/test_discovery_manager.rb +262 -0
- data/test/test_extension.rb +46 -0
- data/test/test_extras.rb +35 -0
- data/test/test_fetchers.rb +565 -0
- data/test/test_filters.rb +270 -0
- data/test/test_idres.rb +963 -0
- data/test/test_kvform.rb +165 -0
- data/test/test_kvpost.rb +65 -0
- data/test/test_linkparse.rb +101 -0
- data/test/test_message.rb +1116 -0
- data/test/test_nonce.rb +89 -0
- data/test/test_oauth.rb +175 -0
- data/test/test_openid_yadis.rb +178 -0
- data/test/test_pape.rb +247 -0
- data/test/test_parsehtml.rb +80 -0
- data/test/test_responses.rb +63 -0
- data/test/test_server.rb +2457 -0
- data/test/test_sreg.rb +479 -0
- data/test/test_stores.rb +298 -0
- data/test/test_trustroot.rb +113 -0
- data/test/test_ui.rb +93 -0
- data/test/test_urinorm.rb +35 -0
- data/test/test_util.rb +145 -0
- data/test/test_xrds.rb +169 -0
- data/test/test_xri.rb +48 -0
- data/test/test_xrires.rb +63 -0
- data/test/test_yadis_discovery.rb +220 -0
- data/test/testutil.rb +127 -0
- data/test/util.rb +53 -0
- metadata +336 -0
data/test/test_sreg.rb
ADDED
@@ -0,0 +1,479 @@
|
|
1
|
+
require 'openid/extensions/sreg'
|
2
|
+
require 'openid/message'
|
3
|
+
require 'openid/server'
|
4
|
+
require 'test/unit'
|
5
|
+
|
6
|
+
module OpenID
|
7
|
+
module SReg
|
8
|
+
module SRegTest
|
9
|
+
SOME_DATA = {
|
10
|
+
'nickname'=>'linusaur',
|
11
|
+
'postcode'=>'12345',
|
12
|
+
'country'=>'US',
|
13
|
+
'gender'=>'M',
|
14
|
+
'fullname'=>'Leonhard Euler',
|
15
|
+
'email'=>'president@whitehouse.gov',
|
16
|
+
'dob'=>'0000-00-00',
|
17
|
+
'language'=>'en-us',
|
18
|
+
}
|
19
|
+
|
20
|
+
class SRegTest < Test::Unit::TestCase
|
21
|
+
|
22
|
+
def test_is11
|
23
|
+
assert_equal(NS_URI, NS_URI_1_1)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_check_field_name
|
27
|
+
DATA_FIELDS.keys.each{|field_name|
|
28
|
+
OpenID::check_sreg_field_name(field_name)
|
29
|
+
}
|
30
|
+
assert_raises(ArgumentError) { OpenID::check_sreg_field_name('invalid') }
|
31
|
+
assert_raises(ArgumentError) { OpenID::check_sreg_field_name(nil) }
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_unsupported
|
35
|
+
endpoint = FakeEndpoint.new([])
|
36
|
+
assert(!OpenID::supports_sreg?(endpoint))
|
37
|
+
assert_equal([NS_URI_1_1,NS_URI_1_0], endpoint.checked_uris)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_supported_1_1
|
41
|
+
endpoint = FakeEndpoint.new([NS_URI_1_1])
|
42
|
+
assert(OpenID::supports_sreg?(endpoint))
|
43
|
+
assert_equal([NS_URI_1_1], endpoint.checked_uris)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_supported_1_0
|
47
|
+
endpoint = FakeEndpoint.new([NS_URI_1_0])
|
48
|
+
assert(OpenID::supports_sreg?(endpoint))
|
49
|
+
assert_equal([NS_URI_1_1,NS_URI_1_0], endpoint.checked_uris)
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
class FakeEndpoint < Object
|
55
|
+
attr_accessor :checked_uris
|
56
|
+
def initialize(supported)
|
57
|
+
@supported = supported
|
58
|
+
@checked_uris = []
|
59
|
+
end
|
60
|
+
|
61
|
+
def uses_extension(namespace_uri)
|
62
|
+
@checked_uris << namespace_uri
|
63
|
+
return @supported.member?(namespace_uri)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class FakeMessage < Object
|
68
|
+
attr_accessor :namespaces
|
69
|
+
attr_accessor :openid1
|
70
|
+
def initialize
|
71
|
+
@openid1 = false
|
72
|
+
@namespaces = NamespaceMap.new
|
73
|
+
end
|
74
|
+
|
75
|
+
def is_openid1
|
76
|
+
return @openid1
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
class GetNSTest < Test::Unit::TestCase
|
82
|
+
def setup
|
83
|
+
@msg = FakeMessage.new
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_openid2_empty
|
87
|
+
ns_uri = OpenID::get_sreg_ns(@msg)
|
88
|
+
assert_equal('sreg', @msg.namespaces.get_alias(ns_uri))
|
89
|
+
assert_equal(NS_URI, ns_uri)
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_openid1_empty
|
93
|
+
@msg.openid1 = true
|
94
|
+
ns_uri = OpenID::get_sreg_ns(@msg)
|
95
|
+
assert_equal('sreg', @msg.namespaces.get_alias(ns_uri))
|
96
|
+
assert_equal(NS_URI, ns_uri)
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_openid1defined_1_0
|
100
|
+
@msg.openid1 = true
|
101
|
+
@msg.namespaces.add(NS_URI_1_0)
|
102
|
+
ns_uri = OpenID::get_sreg_ns(@msg)
|
103
|
+
assert_equal(NS_URI_1_0, ns_uri)
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_openid1_defined_1_0_override_alias
|
107
|
+
[true, false].each{|openid_version|
|
108
|
+
[NS_URI_1_0, NS_URI_1_1].each{|sreg_version|
|
109
|
+
['sreg', 'bogus'].each{|name|
|
110
|
+
setup
|
111
|
+
@msg.openid1 = openid_version
|
112
|
+
@msg.namespaces.add_alias(sreg_version, name)
|
113
|
+
ns_uri = OpenID::get_sreg_ns(@msg)
|
114
|
+
assert_equal(name, @msg.namespaces.get_alias(ns_uri))
|
115
|
+
assert_equal(sreg_version, ns_uri)
|
116
|
+
}
|
117
|
+
}
|
118
|
+
}
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_openid1_defined_badly
|
122
|
+
@msg.openid1 = true
|
123
|
+
@msg.namespaces.add_alias('http://invalid/', 'sreg')
|
124
|
+
assert_raises(NamespaceError) { OpenID::get_sreg_ns(@msg) }
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_openid2_defined_badly
|
128
|
+
@msg.namespaces.add_alias('http://invalid/', 'sreg')
|
129
|
+
assert_raises(NamespaceError) { OpenID::get_sreg_ns(@msg) }
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_openid2_defined_1_0
|
133
|
+
@msg.namespaces.add(NS_URI_1_0)
|
134
|
+
ns_uri = OpenID::get_sreg_ns(@msg)
|
135
|
+
assert_equal(NS_URI_1_0, ns_uri)
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_openid1_sreg_ns_from_args
|
139
|
+
args = {
|
140
|
+
'sreg.optional'=> 'nickname',
|
141
|
+
'sreg.required'=> 'dob',
|
142
|
+
}
|
143
|
+
|
144
|
+
m = Message.from_openid_args(args)
|
145
|
+
|
146
|
+
assert_equal('nickname', m.get_arg(NS_URI_1_1, 'optional'))
|
147
|
+
assert_equal('dob', m.get_arg(NS_URI_1_1, 'required'))
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
151
|
+
|
152
|
+
class SRegRequestTest < Test::Unit::TestCase
|
153
|
+
def test_construct_empty
|
154
|
+
req = Request.new
|
155
|
+
assert_equal([], req.optional)
|
156
|
+
assert_equal([], req.required)
|
157
|
+
assert_equal(nil, req.policy_url)
|
158
|
+
assert_equal(NS_URI, req.ns_uri)
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_construct_fields
|
162
|
+
req = Request.new(['nickname'],['gender'],'http://policy', 'http://sreg.ns_uri')
|
163
|
+
assert_equal(['gender'], req.optional)
|
164
|
+
assert_equal(['nickname'], req.required)
|
165
|
+
assert_equal('http://policy', req.policy_url)
|
166
|
+
assert_equal('http://sreg.ns_uri', req.ns_uri)
|
167
|
+
end
|
168
|
+
|
169
|
+
def test_construct_bad_fields
|
170
|
+
assert_raises(ArgumentError) {Request.new(['elvis'])}
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_from_openid_request_message_copied
|
174
|
+
message = Message.from_openid_args({"sreg.required" => "nickname"})
|
175
|
+
openid_req = Server::OpenIDRequest.new
|
176
|
+
openid_req.message = message
|
177
|
+
sreg_req = Request.from_openid_request(openid_req)
|
178
|
+
# check that the message is copied by looking at sreg namespace
|
179
|
+
assert_equal(NS_URI_1_1, message.namespaces.get_namespace_uri('sreg'))
|
180
|
+
assert_equal(NS_URI, sreg_req.ns_uri)
|
181
|
+
assert_equal(['nickname'], sreg_req.required)
|
182
|
+
end
|
183
|
+
|
184
|
+
def test_from_openid_request_ns_1_0
|
185
|
+
message = Message.from_openid_args({'ns.sreg' => NS_URI_1_0,
|
186
|
+
"sreg.required" => "nickname"})
|
187
|
+
openid_req = Server::OpenIDRequest.new
|
188
|
+
openid_req.message = message
|
189
|
+
sreg_req = Request.from_openid_request(openid_req)
|
190
|
+
assert_equal(NS_URI_1_0, sreg_req.ns_uri)
|
191
|
+
assert_equal(['nickname'], sreg_req.required)
|
192
|
+
end
|
193
|
+
|
194
|
+
def test_from_openid_request_no_sreg
|
195
|
+
message = Message.new
|
196
|
+
openid_req = Server::OpenIDRequest.new
|
197
|
+
openid_req.message = message
|
198
|
+
sreg_req = Request.from_openid_request(openid_req)
|
199
|
+
assert(sreg_req.nil?)
|
200
|
+
end
|
201
|
+
|
202
|
+
def test_parse_extension_args_empty
|
203
|
+
req = Request.new
|
204
|
+
req.parse_extension_args({})
|
205
|
+
end
|
206
|
+
|
207
|
+
def test_parse_extension_args_extra_ignored
|
208
|
+
req = Request.new
|
209
|
+
req.parse_extension_args({'extra' => 'stuff'})
|
210
|
+
end
|
211
|
+
|
212
|
+
def test_parse_extension_args_non_strict
|
213
|
+
req = Request.new
|
214
|
+
req.parse_extension_args({'required' => 'stuff'})
|
215
|
+
assert_equal([], req.required)
|
216
|
+
end
|
217
|
+
|
218
|
+
def test_parse_extension_args_strict
|
219
|
+
req = Request.new
|
220
|
+
assert_raises(ArgumentError) {
|
221
|
+
req.parse_extension_args({'required' => 'stuff'}, true)
|
222
|
+
}
|
223
|
+
end
|
224
|
+
|
225
|
+
def test_parse_extension_args_policy
|
226
|
+
req = Request.new
|
227
|
+
req.parse_extension_args({'policy_url' => 'http://policy'}, true)
|
228
|
+
assert_equal('http://policy', req.policy_url)
|
229
|
+
end
|
230
|
+
|
231
|
+
def test_parse_extension_args_required_empty
|
232
|
+
req = Request.new
|
233
|
+
req.parse_extension_args({'required' => ''}, true)
|
234
|
+
assert_equal([], req.required)
|
235
|
+
end
|
236
|
+
|
237
|
+
def test_parse_extension_args_optional_empty
|
238
|
+
req = Request.new
|
239
|
+
req.parse_extension_args({'optional' => ''},true)
|
240
|
+
assert_equal([], req.optional)
|
241
|
+
end
|
242
|
+
|
243
|
+
def test_parse_extension_args_optional_single
|
244
|
+
req = Request.new
|
245
|
+
req.parse_extension_args({'optional' => 'nickname'},true)
|
246
|
+
assert_equal(['nickname'], req.optional)
|
247
|
+
end
|
248
|
+
|
249
|
+
def test_parse_extension_args_optional_list
|
250
|
+
req = Request.new
|
251
|
+
req.parse_extension_args({'optional' => 'nickname,email'},true)
|
252
|
+
assert_equal(['nickname','email'], req.optional)
|
253
|
+
end
|
254
|
+
|
255
|
+
def test_parse_extension_args_optional_list_bad_nonstrict
|
256
|
+
req = Request.new
|
257
|
+
req.parse_extension_args({'optional' => 'nickname,email,beer'})
|
258
|
+
assert_equal(['nickname','email'], req.optional)
|
259
|
+
end
|
260
|
+
|
261
|
+
def test_parse_extension_args_optional_list_bad_strict
|
262
|
+
req = Request.new
|
263
|
+
assert_raises(ArgumentError) {
|
264
|
+
req.parse_extension_args({'optional' => 'nickname,email,beer'}, true)
|
265
|
+
}
|
266
|
+
end
|
267
|
+
|
268
|
+
def test_parse_extension_args_both_nonstrict
|
269
|
+
req = Request.new
|
270
|
+
req.parse_extension_args({'optional' => 'nickname', 'required' => 'nickname'})
|
271
|
+
assert_equal(['nickname'], req.required)
|
272
|
+
assert_equal([], req.optional)
|
273
|
+
end
|
274
|
+
|
275
|
+
def test_parse_extension_args_both_strict
|
276
|
+
req = Request.new
|
277
|
+
assert_raises(ArgumentError) {
|
278
|
+
req.parse_extension_args({'optional' => 'nickname', 'required' => 'nickname'},true)
|
279
|
+
}
|
280
|
+
end
|
281
|
+
|
282
|
+
def test_parse_extension_args_both_list
|
283
|
+
req = Request.new
|
284
|
+
req.parse_extension_args({'optional' => 'nickname,email', 'required' => 'country,postcode'},true)
|
285
|
+
assert_equal(['nickname','email'], req.optional)
|
286
|
+
assert_equal(['country','postcode'], req.required)
|
287
|
+
end
|
288
|
+
|
289
|
+
def test_all_requested_fields
|
290
|
+
req = Request.new
|
291
|
+
assert_equal([], req.all_requested_fields)
|
292
|
+
req.request_field('nickname')
|
293
|
+
assert_equal(['nickname'], req.all_requested_fields)
|
294
|
+
req.request_field('gender', true)
|
295
|
+
requested = req.all_requested_fields.sort
|
296
|
+
assert_equal(['gender', 'nickname'], requested)
|
297
|
+
end
|
298
|
+
|
299
|
+
def test_were_fields_requested
|
300
|
+
req = Request.new
|
301
|
+
assert(!req.were_fields_requested?)
|
302
|
+
req.request_field('nickname')
|
303
|
+
assert(req.were_fields_requested?)
|
304
|
+
end
|
305
|
+
|
306
|
+
def test_member
|
307
|
+
req = Request.new
|
308
|
+
DATA_FIELDS.keys.each {|f|
|
309
|
+
assert(!req.member?(f))
|
310
|
+
}
|
311
|
+
assert(!req.member?('something else'))
|
312
|
+
req.request_field('nickname')
|
313
|
+
DATA_FIELDS.keys.each {|f|
|
314
|
+
assert_equal(f == 'nickname',req.member?(f))
|
315
|
+
}
|
316
|
+
end
|
317
|
+
|
318
|
+
def test_request_field_bogus
|
319
|
+
req = Request.new
|
320
|
+
fields = DATA_FIELDS.keys
|
321
|
+
fields.each {|f| req.request_field(f) }
|
322
|
+
assert_equal(fields, req.optional)
|
323
|
+
assert_equal([], req.required)
|
324
|
+
|
325
|
+
# By default, adding the same fields over again has no effect
|
326
|
+
fields.each {|f| req.request_field(f) }
|
327
|
+
assert_equal(fields, req.optional)
|
328
|
+
assert_equal([], req.required)
|
329
|
+
|
330
|
+
# Requesting a field as required overrides requesting it as optional
|
331
|
+
expected = fields[1..-1]
|
332
|
+
overridden = fields[0]
|
333
|
+
req.request_field(overridden, true)
|
334
|
+
assert_equal(expected, req.optional)
|
335
|
+
assert_equal([overridden], req.required)
|
336
|
+
|
337
|
+
fields.each {|f| req.request_field(f, true) }
|
338
|
+
assert_equal(fields, req.required)
|
339
|
+
assert_equal([], req.optional)
|
340
|
+
end
|
341
|
+
|
342
|
+
def test_request_fields_type
|
343
|
+
req = Request.new
|
344
|
+
assert_raises(ArgumentError) { req.request_fields('nickname') }
|
345
|
+
end
|
346
|
+
|
347
|
+
def test_request_fields
|
348
|
+
req = Request.new
|
349
|
+
fields = DATA_FIELDS.keys
|
350
|
+
|
351
|
+
req.request_fields(fields)
|
352
|
+
assert_equal(fields, req.optional)
|
353
|
+
assert_equal([], req.required)
|
354
|
+
|
355
|
+
# By default, adding the same fields over again has no effect
|
356
|
+
req.request_fields(fields)
|
357
|
+
assert_equal(fields, req.optional)
|
358
|
+
assert_equal([], req.required)
|
359
|
+
|
360
|
+
# required overrides optional
|
361
|
+
expected = fields[1..-1]
|
362
|
+
overridden = fields[0]
|
363
|
+
req.request_fields([overridden], true)
|
364
|
+
assert_equal(expected, req.optional)
|
365
|
+
assert_equal([overridden], req.required)
|
366
|
+
|
367
|
+
req.request_fields(fields, true)
|
368
|
+
assert_equal(fields, req.required)
|
369
|
+
assert_equal([], req.optional)
|
370
|
+
|
371
|
+
# optional does not override required
|
372
|
+
req.request_fields(fields)
|
373
|
+
assert_equal(fields, req.required)
|
374
|
+
assert_equal([], req.optional)
|
375
|
+
end
|
376
|
+
|
377
|
+
def test_get_extension_args
|
378
|
+
req = Request.new
|
379
|
+
assert_equal({}, req.get_extension_args)
|
380
|
+
|
381
|
+
req.request_field('nickname')
|
382
|
+
assert_equal({'optional' => 'nickname'}, req.get_extension_args)
|
383
|
+
|
384
|
+
req.request_field('email')
|
385
|
+
assert_equal({'optional' => 'nickname,email'}, req.get_extension_args)
|
386
|
+
|
387
|
+
req.request_field('gender', true)
|
388
|
+
assert_equal({'optional' => 'nickname,email',
|
389
|
+
'required' => 'gender'}, req.get_extension_args)
|
390
|
+
|
391
|
+
req.request_field('dob', true)
|
392
|
+
assert_equal({'optional' => 'nickname,email',
|
393
|
+
'required' => 'gender,dob'}, req.get_extension_args)
|
394
|
+
|
395
|
+
req.policy_url = 'http://policy'
|
396
|
+
assert_equal({'optional' => 'nickname,email',
|
397
|
+
'required' => 'gender,dob',
|
398
|
+
'policy_url' => 'http://policy'},
|
399
|
+
req.get_extension_args)
|
400
|
+
|
401
|
+
end
|
402
|
+
end
|
403
|
+
|
404
|
+
class DummySuccessResponse
|
405
|
+
attr_accessor :message
|
406
|
+
def initialize(message, signed_stuff)
|
407
|
+
@message = message
|
408
|
+
@signed_stuff = signed_stuff
|
409
|
+
end
|
410
|
+
def get_signed_ns(ns_uri)
|
411
|
+
return @signed_stuff
|
412
|
+
end
|
413
|
+
end
|
414
|
+
|
415
|
+
|
416
|
+
class SRegResponseTest < Test::Unit::TestCase
|
417
|
+
def test_construct
|
418
|
+
resp = Response.new(SOME_DATA)
|
419
|
+
assert_equal(SOME_DATA, resp.get_extension_args)
|
420
|
+
assert_equal(NS_URI, resp.ns_uri)
|
421
|
+
resp2 = Response.new({}, "http://foo")
|
422
|
+
assert_equal({}, resp2.get_extension_args)
|
423
|
+
assert_equal('http://foo', resp2.ns_uri)
|
424
|
+
end
|
425
|
+
|
426
|
+
def test_from_success_response_signed
|
427
|
+
message = Message.from_openid_args({
|
428
|
+
'sreg.nickname'=>'The Mad Stork',
|
429
|
+
})
|
430
|
+
success_resp = DummySuccessResponse.new(message, {})
|
431
|
+
sreg_resp = Response.from_success_response(success_resp)
|
432
|
+
assert_equal({}, sreg_resp.get_extension_args)
|
433
|
+
end
|
434
|
+
|
435
|
+
def test_from_success_response_unsigned
|
436
|
+
message = Message.from_openid_args({
|
437
|
+
'ns.sreg' => NS_URI,
|
438
|
+
'sreg.nickname' => 'The Mad Stork',
|
439
|
+
})
|
440
|
+
success_resp = DummySuccessResponse.new(message, {})
|
441
|
+
sreg_resp = Response.from_success_response(success_resp, false)
|
442
|
+
assert_equal({'nickname' => 'The Mad Stork'},
|
443
|
+
sreg_resp.get_extension_args)
|
444
|
+
end
|
445
|
+
end
|
446
|
+
|
447
|
+
class SendFieldsTest < Test::Unit::TestCase
|
448
|
+
# class SendFieldsTest < Object
|
449
|
+
def test_send_fields
|
450
|
+
# create a request message with simple reg fields
|
451
|
+
sreg_req = Request.new(['nickname', 'email'], ['fullname'])
|
452
|
+
req_msg = Message.new
|
453
|
+
req_msg.update_args(NS_URI, sreg_req.get_extension_args)
|
454
|
+
req = Server::OpenIDRequest.new
|
455
|
+
req.message = req_msg
|
456
|
+
|
457
|
+
# -> checkid_* request
|
458
|
+
|
459
|
+
# create a response
|
460
|
+
resp_msg = Message.new
|
461
|
+
resp = Server::OpenIDResponse.new(req)
|
462
|
+
resp.fields = resp_msg
|
463
|
+
sreg_resp = Response.extract_response(sreg_req, SOME_DATA)
|
464
|
+
resp.add_extension(sreg_resp)
|
465
|
+
|
466
|
+
# <- id_res response
|
467
|
+
|
468
|
+
# extract sent fields
|
469
|
+
sreg_data_resp = resp_msg.get_args(NS_URI)
|
470
|
+
assert_equal({'nickname' => 'linusaur',
|
471
|
+
'email'=>'president@whitehouse.gov',
|
472
|
+
'fullname'=>'Leonhard Euler',
|
473
|
+
}, sreg_data_resp)
|
474
|
+
end
|
475
|
+
end
|
476
|
+
end
|
477
|
+
end
|
478
|
+
end
|
479
|
+
|