pelle-ruby-openid 2.1.8
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 +82 -0
- data/UPGRADE +127 -0
- data/VERSION +1 -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/association.rb +249 -0
- data/lib/openid/consumer/associationmanager.rb +344 -0
- data/lib/openid/consumer/checkid_request.rb +186 -0
- data/lib/openid/consumer/discovery.rb +498 -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/consumer.rb +395 -0
- data/lib/openid/cryptutil.rb +97 -0
- data/lib/openid/dh.rb +89 -0
- data/lib/openid/extension.rb +39 -0
- data/lib/openid/extensions/ax.rb +516 -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/extras.rb +11 -0
- data/lib/openid/fetchers.rb +238 -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 +106 -0
- data/lib/openid.rb +20 -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/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 +648 -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 +838 -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 +538 -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_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 +316 -0
@@ -0,0 +1,270 @@
|
|
1
|
+
|
2
|
+
require 'test/unit'
|
3
|
+
require 'openid/yadis/filters'
|
4
|
+
|
5
|
+
module OpenID
|
6
|
+
class BasicServiceEndpointTest < Test::Unit::TestCase
|
7
|
+
def test_match_types
|
8
|
+
# Make sure the match_types operation returns the expected
|
9
|
+
# results with various inputs.
|
10
|
+
types = ["urn:bogus", "urn:testing"]
|
11
|
+
yadis_url = "http://yadis/"
|
12
|
+
|
13
|
+
no_types_endpoint = Yadis::BasicServiceEndpoint.new(yadis_url, [], nil, nil)
|
14
|
+
|
15
|
+
some_types_endpoint = Yadis::BasicServiceEndpoint.new(yadis_url, types,
|
16
|
+
nil, nil)
|
17
|
+
|
18
|
+
assert(no_types_endpoint.match_types([]) == [])
|
19
|
+
assert(no_types_endpoint.match_types(["urn:absent"]) == [])
|
20
|
+
|
21
|
+
assert(some_types_endpoint.match_types([]) == [])
|
22
|
+
assert(some_types_endpoint.match_types(["urn:absent"]) == [])
|
23
|
+
assert(some_types_endpoint.match_types(types) == types)
|
24
|
+
assert(some_types_endpoint.match_types([types[1], types[0]]) == types)
|
25
|
+
assert(some_types_endpoint.match_types([types[0]]) == [types[0]])
|
26
|
+
assert(some_types_endpoint.match_types(types + ["urn:absent"]) == types)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_from_basic_service_endpoint
|
30
|
+
# Check BasicServiceEndpoint.from_basic_service_endpoint
|
31
|
+
endpoint = "unused"
|
32
|
+
e = Yadis::BasicServiceEndpoint.new(nil, [], nil, nil)
|
33
|
+
|
34
|
+
assert(Yadis::BasicServiceEndpoint.from_basic_service_endpoint(endpoint) ==
|
35
|
+
endpoint)
|
36
|
+
assert(e.from_basic_service_endpoint(endpoint) ==
|
37
|
+
endpoint)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class TransformFilterMakerTest < Test::Unit::TestCase
|
42
|
+
def make_service_element(types, uris)
|
43
|
+
service = REXML::Element.new('Service')
|
44
|
+
types.each { |type_text|
|
45
|
+
service.add_element('Type').text = type_text
|
46
|
+
}
|
47
|
+
uris.each { |uri_text|
|
48
|
+
service.add_element('URI').text = uri_text
|
49
|
+
}
|
50
|
+
return service
|
51
|
+
end
|
52
|
+
def test_get_service_endpoints
|
53
|
+
yadis_url = "http://yad.is/"
|
54
|
+
uri = "http://uri/"
|
55
|
+
type_uris = ["urn:type1", "urn:type2"]
|
56
|
+
element = make_service_element(type_uris, [uri])
|
57
|
+
|
58
|
+
data = [
|
59
|
+
[type_uris, uri, element],
|
60
|
+
]
|
61
|
+
|
62
|
+
filters = [Proc.new { |endpoint|
|
63
|
+
if endpoint.service_element == element
|
64
|
+
endpoint
|
65
|
+
else
|
66
|
+
nil
|
67
|
+
end
|
68
|
+
}
|
69
|
+
]
|
70
|
+
|
71
|
+
tf = Yadis::TransformFilterMaker.new(filters)
|
72
|
+
result = tf.get_service_endpoints(yadis_url, element)
|
73
|
+
|
74
|
+
assert_equal(result[0].yadis_url, yadis_url, result)
|
75
|
+
assert_equal(result[0].uri, uri, result)
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_empty_transform_filter
|
79
|
+
# A transform filter with no filter procs should return nil.
|
80
|
+
endpoint = "unused"
|
81
|
+
t = Yadis::TransformFilterMaker.new([])
|
82
|
+
assert(t.apply_filters(endpoint).nil?)
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_nil_filter
|
86
|
+
# A transform filter with a single nil filter should return nil.
|
87
|
+
nil_filter = Proc.new { |endpoint| nil }
|
88
|
+
t = Yadis::TransformFilterMaker.new([nil_filter])
|
89
|
+
endpoint = "unused"
|
90
|
+
assert(t.apply_filters(endpoint).nil?)
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_identity_filter
|
94
|
+
# A transform filter with an identity filter should return the
|
95
|
+
# input.
|
96
|
+
identity_filter = Proc.new { |endpoint| endpoint }
|
97
|
+
t = Yadis::TransformFilterMaker.new([identity_filter])
|
98
|
+
endpoint = "unused"
|
99
|
+
assert(t.apply_filters(endpoint) == endpoint)
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_return_different_endpoint
|
103
|
+
# Make sure the result of the filter is returned, rather than
|
104
|
+
# the input.
|
105
|
+
returned_endpoint = "returned endpoint"
|
106
|
+
filter = Proc.new { |endpoint| returned_endpoint }
|
107
|
+
t = Yadis::TransformFilterMaker.new([filter])
|
108
|
+
endpoint = "unused"
|
109
|
+
assert(t.apply_filters(endpoint) == returned_endpoint)
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_multiple_filters
|
113
|
+
# Check filter fallback behavior on different inputs.
|
114
|
+
odd, odd_result = 45, "odd"
|
115
|
+
even, even_result = 46, "even"
|
116
|
+
|
117
|
+
filter_odd = Proc.new { |endpoint|
|
118
|
+
if endpoint % 2 == 1
|
119
|
+
odd_result
|
120
|
+
else
|
121
|
+
nil
|
122
|
+
end
|
123
|
+
}
|
124
|
+
|
125
|
+
filter_even = Proc.new { |endpoint|
|
126
|
+
if endpoint % 2 == 0
|
127
|
+
even_result
|
128
|
+
else
|
129
|
+
nil
|
130
|
+
end
|
131
|
+
}
|
132
|
+
|
133
|
+
t = Yadis::TransformFilterMaker.new([filter_odd, filter_even])
|
134
|
+
assert(t.apply_filters(odd) == odd_result)
|
135
|
+
assert(t.apply_filters(even) == even_result)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
class BogusServiceEndpointExtractor
|
140
|
+
def initialize(data)
|
141
|
+
@data = data
|
142
|
+
end
|
143
|
+
|
144
|
+
def get_service_endpoints(yadis_url, service_element)
|
145
|
+
return @data
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
class CompoundFilterTest < Test::Unit::TestCase
|
150
|
+
def test_get_service_endpoints
|
151
|
+
first = ["bogus", "test"]
|
152
|
+
second = ["third"]
|
153
|
+
all = first + second
|
154
|
+
|
155
|
+
subfilters = [
|
156
|
+
BogusServiceEndpointExtractor.new(first),
|
157
|
+
BogusServiceEndpointExtractor.new(second),
|
158
|
+
]
|
159
|
+
|
160
|
+
cf = Yadis::CompoundFilter.new(subfilters)
|
161
|
+
assert(cf.get_service_endpoints("unused", "unused") == all)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
class MakeFilterTest < Test::Unit::TestCase
|
166
|
+
def test_parts_nil
|
167
|
+
result = Yadis.make_filter(nil)
|
168
|
+
assert(result.is_a?(Yadis::TransformFilterMaker),
|
169
|
+
result)
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_parts_array
|
173
|
+
e1 = Yadis::BasicServiceEndpoint.new(nil, [], nil, nil)
|
174
|
+
e2 = Yadis::BasicServiceEndpoint.new(nil, [], nil, nil)
|
175
|
+
|
176
|
+
result = Yadis.make_filter([e1, e2])
|
177
|
+
assert(result.is_a?(Yadis::TransformFilterMaker),
|
178
|
+
result)
|
179
|
+
assert(result.filter_procs[0] == e1.method('from_basic_service_endpoint'))
|
180
|
+
assert(result.filter_procs[1] == e2.method('from_basic_service_endpoint'))
|
181
|
+
end
|
182
|
+
|
183
|
+
def test_parts_single
|
184
|
+
e = Yadis::BasicServiceEndpoint.new(nil, [], nil, nil)
|
185
|
+
result = Yadis.make_filter(e)
|
186
|
+
assert(result.is_a?(Yadis::TransformFilterMaker),
|
187
|
+
result)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
class MakeCompoundFilterTest < Test::Unit::TestCase
|
192
|
+
def test_no_filters
|
193
|
+
result = Yadis.mk_compound_filter([])
|
194
|
+
assert(result.subfilters == [])
|
195
|
+
end
|
196
|
+
|
197
|
+
def test_single_transform_filter
|
198
|
+
f = Yadis::TransformFilterMaker.new([])
|
199
|
+
assert(Yadis.mk_compound_filter([f]) == f)
|
200
|
+
end
|
201
|
+
|
202
|
+
def test_single_endpoint
|
203
|
+
e = Yadis::BasicServiceEndpoint.new(nil, [], nil, nil)
|
204
|
+
result = Yadis.mk_compound_filter([e])
|
205
|
+
assert(result.is_a?(Yadis::TransformFilterMaker))
|
206
|
+
|
207
|
+
# Expect the transform filter to call
|
208
|
+
# from_basic_service_endpoint on the endpoint
|
209
|
+
filter = result.filter_procs[0]
|
210
|
+
assert(filter == e.method('from_basic_service_endpoint'),
|
211
|
+
filter)
|
212
|
+
end
|
213
|
+
|
214
|
+
def test_single_proc
|
215
|
+
# Create a proc that just returns nil for any endpoint
|
216
|
+
p = Proc.new { |endpoint| nil }
|
217
|
+
result = Yadis.mk_compound_filter([p])
|
218
|
+
assert(result.is_a?(Yadis::TransformFilterMaker))
|
219
|
+
|
220
|
+
# Expect the transform filter to call
|
221
|
+
# from_basic_service_endpoint on the endpoint
|
222
|
+
filter = result.filter_procs[0]
|
223
|
+
assert(filter == p)
|
224
|
+
end
|
225
|
+
|
226
|
+
def test_multiple_filters_same_type
|
227
|
+
f1 = Yadis::TransformFilterMaker.new([])
|
228
|
+
f2 = Yadis::TransformFilterMaker.new([])
|
229
|
+
|
230
|
+
# Expect mk_compound_filter to actually make a CompoundFilter
|
231
|
+
# from f1 and f2.
|
232
|
+
result = Yadis.mk_compound_filter([f1, f2])
|
233
|
+
|
234
|
+
assert(result.is_a?(Yadis::CompoundFilter))
|
235
|
+
assert(result.subfilters == [f1, f2])
|
236
|
+
end
|
237
|
+
|
238
|
+
def test_multiple_filters_different_type
|
239
|
+
f1 = Yadis::TransformFilterMaker.new([])
|
240
|
+
f2 = Yadis::BasicServiceEndpoint.new(nil, [], nil, nil)
|
241
|
+
f3 = Proc.new { |endpoint| nil }
|
242
|
+
|
243
|
+
e = Yadis::BasicServiceEndpoint.new(nil, [], nil, nil)
|
244
|
+
f4 = [e]
|
245
|
+
|
246
|
+
# Expect mk_compound_filter to actually make a CompoundFilter
|
247
|
+
# from f1 and f2.
|
248
|
+
result = Yadis.mk_compound_filter([f1, f2, f3, f4])
|
249
|
+
|
250
|
+
assert(result.is_a?(Yadis::CompoundFilter))
|
251
|
+
|
252
|
+
assert(result.subfilters[0] == f1)
|
253
|
+
assert(result.subfilters[1].filter_procs[0] ==
|
254
|
+
e.method('from_basic_service_endpoint'))
|
255
|
+
assert(result.subfilters[2].filter_procs[0] ==
|
256
|
+
f2.method('from_basic_service_endpoint'))
|
257
|
+
assert(result.subfilters[2].filter_procs[1] == f3)
|
258
|
+
end
|
259
|
+
|
260
|
+
def test_filter_type_error
|
261
|
+
# Pass various non-filter objects and make sure the filter
|
262
|
+
# machinery explodes.
|
263
|
+
[nil, ["bogus"], [1], [nil, "bogus"]].each { |thing|
|
264
|
+
assert_raise(TypeError) {
|
265
|
+
Yadis.mk_compound_filter(thing)
|
266
|
+
}
|
267
|
+
}
|
268
|
+
end
|
269
|
+
end
|
270
|
+
end
|