pelle-ruby-openid 2.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
data/test/test_xrds.rb
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
|
|
2
|
+
require 'test/unit'
|
|
3
|
+
require 'openid/yadis/xrds'
|
|
4
|
+
|
|
5
|
+
require 'testutil'
|
|
6
|
+
|
|
7
|
+
module OpenID
|
|
8
|
+
module Yadis
|
|
9
|
+
|
|
10
|
+
module XRDSTestMixin
|
|
11
|
+
include TestDataMixin
|
|
12
|
+
|
|
13
|
+
XRD_FILE = 'valid-populated-xrds.xml'
|
|
14
|
+
NOXRDS_FILE = 'not-xrds.xml'
|
|
15
|
+
NOXRD_FILE = 'no-xrd.xml'
|
|
16
|
+
|
|
17
|
+
XRDS_DATA_DIR = TEST_DATA_DIR.join('test_xrds')
|
|
18
|
+
|
|
19
|
+
def read_data_file(filename)
|
|
20
|
+
super(filename, false, XRDS_DATA_DIR)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
class ParseXRDSTestCase < Test::Unit::TestCase
|
|
25
|
+
include XRDSTestMixin
|
|
26
|
+
|
|
27
|
+
# Check that parsing succeeds at all.
|
|
28
|
+
def test_parse
|
|
29
|
+
result = Yadis.parseXRDS(read_data_file(XRD_FILE))
|
|
30
|
+
assert_not_nil result
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_parse_no_xrds_xml
|
|
34
|
+
xmldoc = read_data_file(NOXRDS_FILE)
|
|
35
|
+
assert_raise(Yadis::XRDSError) {
|
|
36
|
+
Yadis.parseXRDS(xmldoc)
|
|
37
|
+
}
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_parse_no_xrds_empty
|
|
41
|
+
assert_raise(Yadis::XRDSError) {
|
|
42
|
+
Yadis.parseXRDS('')
|
|
43
|
+
}
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def test_is_xrds
|
|
47
|
+
isnt = REXML::Document.new(read_data_file(NOXRDS_FILE))
|
|
48
|
+
should_be = Yadis.parseXRDS(read_data_file(XRD_FILE))
|
|
49
|
+
assert_equal false, Yadis::is_xrds?(isnt)
|
|
50
|
+
assert Yadis::is_xrds?(should_be)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
class GetYadisXRDTestCase < Test::Unit::TestCase
|
|
55
|
+
include XRDSTestMixin
|
|
56
|
+
|
|
57
|
+
# XXX: Test to make sure this really gets the _right_ XRD.
|
|
58
|
+
def test_get_xrd
|
|
59
|
+
doc = Yadis.parseXRDS(read_data_file(XRD_FILE))
|
|
60
|
+
result = Yadis::get_yadis_xrd(doc)
|
|
61
|
+
assert_not_nil result
|
|
62
|
+
assert_equal 'XRD', result.name
|
|
63
|
+
assert_equal Yadis::XRD_NS_2_0, result.namespace
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def test_no_xrd
|
|
67
|
+
xmldoc = read_data_file(NOXRD_FILE)
|
|
68
|
+
doc = Yadis.parseXRDS(xmldoc)
|
|
69
|
+
assert_raise(Yadis::XRDSError) {
|
|
70
|
+
Yadis.get_yadis_xrd(doc)
|
|
71
|
+
}
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
class EachServiceTestCase < Test::Unit::TestCase
|
|
76
|
+
include XRDSTestMixin
|
|
77
|
+
|
|
78
|
+
def test_get_xrd
|
|
79
|
+
doc = Yadis.parseXRDS(read_data_file(XRD_FILE))
|
|
80
|
+
count = 0
|
|
81
|
+
result = Yadis::each_service(doc) { |e|
|
|
82
|
+
assert_equal 'Service', e.name
|
|
83
|
+
count += 1
|
|
84
|
+
}
|
|
85
|
+
assert_not_nil result
|
|
86
|
+
assert_equal 5, count
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def test_no_xrd
|
|
90
|
+
xmldoc = read_data_file(NOXRD_FILE)
|
|
91
|
+
doc = Yadis.parseXRDS(xmldoc)
|
|
92
|
+
assert_raise(Yadis::XRDSError) {
|
|
93
|
+
Yadis.each_service(doc)
|
|
94
|
+
}
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def test_equal_j3h
|
|
98
|
+
doc = Yadis.parseXRDS(read_data_file('=j3h.2007.11.14.xrds'))
|
|
99
|
+
count = 0
|
|
100
|
+
result = Yadis::each_service(doc) { |e|
|
|
101
|
+
assert_equal 'Service', e.name
|
|
102
|
+
count += 1
|
|
103
|
+
}
|
|
104
|
+
assert_not_nil result
|
|
105
|
+
assert_equal 2, count
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# XXX: test prioSort!
|
|
110
|
+
|
|
111
|
+
class ExpandServiceTestCase < Test::Unit::TestCase
|
|
112
|
+
@@service_xml = <<END
|
|
113
|
+
<Service>
|
|
114
|
+
<Type>urn://foo</Type>
|
|
115
|
+
<Type>urn://bar</Type>
|
|
116
|
+
<URI priority='2'>http://2.invalid/</URI>
|
|
117
|
+
<URI>http://0.invalid/</URI>
|
|
118
|
+
<URI priority='1'>http://1.invalid/</URI>
|
|
119
|
+
</Service>
|
|
120
|
+
END
|
|
121
|
+
|
|
122
|
+
# XXX - not sorted!
|
|
123
|
+
def test_expand_service
|
|
124
|
+
service_element = REXML::Document.new(@@service_xml).root
|
|
125
|
+
result = Yadis::expand_service(service_element)
|
|
126
|
+
assert_equal 3, result.length
|
|
127
|
+
types, uri, result_element = result[0]
|
|
128
|
+
assert_same service_element, result_element
|
|
129
|
+
assert_equal 'http://0.invalid/', uri
|
|
130
|
+
assert_equal ['urn://foo', 'urn://bar'], types
|
|
131
|
+
types, uri, result_element = result[1]
|
|
132
|
+
assert_equal 'http://1.invalid/', uri
|
|
133
|
+
types, uri, result_element = result[2]
|
|
134
|
+
assert_equal 'http://2.invalid/', uri
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
class PrioSortTestCase < Test::Unit::TestCase
|
|
139
|
+
def new_uri(priority)
|
|
140
|
+
e = REXML::Element.new("URI")
|
|
141
|
+
e.add_attribute("priority", priority.to_s) unless e.nil?
|
|
142
|
+
return e
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def test_sorting
|
|
146
|
+
l = [
|
|
147
|
+
e7 = new_uri(7),
|
|
148
|
+
e1 = new_uri(1),
|
|
149
|
+
e0 = new_uri(nil),
|
|
150
|
+
e2 = new_uri(2),
|
|
151
|
+
]
|
|
152
|
+
sorted = Yadis::prio_sort(l)
|
|
153
|
+
assert_same e0, sorted[0]
|
|
154
|
+
assert_same e1, sorted[1]
|
|
155
|
+
assert_same e2, sorted[2]
|
|
156
|
+
assert_same e7, sorted[3]
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
class GetCanonicalIDTestCase < Test::Unit::TestCase
|
|
161
|
+
include XRDSTestMixin
|
|
162
|
+
|
|
163
|
+
def test_multisegment_xri
|
|
164
|
+
xmldoc = Yadis.parseXRDS(read_data_file('subsegments.xrds'))
|
|
165
|
+
result = Yadis.get_canonical_id('xri://=nishitani*masaki', xmldoc)
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
end
|
data/test/test_xri.rb
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
require 'test/unit'
|
|
2
|
+
require 'openid/yadis/xri'
|
|
3
|
+
|
|
4
|
+
module OpenID
|
|
5
|
+
|
|
6
|
+
module Yadis
|
|
7
|
+
|
|
8
|
+
class XriDiscoveryTestCase < Test::Unit::TestCase
|
|
9
|
+
|
|
10
|
+
def test_isXRI?
|
|
11
|
+
assert_equal(:xri, XRI.identifier_scheme('=john.smith'))
|
|
12
|
+
assert_equal(:xri, XRI.identifier_scheme('@smiths/john'))
|
|
13
|
+
assert_equal(:xri, XRI.identifier_scheme('xri://=john'))
|
|
14
|
+
assert_equal(:xri, XRI.identifier_scheme('@ootao*test1'))
|
|
15
|
+
assert_equal(:uri, XRI.identifier_scheme('smoker.myopenid.com'))
|
|
16
|
+
assert_equal(:uri, XRI.identifier_scheme('http://smoker.myopenid.com'))
|
|
17
|
+
assert_equal(:uri, XRI.identifier_scheme('https://smoker.myopenid.com'))
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
class XriEscapingTestCase < Test::Unit::TestCase
|
|
22
|
+
def test_escaping_percents
|
|
23
|
+
assert_equal('@example/abc%252Fd/ef',
|
|
24
|
+
XRI.escape_for_iri('@example/abc%2Fd/ef'))
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_escaping_xref
|
|
28
|
+
# no escapes
|
|
29
|
+
assert_equal('@example/foo/(@bar)',
|
|
30
|
+
XRI.escape_for_iri('@example/foo/(@bar)'))
|
|
31
|
+
# escape slashes
|
|
32
|
+
assert_equal('@example/foo/(@bar%2Fbaz)',
|
|
33
|
+
XRI.escape_for_iri('@example/foo/(@bar/baz)'))
|
|
34
|
+
# escape query ? and fragment #
|
|
35
|
+
assert_equal('@example/foo/(@baz%3Fp=q%23r)?i=j#k',
|
|
36
|
+
XRI.escape_for_iri('@example/foo/(@baz?p=q#r)?i=j#k'))
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
class XriTransformationTestCase < Test::Unit::TestCase
|
|
41
|
+
def test_to_iri_normal
|
|
42
|
+
assert_equal('xri://@example', XRI.to_iri_normal('@example'))
|
|
43
|
+
end
|
|
44
|
+
# iri_to_url:
|
|
45
|
+
# various ucschar to hex
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
data/test/test_xrires.rb
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
|
|
2
|
+
require 'test/unit'
|
|
3
|
+
require 'openid/yadis/xrires'
|
|
4
|
+
|
|
5
|
+
module OpenID
|
|
6
|
+
module Yadis
|
|
7
|
+
|
|
8
|
+
class XRDSFetcher
|
|
9
|
+
def initialize(results)
|
|
10
|
+
@results = results
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def fetch(url, body=nil, headers=nil, redirect_limit=nil)
|
|
14
|
+
if !@results.empty?
|
|
15
|
+
return @results.shift
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
nil
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
class ProxyQueryTestCase < Test::Unit::TestCase
|
|
23
|
+
def setup
|
|
24
|
+
@proxy_url = 'http://xri.example.com/'
|
|
25
|
+
@proxy = XRI::ProxyResolver.new(@proxy_url)
|
|
26
|
+
@servicetype = 'xri://+i-service*(+forwarding)*($v*1.0)'
|
|
27
|
+
@servicetype_enc = 'xri%3A%2F%2F%2Bi-service%2A%28%2Bforwarding%29%2A%28%24v%2A1.0%29'
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def test_proxy_url
|
|
31
|
+
st = @servicetype
|
|
32
|
+
ste = @servicetype_enc
|
|
33
|
+
args_esc = "_xrd_r=application%2Fxrds%2Bxml&_xrd_t=" + ste
|
|
34
|
+
pqu = @proxy.method('query_url')
|
|
35
|
+
h = @proxy_url
|
|
36
|
+
|
|
37
|
+
assert_equal(h + '=foo?' + args_esc, pqu.call('=foo', st))
|
|
38
|
+
assert_equal(h + '=foo/bar?baz&' + args_esc,
|
|
39
|
+
pqu.call('=foo/bar?baz', st))
|
|
40
|
+
assert_equal(h + '=foo/bar?baz=quux&' + args_esc,
|
|
41
|
+
pqu.call('=foo/bar?baz=quux', st))
|
|
42
|
+
assert_equal(h + '=foo/bar?mi=fa&so=la&' + args_esc,
|
|
43
|
+
pqu.call('=foo/bar?mi=fa&so=la', st))
|
|
44
|
+
|
|
45
|
+
# With no service endpoint selection.
|
|
46
|
+
args_esc = "_xrd_r=application%2Fxrds%2Bxml%3Bsep%3Dfalse"
|
|
47
|
+
assert_equal(h + '=foo?' + args_esc, pqu.call('=foo', nil))
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def test_proxy_url_qmarks
|
|
51
|
+
st = @servicetype
|
|
52
|
+
ste = @servicetype_enc
|
|
53
|
+
args_esc = "_xrd_r=application%2Fxrds%2Bxml&_xrd_t=" + ste
|
|
54
|
+
pqu = @proxy.method('query_url')
|
|
55
|
+
h = @proxy_url
|
|
56
|
+
|
|
57
|
+
assert_equal(h + '=foo/bar??' + args_esc, pqu.call('=foo/bar?', st))
|
|
58
|
+
assert_equal(h + '=foo/bar????' + args_esc,
|
|
59
|
+
pqu.call('=foo/bar???', st))
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
|
|
2
|
+
require 'test/unit'
|
|
3
|
+
require 'uri'
|
|
4
|
+
require 'testutil'
|
|
5
|
+
|
|
6
|
+
require 'openid/yadis/discovery'
|
|
7
|
+
require 'openid/fetchers'
|
|
8
|
+
require 'openid/util'
|
|
9
|
+
require 'discoverdata'
|
|
10
|
+
|
|
11
|
+
module OpenID
|
|
12
|
+
|
|
13
|
+
module YadisDiscovery
|
|
14
|
+
include FetcherMixin
|
|
15
|
+
include DiscoverData
|
|
16
|
+
|
|
17
|
+
STATUS_HEADER_RE = /Status: (\d+) .*?$/m
|
|
18
|
+
|
|
19
|
+
four04_pat = "\nContent-Type: text/plain\n\nNo such file %s"
|
|
20
|
+
|
|
21
|
+
def self.mkResponse(data)
|
|
22
|
+
status_mo = data.scan(STATUS_HEADER_RE)
|
|
23
|
+
headers_str, body = data.split("\n\n", 2)
|
|
24
|
+
headers = {}
|
|
25
|
+
headers_str.split("\n", -1).each { |line|
|
|
26
|
+
k, v = line.split(':', 2)
|
|
27
|
+
k = k.strip().downcase
|
|
28
|
+
v = v.strip()
|
|
29
|
+
headers[k] = v
|
|
30
|
+
}
|
|
31
|
+
status = status_mo[0][0].to_i
|
|
32
|
+
return HTTPResponse._from_raw_data(status, body,
|
|
33
|
+
headers)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
class TestFetcher
|
|
37
|
+
include DiscoverData
|
|
38
|
+
|
|
39
|
+
def initialize(base_url)
|
|
40
|
+
@base_url = base_url
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def fetch(url, headers, body, redirect_limit=nil)
|
|
44
|
+
current_url = url
|
|
45
|
+
while true
|
|
46
|
+
parsed = URI::parse(current_url)
|
|
47
|
+
# parsed[2][1:]
|
|
48
|
+
path = parsed.path[1..-1]
|
|
49
|
+
begin
|
|
50
|
+
data = generateSample(path, @base_url)
|
|
51
|
+
rescue ArgumentError
|
|
52
|
+
return HTTPResponse._from_raw_data(404, '', {},
|
|
53
|
+
current_url)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
response = YadisDiscovery.mkResponse(data)
|
|
57
|
+
if ["301", "302", "303", "307"].member?(response.code)
|
|
58
|
+
current_url = response['location']
|
|
59
|
+
else
|
|
60
|
+
response.final_url = current_url
|
|
61
|
+
return response
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
class MockFetcher
|
|
68
|
+
def initialize
|
|
69
|
+
@count = 0
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def fetch(uri, headers=nil, body=nil, redirect_limit=nil)
|
|
73
|
+
@count += 1
|
|
74
|
+
if @count == 1
|
|
75
|
+
headers = {
|
|
76
|
+
'X-XRDS-Location'.downcase => 'http://unittest/404',
|
|
77
|
+
}
|
|
78
|
+
return HTTPResponse._from_raw_data(200, '', headers, uri)
|
|
79
|
+
else
|
|
80
|
+
return HTTPResponse._from_raw_data(404, '', {}, uri)
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
class TestSecondGet < Test::Unit::TestCase
|
|
86
|
+
include FetcherMixin
|
|
87
|
+
|
|
88
|
+
def test_404
|
|
89
|
+
uri = "http://something.unittest/"
|
|
90
|
+
assert_raise(DiscoveryFailure) {
|
|
91
|
+
with_fetcher(MockFetcher.new) { Yadis.discover(uri) }
|
|
92
|
+
}
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
class DiscoveryTestCase
|
|
97
|
+
include DiscoverData
|
|
98
|
+
include FetcherMixin
|
|
99
|
+
|
|
100
|
+
def initialize(testcase, input_name, id_name, result_name, success)
|
|
101
|
+
@base_url = 'http://invalid.unittest/'
|
|
102
|
+
@testcase = testcase
|
|
103
|
+
@input_name = input_name
|
|
104
|
+
@id_name = id_name
|
|
105
|
+
@result_name = result_name
|
|
106
|
+
@success = success
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def setup
|
|
110
|
+
@input_url, @expected = generateResult(@base_url,
|
|
111
|
+
@input_name,
|
|
112
|
+
@id_name,
|
|
113
|
+
@result_name,
|
|
114
|
+
@success)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def do_discovery
|
|
118
|
+
with_fetcher(TestFetcher.new(@base_url)) do
|
|
119
|
+
Yadis.discover(@input_url)
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def runCustomTest
|
|
124
|
+
setup
|
|
125
|
+
|
|
126
|
+
if @expected.respond_to?("ancestors") and @expected.ancestors.member?(DiscoveryFailure)
|
|
127
|
+
@testcase.assert_raise(DiscoveryFailure) {
|
|
128
|
+
do_discovery
|
|
129
|
+
}
|
|
130
|
+
else
|
|
131
|
+
result = do_discovery
|
|
132
|
+
@testcase.assert_equal(@input_url, result.request_uri)
|
|
133
|
+
|
|
134
|
+
msg = sprintf("Identity URL mismatch: actual = %s, expected = %s",
|
|
135
|
+
result.normalized_uri, @expected.normalized_uri)
|
|
136
|
+
@testcase.assert_equal(@expected.normalized_uri, result.normalized_uri, msg)
|
|
137
|
+
|
|
138
|
+
msg = sprintf("Content mismatch: actual = %s, expected = %s",
|
|
139
|
+
result.response_text, @expected.response_text)
|
|
140
|
+
@testcase.assert_equal(@expected.response_text, result.response_text, msg)
|
|
141
|
+
|
|
142
|
+
expected_keys = @expected.instance_variables
|
|
143
|
+
expected_keys.sort!
|
|
144
|
+
|
|
145
|
+
actual_keys = result.instance_variables
|
|
146
|
+
actual_keys.sort!
|
|
147
|
+
|
|
148
|
+
@testcase.assert_equal(actual_keys, expected_keys)
|
|
149
|
+
|
|
150
|
+
@expected.instance_variables.each { |k|
|
|
151
|
+
exp_v = @expected.instance_variable_get(k)
|
|
152
|
+
act_v = result.instance_variable_get(k)
|
|
153
|
+
@testcase.assert_equal(act_v, exp_v, [k, exp_v, act_v])
|
|
154
|
+
}
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
class NoContentTypeFetcher
|
|
160
|
+
def fetch(url, body=nil, headers=nil, redirect_limit=nil)
|
|
161
|
+
return OpenID::HTTPResponse._from_raw_data(200, "", {}, nil)
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
class BlankContentTypeFetcher
|
|
166
|
+
def fetch(url, body=nil, headers=nil, redirect_limit=nil)
|
|
167
|
+
return OpenID::HTTPResponse._from_raw_data(200, "", {"Content-Type" => ""}, nil)
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
class TestYadisDiscovery < Test::Unit::TestCase
|
|
172
|
+
include FetcherMixin
|
|
173
|
+
|
|
174
|
+
def test_yadis_discovery
|
|
175
|
+
DiscoverData::TESTLIST.each { |success, input_name, id_name, result_name|
|
|
176
|
+
test = DiscoveryTestCase.new(self, input_name, id_name, result_name, success)
|
|
177
|
+
test.runCustomTest
|
|
178
|
+
}
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
def test_is_xrds_yadis_location
|
|
182
|
+
result = Yadis::DiscoveryResult.new('http://request.uri/')
|
|
183
|
+
result.normalized_uri = "http://normalized/"
|
|
184
|
+
result.xrds_uri = "http://normalized/xrds"
|
|
185
|
+
|
|
186
|
+
assert(result.is_xrds)
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
def test_is_xrds_content_type
|
|
190
|
+
result = Yadis::DiscoveryResult.new('http://request.uri/')
|
|
191
|
+
result.normalized_uri = result.xrds_uri = "http://normalized/"
|
|
192
|
+
result.content_type = Yadis::YADIS_CONTENT_TYPE
|
|
193
|
+
|
|
194
|
+
assert(result.is_xrds)
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
def test_is_xrds_neither
|
|
198
|
+
result = Yadis::DiscoveryResult.new('http://request.uri/')
|
|
199
|
+
result.normalized_uri = result.xrds_uri = "http://normalized/"
|
|
200
|
+
result.content_type = "another/content-type"
|
|
201
|
+
|
|
202
|
+
assert(!result.is_xrds)
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
def test_no_content_type
|
|
206
|
+
with_fetcher(NoContentTypeFetcher.new) do
|
|
207
|
+
result = Yadis.discover("http://bogus")
|
|
208
|
+
assert_equal(nil, result.content_type)
|
|
209
|
+
end
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
def test_blank_content_type
|
|
213
|
+
with_fetcher(BlankContentTypeFetcher.new) do
|
|
214
|
+
result = Yadis.discover("http://bogus")
|
|
215
|
+
assert_equal("", result.content_type)
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
end
|
|
220
|
+
end
|
data/test/testutil.rb
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
require "pathname"
|
|
2
|
+
|
|
3
|
+
module OpenID
|
|
4
|
+
module TestDataMixin
|
|
5
|
+
TESTS_DIR = Pathname.new(__FILE__).dirname
|
|
6
|
+
TEST_DATA_DIR = Pathname.new('data')
|
|
7
|
+
|
|
8
|
+
def read_data_file(filename, lines=true, data_dir=TEST_DATA_DIR)
|
|
9
|
+
fname = TESTS_DIR.join(data_dir, filename)
|
|
10
|
+
|
|
11
|
+
if lines
|
|
12
|
+
fname.readlines
|
|
13
|
+
else
|
|
14
|
+
fname.read
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
module FetcherMixin
|
|
20
|
+
def with_fetcher(fetcher)
|
|
21
|
+
original_fetcher = OpenID.fetcher
|
|
22
|
+
begin
|
|
23
|
+
OpenID.fetcher = fetcher
|
|
24
|
+
return yield
|
|
25
|
+
ensure
|
|
26
|
+
OpenID.fetcher = original_fetcher
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
module Const
|
|
32
|
+
def const(symbol, value)
|
|
33
|
+
(class << self;self;end).instance_eval do
|
|
34
|
+
define_method(symbol) { value }
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
class MockResponse
|
|
40
|
+
attr_reader :code, :body
|
|
41
|
+
|
|
42
|
+
def initialize(code, body)
|
|
43
|
+
@code = code.to_s
|
|
44
|
+
@body = body
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
module ProtocolErrorMixin
|
|
49
|
+
def assert_protocol_error(str_prefix)
|
|
50
|
+
begin
|
|
51
|
+
result = yield
|
|
52
|
+
rescue ProtocolError => why
|
|
53
|
+
message = "Expected prefix #{str_prefix.inspect}, got "\
|
|
54
|
+
"#{why.message.inspect}"
|
|
55
|
+
assert(why.message.starts_with?(str_prefix), message)
|
|
56
|
+
else
|
|
57
|
+
fail("Expected ProtocolError. Got #{result.inspect}")
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
module OverrideMethodMixin
|
|
63
|
+
def with_method_overridden(method_name, proc)
|
|
64
|
+
original = method(method_name)
|
|
65
|
+
begin
|
|
66
|
+
# TODO: find a combination of undef calls which prevent the warning
|
|
67
|
+
verbose, $VERBOSE = $VERBOSE, false
|
|
68
|
+
define_method(method_name, proc)
|
|
69
|
+
module_function(method_name)
|
|
70
|
+
$VERBOSE = verbose
|
|
71
|
+
yield
|
|
72
|
+
ensure
|
|
73
|
+
if original.respond_to? :owner
|
|
74
|
+
original.owner.send(:undef_method, method_name)
|
|
75
|
+
original.owner.send :define_method, method_name, original
|
|
76
|
+
else
|
|
77
|
+
define_method(method_name, original)
|
|
78
|
+
module_function(method_name)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# To use:
|
|
85
|
+
# > x = Object.new
|
|
86
|
+
# > x.extend(InstanceDefExtension)
|
|
87
|
+
# > x.instance_def(:monkeys) do
|
|
88
|
+
# > "bananas"
|
|
89
|
+
# > end
|
|
90
|
+
# > x.monkeys
|
|
91
|
+
#
|
|
92
|
+
module InstanceDefExtension
|
|
93
|
+
def instance_def(method_name, &proc)
|
|
94
|
+
(class << self;self;end).instance_eval do
|
|
95
|
+
# TODO: find a combination of undef calls which prevent the warning
|
|
96
|
+
verbose, $VERBOSE = $VERBOSE, false
|
|
97
|
+
define_method(method_name, proc)
|
|
98
|
+
$VERBOSE = verbose
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
GOODSIG = '[A Good Signature]'
|
|
104
|
+
|
|
105
|
+
class GoodAssoc
|
|
106
|
+
attr_accessor :handle, :expires_in
|
|
107
|
+
|
|
108
|
+
def initialize(handle='-blah-')
|
|
109
|
+
@handle = handle
|
|
110
|
+
@expires_in = 3600
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def check_message_signature(msg)
|
|
114
|
+
msg.get_arg(OPENID_NS, 'sig') == GOODSIG
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
class HTTPResponse
|
|
119
|
+
def self._from_raw_data(status, body="", headers={}, final_url=nil)
|
|
120
|
+
resp = Net::HTTPResponse.new('1.1', status.to_s, 'NONE')
|
|
121
|
+
me = self._from_net_response(resp, final_url)
|
|
122
|
+
me.initialize_http_header headers
|
|
123
|
+
me.body = body
|
|
124
|
+
return me
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
data/test/util.rb
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Utilities that are only used in the testing code
|
|
2
|
+
require 'stringio'
|
|
3
|
+
|
|
4
|
+
module OpenID
|
|
5
|
+
module TestUtil
|
|
6
|
+
def assert_log_matches(*regexes)
|
|
7
|
+
begin
|
|
8
|
+
old_logger = Util.logger
|
|
9
|
+
log_output = StringIO.new
|
|
10
|
+
Util.logger = Logger.new(log_output)
|
|
11
|
+
result = yield
|
|
12
|
+
ensure
|
|
13
|
+
Util.logger = old_logger
|
|
14
|
+
end
|
|
15
|
+
log_output.rewind
|
|
16
|
+
log_lines = log_output.readlines
|
|
17
|
+
assert_equal(regexes.length, log_lines.length,
|
|
18
|
+
[regexes, log_lines].inspect)
|
|
19
|
+
log_lines.zip(regexes) do |line, regex|
|
|
20
|
+
assert_match(regex, line)
|
|
21
|
+
end
|
|
22
|
+
result
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def assert_log_line_count(num_lines)
|
|
26
|
+
begin
|
|
27
|
+
old_logger = Util.logger
|
|
28
|
+
log_output = StringIO.new
|
|
29
|
+
Util.logger = Logger.new(log_output)
|
|
30
|
+
result = yield
|
|
31
|
+
ensure
|
|
32
|
+
Util.logger = old_logger
|
|
33
|
+
end
|
|
34
|
+
log_output.rewind
|
|
35
|
+
log_lines = log_output.readlines
|
|
36
|
+
assert_equal(num_lines, log_lines.length)
|
|
37
|
+
result
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def silence_logging
|
|
41
|
+
begin
|
|
42
|
+
old_logger = Util.logger
|
|
43
|
+
log_output = StringIO.new
|
|
44
|
+
Util.logger = Logger.new(log_output)
|
|
45
|
+
result = yield
|
|
46
|
+
ensure
|
|
47
|
+
Util.logger = old_logger
|
|
48
|
+
end
|
|
49
|
+
result
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|