ruby-openid 1.1.4 → 2.0.1
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/INSTALL +0 -9
- data/README +21 -22
- data/UPGRADE +117 -0
- data/admin/runtests.rb +36 -0
- data/examples/README +13 -21
- data/examples/active_record_openid_store/README +8 -3
- data/examples/active_record_openid_store/XXX_add_open_id_store_to_db.rb +4 -8
- data/examples/active_record_openid_store/XXX_upgrade_open_id_store.rb +26 -0
- data/examples/active_record_openid_store/lib/association.rb +2 -0
- data/examples/active_record_openid_store/lib/openid_ar_store.rb +22 -47
- data/examples/active_record_openid_store/test/store_test.rb +78 -48
- data/examples/discover +46 -0
- data/examples/{rails_server → rails_openid}/README +0 -0
- data/examples/{rails_server → rails_openid}/Rakefile +0 -0
- data/examples/{rails_server → rails_openid}/app/controllers/application.rb +0 -0
- data/examples/rails_openid/app/controllers/consumer_controller.rb +115 -0
- data/examples/{rails_server → rails_openid}/app/controllers/login_controller.rb +10 -2
- data/examples/rails_openid/app/controllers/server_controller.rb +265 -0
- data/examples/{rails_server → rails_openid}/app/helpers/application_helper.rb +0 -0
- data/examples/{rails_server → rails_openid}/app/helpers/login_helper.rb +0 -0
- data/examples/{rails_server → rails_openid}/app/helpers/server_helper.rb +0 -0
- data/examples/rails_openid/app/views/consumer/index.rhtml +81 -0
- data/examples/rails_openid/app/views/consumer/start.rhtml +8 -0
- data/examples/{rails_server → rails_openid}/app/views/layouts/server.rhtml +0 -0
- data/examples/{rails_server → rails_openid}/app/views/login/index.rhtml +1 -1
- data/examples/rails_openid/app/views/server/decide.rhtml +26 -0
- data/examples/{rails_server → rails_openid}/config/boot.rb +0 -0
- data/examples/{rails_server → rails_openid}/config/database.yml +0 -0
- data/examples/{rails_server → rails_openid}/config/environment.rb +0 -0
- data/examples/{rails_server → rails_openid}/config/environments/development.rb +0 -0
- data/examples/{rails_server → rails_openid}/config/environments/production.rb +0 -0
- data/examples/{rails_server → rails_openid}/config/environments/test.rb +0 -0
- data/examples/{rails_server → rails_openid}/config/routes.rb +2 -1
- data/examples/{rails_server → rails_openid}/doc/README_FOR_APP +0 -0
- data/examples/{rails_server → rails_openid}/public/404.html +0 -0
- data/examples/{rails_server → rails_openid}/public/500.html +0 -0
- data/examples/{rails_server → rails_openid}/public/dispatch.cgi +0 -0
- data/examples/{rails_server → rails_openid}/public/dispatch.fcgi +0 -0
- data/examples/{rails_server → rails_openid}/public/dispatch.rb +0 -0
- data/examples/{rails_server → rails_openid}/public/favicon.ico +0 -0
- data/examples/rails_openid/public/images/openid_login_bg.gif +0 -0
- data/examples/{rails_server → rails_openid}/public/javascripts/controls.js +0 -0
- data/examples/{rails_server → rails_openid}/public/javascripts/dragdrop.js +0 -0
- data/examples/{rails_server → rails_openid}/public/javascripts/effects.js +0 -0
- data/examples/{rails_server → rails_openid}/public/javascripts/prototype.js +0 -0
- data/examples/{rails_server → rails_openid}/public/robots.txt +0 -0
- data/examples/{rails_server → rails_openid}/script/about +0 -0
- data/examples/{rails_server → rails_openid}/script/breakpointer +0 -0
- data/examples/{rails_server → rails_openid}/script/console +0 -0
- data/examples/{rails_server → rails_openid}/script/destroy +0 -0
- data/examples/{rails_server → rails_openid}/script/generate +0 -0
- data/examples/{rails_server → rails_openid}/script/performance/benchmarker +0 -0
- data/examples/{rails_server → rails_openid}/script/performance/profiler +0 -0
- data/examples/{rails_server → rails_openid}/script/plugin +0 -0
- data/examples/{rails_server → rails_openid}/script/process/reaper +0 -0
- data/examples/{rails_server → rails_openid}/script/process/spawner +0 -0
- data/examples/{rails_server → rails_openid}/script/process/spinner +0 -0
- data/examples/{rails_server → rails_openid}/script/runner +0 -0
- data/examples/{rails_server → rails_openid}/script/server +0 -0
- data/examples/{rails_server → rails_openid}/test/functional/login_controller_test.rb +0 -0
- data/examples/{rails_server → rails_openid}/test/functional/server_controller_test.rb +0 -0
- data/examples/{rails_server → rails_openid}/test/test_helper.rb +0 -0
- data/lib/{hmac.rb → hmac/hmac.rb} +0 -0
- data/lib/{hmac-sha1.rb → hmac/sha1.rb} +1 -1
- data/lib/{hmac-sha2.rb → hmac/sha2.rb} +1 -1
- data/lib/openid/association.rb +213 -73
- data/lib/openid/consumer/associationmanager.rb +338 -0
- data/lib/openid/consumer/checkid_request.rb +175 -0
- data/lib/openid/consumer/discovery.rb +480 -0
- data/lib/openid/consumer/discovery_manager.rb +123 -0
- data/lib/openid/consumer/html_parse.rb +136 -0
- data/lib/openid/consumer/idres.rb +525 -0
- data/lib/openid/consumer/responses.rb +133 -0
- data/lib/openid/consumer.rb +280 -807
- data/lib/openid/cryptutil.rb +85 -0
- data/lib/openid/dh.rb +60 -23
- data/lib/openid/extension.rb +31 -0
- data/lib/openid/extensions/ax.rb +506 -0
- data/lib/openid/extensions/pape.rb +182 -0
- data/lib/openid/extensions/sreg.rb +275 -0
- data/lib/openid/extras.rb +11 -0
- data/lib/openid/fetchers.rb +132 -93
- data/lib/openid/kvform.rb +133 -0
- data/lib/openid/kvpost.rb +56 -0
- data/lib/openid/message.rb +534 -0
- data/lib/openid/protocolerror.rb +6 -0
- data/lib/openid/server.rb +1215 -666
- data/lib/openid/store/filesystem.rb +271 -0
- data/lib/openid/store/interface.rb +75 -0
- data/lib/openid/store/memory.rb +84 -0
- data/lib/openid/store/nonce.rb +68 -0
- data/lib/openid/trustroot.rb +314 -87
- data/lib/openid/urinorm.rb +37 -34
- data/lib/openid/util.rb +42 -220
- 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/{htmltokenizer.rb → yadis/htmltokenizer.rb} +1 -54
- data/lib/openid/yadis/parsehtml.rb +36 -0
- data/lib/openid/yadis/services.rb +42 -0
- data/lib/openid/yadis/xrds.rb +171 -0
- data/lib/openid/yadis/xri.rb +90 -0
- data/lib/openid/yadis/xrires.rb +106 -0
- data/lib/openid.rb +1 -4
- 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 +128 -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/valid-populated-xrds.xml +39 -0
- data/test/data/trustroot.txt +147 -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 +899 -0
- data/test/test_ax.rb +587 -0
- data/test/test_checkid_request.rb +297 -0
- data/test/test_consumer.rb +257 -0
- data/test/test_cryptutil.rb +117 -0
- data/test/test_dh.rb +86 -0
- data/test/test_discover.rb +772 -0
- data/test/test_discovery_manager.rb +262 -0
- data/test/test_extras.rb +35 -0
- data/test/test_fetchers.rb +472 -0
- data/test/test_filters.rb +270 -0
- data/test/test_idres.rb +816 -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 +1058 -0
- data/test/test_nonce.rb +89 -0
- data/test/test_openid_yadis.rb +178 -0
- data/test/test_pape.rb +233 -0
- data/test/test_parsehtml.rb +80 -0
- data/test/test_responses.rb +63 -0
- data/test/test_server.rb +2270 -0
- data/test/test_sreg.rb +479 -0
- data/test/test_stores.rb +269 -0
- data/test/test_trustroot.rb +112 -0
- data/test/{urinorm.rb → test_urinorm.rb} +6 -3
- data/test/test_util.rb +144 -0
- data/test/test_xrds.rb +160 -0
- data/test/test_xri.rb +48 -0
- data/test/test_xrires.rb +63 -0
- data/test/test_yadis_discovery.rb +207 -0
- data/test/testutil.rb +116 -0
- data/test/util.rb +47 -50
- metadata +233 -143
- data/examples/consumer.rb +0 -290
- data/examples/rails_openid_login_generator/openid_login_generator-0.1.gem +0 -0
- data/examples/rails_server/app/controllers/server_controller.rb +0 -190
- data/examples/rails_server/app/views/server/decide.rhtml +0 -11
- data/examples/rails_server/public/images/rails.png +0 -0
- data/lib/hmac-md5.rb +0 -11
- data/lib/hmac-rmd160.rb +0 -11
- data/lib/openid/discovery.rb +0 -122
- data/lib/openid/filestore.rb +0 -315
- data/lib/openid/parse.rb +0 -23
- data/lib/openid/service.rb +0 -147
- data/lib/openid/stores.rb +0 -178
- data/test/assoc.rb +0 -38
- data/test/consumer.rb +0 -376
- data/test/data/brian.xrds +0 -16
- data/test/data/brianellin.mylid.xrds +0 -42
- data/test/dh.rb +0 -20
- data/test/extensions.rb +0 -30
- data/test/linkparse.rb +0 -305
- data/test/runtests.rb +0 -22
- data/test/server2.rb +0 -1053
- data/test/service.rb +0 -47
- data/test/storetestcase.rb +0 -172
- data/test/teststore.rb +0 -47
- data/test/trustroot.rb +0 -117
data/test/test_nonce.rb
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
require 'test/unit'
|
|
2
|
+
require 'openid/store/nonce'
|
|
3
|
+
|
|
4
|
+
module OpenID
|
|
5
|
+
class NonceTestCase < Test::Unit::TestCase
|
|
6
|
+
|
|
7
|
+
NONCE_RE = /\A\d{4}-\d\d-\d\dT\d\d:\d\d:\d\dZ/
|
|
8
|
+
|
|
9
|
+
def test_mk_nonce
|
|
10
|
+
nonce = Nonce::mk_nonce
|
|
11
|
+
assert(nonce.match(NONCE_RE))
|
|
12
|
+
assert(nonce.size == 26)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_mk_nonce_time
|
|
16
|
+
nonce = Nonce::mk_nonce(0)
|
|
17
|
+
assert(nonce.match(NONCE_RE))
|
|
18
|
+
assert(nonce.size == 26)
|
|
19
|
+
assert(nonce.match(/^1970-01-01T00:00:00Z/))
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_split
|
|
23
|
+
s = '1970-01-01T00:00:00Z'
|
|
24
|
+
expected_t = 0
|
|
25
|
+
expected_salt = ''
|
|
26
|
+
actual_t, actual_salt = Nonce::split_nonce(s)
|
|
27
|
+
assert_equal(expected_t, actual_t)
|
|
28
|
+
assert_equal(expected_salt, actual_salt)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_mk_split
|
|
32
|
+
t = 42
|
|
33
|
+
nonce_str = Nonce::mk_nonce(t)
|
|
34
|
+
assert(nonce_str.match(NONCE_RE))
|
|
35
|
+
at, salt = Nonce::split_nonce(nonce_str)
|
|
36
|
+
assert_equal(6, salt.size)
|
|
37
|
+
assert_equal(t, at)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_bad_split
|
|
41
|
+
cases = [
|
|
42
|
+
'',
|
|
43
|
+
'1970-01-01T00:00:00+1:00',
|
|
44
|
+
'1969-01-01T00:00:00Z',
|
|
45
|
+
'1970-00-01T00:00:00Z',
|
|
46
|
+
'1970.01-01T00:00:00Z',
|
|
47
|
+
'Thu Sep 7 13:29:31 PDT 2006',
|
|
48
|
+
'monkeys',
|
|
49
|
+
]
|
|
50
|
+
cases.each{|c|
|
|
51
|
+
assert_raises(ArgumentError, c.inspect) { Nonce::split_nonce(c) }
|
|
52
|
+
}
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def test_check_timestamp
|
|
56
|
+
cases = [
|
|
57
|
+
# exact, no allowed skew
|
|
58
|
+
['1970-01-01T00:00:00Z', 0, 0, true],
|
|
59
|
+
|
|
60
|
+
# exact, large skew
|
|
61
|
+
['1970-01-01T00:00:00Z', 1000, 0, true],
|
|
62
|
+
|
|
63
|
+
# no allowed skew, one second old
|
|
64
|
+
['1970-01-01T00:00:00Z', 0, 1, false],
|
|
65
|
+
|
|
66
|
+
# many seconds old, outside of skew
|
|
67
|
+
['1970-01-01T00:00:00Z', 10, 50, false],
|
|
68
|
+
|
|
69
|
+
# one second old, one second skew allowed
|
|
70
|
+
['1970-01-01T00:00:00Z', 1, 1, true],
|
|
71
|
+
|
|
72
|
+
# One second in the future, one second skew allowed
|
|
73
|
+
['1970-01-01T00:00:02Z', 1, 1, true],
|
|
74
|
+
|
|
75
|
+
# two seconds in the future, one second skew allowed
|
|
76
|
+
['1970-01-01T00:00:02Z', 1, 0, false],
|
|
77
|
+
|
|
78
|
+
# malformed nonce string
|
|
79
|
+
['monkeys', 0, 0, false],
|
|
80
|
+
]
|
|
81
|
+
|
|
82
|
+
cases.each{|c|
|
|
83
|
+
(nonce_str, allowed_skew, now, expected) = c
|
|
84
|
+
actual = Nonce::check_timestamp(nonce_str, allowed_skew, now)
|
|
85
|
+
assert_equal(expected, actual, c.inspect)
|
|
86
|
+
}
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
|
|
2
|
+
require 'test/unit'
|
|
3
|
+
require 'openid/consumer/discovery'
|
|
4
|
+
require 'openid/yadis/services'
|
|
5
|
+
|
|
6
|
+
module OpenID
|
|
7
|
+
|
|
8
|
+
XRDS_BOILERPLATE = <<EOF
|
|
9
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
10
|
+
<xrds:XRDS xmlns:xrds="xri://$xrds"
|
|
11
|
+
xmlns="xri://$xrd*($v*2.0)"
|
|
12
|
+
xmlns:openid="http://openid.net/xmlns/1.0">
|
|
13
|
+
<XRD>
|
|
14
|
+
%s
|
|
15
|
+
</XRD>
|
|
16
|
+
</xrds:XRDS>
|
|
17
|
+
EOF
|
|
18
|
+
|
|
19
|
+
def self.mkXRDS(services)
|
|
20
|
+
return sprintf(XRDS_BOILERPLATE, services)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.mkService(uris=nil, type_uris=nil, local_id=nil, dent=" ")
|
|
24
|
+
chunks = [dent, "<Service>\n"]
|
|
25
|
+
dent2 = dent + " "
|
|
26
|
+
if type_uris
|
|
27
|
+
type_uris.each { |type_uri|
|
|
28
|
+
chunks += [dent2 + "<Type>", type_uri, "</Type>\n"]
|
|
29
|
+
}
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
if uris
|
|
33
|
+
uris.each { |uri|
|
|
34
|
+
if uri.is_a?(Array)
|
|
35
|
+
uri, prio = uri
|
|
36
|
+
else
|
|
37
|
+
prio = nil
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
chunks += [dent2, "<URI"]
|
|
41
|
+
if !prio.nil?
|
|
42
|
+
chunks += [" priority='", str(prio), "'"]
|
|
43
|
+
end
|
|
44
|
+
chunks += [">", uri, "</URI>\n"]
|
|
45
|
+
}
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
if local_id
|
|
49
|
+
chunks += [dent2, "<openid:Delegate>", local_id, "</openid:Delegate>\n"]
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
chunks += [dent, "</Service>\n"]
|
|
53
|
+
|
|
54
|
+
return chunks.join("")
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Different sets of server URLs for use in the URI tag
|
|
58
|
+
SERVER_URL_OPTIONS = [
|
|
59
|
+
[], # This case should not generate an endpoint object
|
|
60
|
+
['http://server.url/'],
|
|
61
|
+
['https://server.url/'],
|
|
62
|
+
['https://server.url/', 'http://server.url/'],
|
|
63
|
+
['https://server.url/',
|
|
64
|
+
'http://server.url/',
|
|
65
|
+
'http://example.server.url/'],
|
|
66
|
+
]
|
|
67
|
+
|
|
68
|
+
# Used for generating test data
|
|
69
|
+
def OpenID.subsets(l)
|
|
70
|
+
subsets_list = [[]]
|
|
71
|
+
l.each { |x|
|
|
72
|
+
subsets_list += subsets_list.collect { |t| [x] + t }
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return subsets_list
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# A couple of example extension type URIs. These are not at all
|
|
79
|
+
# official, but are just here for testing.
|
|
80
|
+
EXT_TYPES = [
|
|
81
|
+
'http://janrain.com/extension/blah',
|
|
82
|
+
'http://openid.net/sreg/1.0',
|
|
83
|
+
]
|
|
84
|
+
|
|
85
|
+
# Range of valid Delegate tag values for generating test data
|
|
86
|
+
LOCAL_ID_OPTIONS = [
|
|
87
|
+
nil,
|
|
88
|
+
'http://vanity.domain/',
|
|
89
|
+
'https://somewhere/yadis/',
|
|
90
|
+
]
|
|
91
|
+
|
|
92
|
+
class OpenIDYadisTest
|
|
93
|
+
def initialize(uris, type_uris, local_id)
|
|
94
|
+
super()
|
|
95
|
+
@uris = uris
|
|
96
|
+
@type_uris = type_uris
|
|
97
|
+
@local_id = local_id
|
|
98
|
+
|
|
99
|
+
@yadis_url = 'http://unit.test/'
|
|
100
|
+
|
|
101
|
+
# Create an XRDS document to parse
|
|
102
|
+
services = OpenID.mkService(@uris,
|
|
103
|
+
@type_uris,
|
|
104
|
+
@local_id)
|
|
105
|
+
@xrds = OpenID.mkXRDS(services)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def runTest(testcase)
|
|
109
|
+
# Parse into endpoint objects that we will check
|
|
110
|
+
endpoints = Yadis.apply_filter(@yadis_url, @xrds, OpenIDServiceEndpoint)
|
|
111
|
+
|
|
112
|
+
# make sure there are the same number of endpoints as URIs. This
|
|
113
|
+
# assumes that the type_uris contains at least one OpenID type.
|
|
114
|
+
testcase.assert_equal(@uris.length, endpoints.length)
|
|
115
|
+
|
|
116
|
+
# So that we can check equality on the endpoint types
|
|
117
|
+
type_uris = @type_uris.dup
|
|
118
|
+
type_uris.sort!
|
|
119
|
+
|
|
120
|
+
seen_uris = []
|
|
121
|
+
endpoints.each { |endpoint|
|
|
122
|
+
seen_uris << endpoint.server_url
|
|
123
|
+
|
|
124
|
+
# All endpoints will have same yadis_url
|
|
125
|
+
testcase.assert_equal(@yadis_url, endpoint.claimed_id)
|
|
126
|
+
|
|
127
|
+
# and local_id
|
|
128
|
+
testcase.assert_equal(@local_id, endpoint.local_id)
|
|
129
|
+
|
|
130
|
+
# and types
|
|
131
|
+
actual_types = endpoint.type_uris.dup
|
|
132
|
+
actual_types.sort!
|
|
133
|
+
testcase.assert_equal(type_uris, actual_types, actual_types.inspect)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
# So that they will compare equal, because we don't care what
|
|
137
|
+
# order they are in
|
|
138
|
+
seen_uris.sort!
|
|
139
|
+
uris = @uris.dup
|
|
140
|
+
uris.sort!
|
|
141
|
+
|
|
142
|
+
# Make sure we saw all URIs, and saw each one once
|
|
143
|
+
testcase.assert_equal(uris, seen_uris)
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
class OpenIDYadisTests < Test::Unit::TestCase
|
|
148
|
+
def test_openid_yadis
|
|
149
|
+
data = []
|
|
150
|
+
|
|
151
|
+
# All valid combinations of Type tags that should produce an
|
|
152
|
+
# OpenID endpoint
|
|
153
|
+
type_uri_options = []
|
|
154
|
+
|
|
155
|
+
OpenID.subsets([OPENID_1_0_TYPE, OPENID_1_1_TYPE]).each { |ts|
|
|
156
|
+
OpenID.subsets(EXT_TYPES).each { |exts|
|
|
157
|
+
if !ts.empty?
|
|
158
|
+
type_uri_options << exts + ts
|
|
159
|
+
end
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
# All combinations of valid URIs, Type URIs and Delegate tags
|
|
164
|
+
SERVER_URL_OPTIONS.each { |uris|
|
|
165
|
+
type_uri_options.each { |type_uris|
|
|
166
|
+
LOCAL_ID_OPTIONS.each { |local_id|
|
|
167
|
+
data << [uris, type_uris, local_id]
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
data.each { |args|
|
|
173
|
+
t = OpenIDYadisTest.new(*args)
|
|
174
|
+
t.runTest(self)
|
|
175
|
+
}
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
end
|
data/test/test_pape.rb
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
require 'openid/extensions/pape'
|
|
2
|
+
require 'openid/message'
|
|
3
|
+
require 'openid/server'
|
|
4
|
+
|
|
5
|
+
module OpenID
|
|
6
|
+
module PAPETest
|
|
7
|
+
class PapeRequestTestCase < Test::Unit::TestCase
|
|
8
|
+
def setup
|
|
9
|
+
@req = PAPE::Request.new
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_construct
|
|
13
|
+
assert_equal([], @req.preferred_auth_policies)
|
|
14
|
+
assert_equal(nil, @req.max_auth_age)
|
|
15
|
+
assert_equal('pape', @req.ns_alias)
|
|
16
|
+
|
|
17
|
+
req2 = PAPE::Request.new([PAPE::AUTH_MULTI_FACTOR], 1000)
|
|
18
|
+
assert_equal([PAPE::AUTH_MULTI_FACTOR], req2.preferred_auth_policies)
|
|
19
|
+
assert_equal(1000, req2.max_auth_age)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_add_policy_uri
|
|
23
|
+
assert_equal([], @req.preferred_auth_policies)
|
|
24
|
+
@req.add_policy_uri(PAPE::AUTH_MULTI_FACTOR)
|
|
25
|
+
assert_equal([PAPE::AUTH_MULTI_FACTOR], @req.preferred_auth_policies)
|
|
26
|
+
@req.add_policy_uri(PAPE::AUTH_MULTI_FACTOR)
|
|
27
|
+
assert_equal([PAPE::AUTH_MULTI_FACTOR], @req.preferred_auth_policies)
|
|
28
|
+
@req.add_policy_uri(PAPE::AUTH_PHISHING_RESISTANT)
|
|
29
|
+
assert_equal([PAPE::AUTH_MULTI_FACTOR, PAPE::AUTH_PHISHING_RESISTANT], @req.preferred_auth_policies)
|
|
30
|
+
@req.add_policy_uri(PAPE::AUTH_MULTI_FACTOR)
|
|
31
|
+
assert_equal([PAPE::AUTH_MULTI_FACTOR, PAPE::AUTH_PHISHING_RESISTANT], @req.preferred_auth_policies)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def test_get_extension_args
|
|
35
|
+
assert_equal({'preferred_auth_policies' => ''}, @req.get_extension_args)
|
|
36
|
+
@req.add_policy_uri('http://uri')
|
|
37
|
+
assert_equal({'preferred_auth_policies' => 'http://uri'}, @req.get_extension_args)
|
|
38
|
+
@req.add_policy_uri('http://zig')
|
|
39
|
+
assert_equal({'preferred_auth_policies' => 'http://uri http://zig'}, @req.get_extension_args)
|
|
40
|
+
@req.max_auth_age = 789
|
|
41
|
+
assert_equal({'preferred_auth_policies' => 'http://uri http://zig', 'max_auth_age' => '789'}, @req.get_extension_args)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def test_parse_extension_args
|
|
45
|
+
args = {'preferred_auth_policies' => 'http://foo http://bar',
|
|
46
|
+
'max_auth_age' => '9'}
|
|
47
|
+
@req.parse_extension_args(args)
|
|
48
|
+
assert_equal(9, @req.max_auth_age)
|
|
49
|
+
assert_equal(['http://foo','http://bar'], @req.preferred_auth_policies)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def test_parse_extension_args_empty
|
|
53
|
+
@req.parse_extension_args({})
|
|
54
|
+
assert_equal(nil, @req.max_auth_age)
|
|
55
|
+
assert_equal([], @req.preferred_auth_policies)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def test_from_openid_request
|
|
59
|
+
openid_req_msg = Message.from_openid_args({
|
|
60
|
+
'mode' => 'checkid_setup',
|
|
61
|
+
'ns' => OPENID2_NS,
|
|
62
|
+
'ns.pape' => PAPE::NS_URI,
|
|
63
|
+
'pape.preferred_auth_policies' => [PAPE::AUTH_MULTI_FACTOR, PAPE::AUTH_PHISHING_RESISTANT].join(' '),
|
|
64
|
+
'pape.max_auth_age' => '5476'
|
|
65
|
+
})
|
|
66
|
+
oid_req = Server::OpenIDRequest.new
|
|
67
|
+
oid_req.message = openid_req_msg
|
|
68
|
+
req = PAPE::Request.from_openid_request(oid_req)
|
|
69
|
+
assert_equal([PAPE::AUTH_MULTI_FACTOR, PAPE::AUTH_PHISHING_RESISTANT], req.preferred_auth_policies)
|
|
70
|
+
assert_equal(5476, req.max_auth_age)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def test_from_openid_request_no_pape
|
|
74
|
+
message = Message.new
|
|
75
|
+
openid_req = Server::OpenIDRequest.new
|
|
76
|
+
openid_req.message = message
|
|
77
|
+
pape_req = PAPE::Request.from_openid_request(openid_req)
|
|
78
|
+
assert(pape_req.nil?)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def test_preferred_types
|
|
82
|
+
@req.add_policy_uri(PAPE::AUTH_PHISHING_RESISTANT)
|
|
83
|
+
@req.add_policy_uri(PAPE::AUTH_MULTI_FACTOR)
|
|
84
|
+
pt = @req.preferred_types([PAPE::AUTH_MULTI_FACTOR,
|
|
85
|
+
PAPE::AUTH_MULTI_FACTOR_PHYSICAL])
|
|
86
|
+
assert_equal([PAPE::AUTH_MULTI_FACTOR], pt)
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
class DummySuccessResponse
|
|
91
|
+
attr_accessor :message
|
|
92
|
+
|
|
93
|
+
def initialize(message, signed_stuff)
|
|
94
|
+
@message = message
|
|
95
|
+
@signed_stuff = signed_stuff
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def get_signed_ns(ns_uri)
|
|
99
|
+
return @signed_stuff
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
class PapeResponseTestCase < Test::Unit::TestCase
|
|
105
|
+
def setup
|
|
106
|
+
@req = PAPE::Response.new
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def test_construct
|
|
110
|
+
assert_equal([], @req.auth_policies)
|
|
111
|
+
assert_equal(nil, @req.auth_age)
|
|
112
|
+
assert_equal('pape', @req.ns_alias)
|
|
113
|
+
assert_equal(nil, @req.nist_auth_level)
|
|
114
|
+
|
|
115
|
+
req2 = PAPE::Response.new([PAPE::AUTH_MULTI_FACTOR], 1000, 3)
|
|
116
|
+
assert_equal([PAPE::AUTH_MULTI_FACTOR], req2.auth_policies)
|
|
117
|
+
assert_equal(1000, req2.auth_age)
|
|
118
|
+
assert_equal(3, req2.nist_auth_level)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def test_add_policy_uri
|
|
122
|
+
assert_equal([], @req.auth_policies)
|
|
123
|
+
@req.add_policy_uri(PAPE::AUTH_MULTI_FACTOR)
|
|
124
|
+
assert_equal([PAPE::AUTH_MULTI_FACTOR], @req.auth_policies)
|
|
125
|
+
@req.add_policy_uri(PAPE::AUTH_MULTI_FACTOR)
|
|
126
|
+
assert_equal([PAPE::AUTH_MULTI_FACTOR], @req.auth_policies)
|
|
127
|
+
@req.add_policy_uri(PAPE::AUTH_PHISHING_RESISTANT)
|
|
128
|
+
assert_equal([PAPE::AUTH_MULTI_FACTOR, PAPE::AUTH_PHISHING_RESISTANT], @req.auth_policies)
|
|
129
|
+
@req.add_policy_uri(PAPE::AUTH_MULTI_FACTOR)
|
|
130
|
+
assert_equal([PAPE::AUTH_MULTI_FACTOR, PAPE::AUTH_PHISHING_RESISTANT], @req.auth_policies)
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def test_get_extension_args
|
|
134
|
+
assert_equal({'auth_policies' => ''}, @req.get_extension_args)
|
|
135
|
+
@req.add_policy_uri('http://uri')
|
|
136
|
+
assert_equal({'auth_policies' => 'http://uri'}, @req.get_extension_args)
|
|
137
|
+
@req.add_policy_uri('http://zig')
|
|
138
|
+
assert_equal({'auth_policies' => 'http://uri http://zig'}, @req.get_extension_args)
|
|
139
|
+
@req.auth_age = 789
|
|
140
|
+
assert_equal({'auth_policies' => 'http://uri http://zig', 'auth_age' => '789'}, @req.get_extension_args)
|
|
141
|
+
@req.nist_auth_level = 3
|
|
142
|
+
assert_equal({'auth_policies' => 'http://uri http://zig', 'auth_age' => '789', 'nist_auth_level' => '3'}, @req.get_extension_args)
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def test_get_extension_args_error_auth_age
|
|
146
|
+
@req.auth_age = "older than the sun"
|
|
147
|
+
assert_raises(ArgumentError) { @req.get_extension_args }
|
|
148
|
+
@req.auth_age = -10
|
|
149
|
+
assert_raises(ArgumentError) { @req.get_extension_args }
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def test_get_extension_args_error_nist_auth_level
|
|
153
|
+
@req.nist_auth_level = "high as a kite"
|
|
154
|
+
assert_raises(ArgumentError) { @req.get_extension_args }
|
|
155
|
+
@req.nist_auth_level = 5
|
|
156
|
+
assert_raises(ArgumentError) { @req.get_extension_args }
|
|
157
|
+
@req.nist_auth_level = -1
|
|
158
|
+
assert_raises(ArgumentError) { @req.get_extension_args }
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def test_parse_extension_args
|
|
162
|
+
args = {'auth_policies' => 'http://foo http://bar',
|
|
163
|
+
'auth_age' => '9'}
|
|
164
|
+
@req.parse_extension_args(args)
|
|
165
|
+
assert_equal(9, @req.auth_age)
|
|
166
|
+
assert_equal(['http://foo','http://bar'], @req.auth_policies)
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def test_parse_extension_args_empty
|
|
170
|
+
@req.parse_extension_args({})
|
|
171
|
+
assert_equal(nil, @req.auth_age)
|
|
172
|
+
assert_equal([], @req.auth_policies)
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def test_parse_extension_args_strict_bogus1
|
|
176
|
+
args = {'auth_policies' => 'http://foo http://bar',
|
|
177
|
+
'auth_age' => 'not too old'}
|
|
178
|
+
assert_raises(ArgumentError) {
|
|
179
|
+
@req.parse_extension_args(args, true)
|
|
180
|
+
}
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def test_parse_extension_args_strict_bogus2
|
|
184
|
+
args = {'auth_policies' => 'http://foo http://bar',
|
|
185
|
+
'auth_age' => '63',
|
|
186
|
+
'nist_auth_level' => 'some'}
|
|
187
|
+
assert_raises(ArgumentError) {
|
|
188
|
+
@req.parse_extension_args(args, true)
|
|
189
|
+
}
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
def test_parse_extension_args_strict_good
|
|
193
|
+
args = {'auth_policies' => 'http://foo http://bar',
|
|
194
|
+
'auth_age' => '0',
|
|
195
|
+
'nist_auth_level' => '0'}
|
|
196
|
+
@req.parse_extension_args(args, true)
|
|
197
|
+
assert_equal(['http://foo','http://bar'], @req.auth_policies)
|
|
198
|
+
assert_equal(0, @req.auth_age)
|
|
199
|
+
assert_equal(0, @req.nist_auth_level)
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
def test_parse_extension_args_nostrict_bogus
|
|
203
|
+
args = {'auth_policies' => 'http://foo http://bar',
|
|
204
|
+
'auth_age' => 'old',
|
|
205
|
+
'nist_auth_level' => 'some'}
|
|
206
|
+
@req.parse_extension_args(args)
|
|
207
|
+
assert_equal(['http://foo','http://bar'], @req.auth_policies)
|
|
208
|
+
assert_equal(nil, @req.auth_age)
|
|
209
|
+
assert_equal(nil, @req.nist_auth_level)
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def test_from_success_response
|
|
214
|
+
|
|
215
|
+
openid_req_msg = Message.from_openid_args({
|
|
216
|
+
'mode' => 'id_res',
|
|
217
|
+
'ns' => OPENID2_NS,
|
|
218
|
+
'ns.pape' => PAPE::NS_URI,
|
|
219
|
+
'pape.auth_policies' => [PAPE::AUTH_MULTI_FACTOR, PAPE::AUTH_PHISHING_RESISTANT].join(' '),
|
|
220
|
+
'pape.auth_age' => '5476'
|
|
221
|
+
})
|
|
222
|
+
signed_stuff = {
|
|
223
|
+
'auth_policies' => [PAPE::AUTH_MULTI_FACTOR, PAPE::AUTH_PHISHING_RESISTANT].join(' '),
|
|
224
|
+
'auth_age' => '5476'
|
|
225
|
+
}
|
|
226
|
+
oid_req = DummySuccessResponse.new(openid_req_msg, signed_stuff)
|
|
227
|
+
req = PAPE::Response.from_success_response(oid_req)
|
|
228
|
+
assert_equal([PAPE::AUTH_MULTI_FACTOR, PAPE::AUTH_PHISHING_RESISTANT], req.auth_policies)
|
|
229
|
+
assert_equal(5476, req.auth_age)
|
|
230
|
+
end
|
|
231
|
+
end
|
|
232
|
+
end
|
|
233
|
+
end
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
require 'test/unit'
|
|
2
|
+
require "openid/yadis/parsehtml"
|
|
3
|
+
require "testutil"
|
|
4
|
+
|
|
5
|
+
module OpenID
|
|
6
|
+
class ParseHTMLTestCase < Test::Unit::TestCase
|
|
7
|
+
include OpenID::TestDataMixin
|
|
8
|
+
|
|
9
|
+
def test_parsehtml
|
|
10
|
+
reserved_values = ['None', 'EOF']
|
|
11
|
+
chunks = read_data_file('test1-parsehtml.txt', false).split("\f\n")
|
|
12
|
+
test_num = 1
|
|
13
|
+
|
|
14
|
+
chunks.each{|c|
|
|
15
|
+
expected, html = c.split("\n", 2)
|
|
16
|
+
found = Yadis::html_yadis_location(html)
|
|
17
|
+
|
|
18
|
+
assert(!reserved_values.member?(found))
|
|
19
|
+
|
|
20
|
+
# this case is a little hard to detect and the distinction
|
|
21
|
+
# seems unimportant
|
|
22
|
+
expected = "None" if expected == "EOF"
|
|
23
|
+
|
|
24
|
+
found = "None" if found.nil?
|
|
25
|
+
assert_equal(expected, found, html.split("\n",2)[0])
|
|
26
|
+
}
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# the HTML tokenizer test
|
|
31
|
+
class TC_TestHTMLTokenizer < Test::Unit::TestCase
|
|
32
|
+
def test_bad_link
|
|
33
|
+
toke = HTMLTokenizer.new("<p><a href=http://bad.com/link>foo</a></p>")
|
|
34
|
+
assert("http://bad.com/link" == toke.getTag("a").attr_hash['href'])
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_namespace
|
|
38
|
+
toke = HTMLTokenizer.new("<f:table xmlns:f=\"http://www.com/foo\">")
|
|
39
|
+
assert("http://www.com/foo" == toke.getTag("f:table").attr_hash['xmlns:f'])
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_comment
|
|
43
|
+
toke = HTMLTokenizer.new("<!-- comment on me -->")
|
|
44
|
+
t = toke.getNextToken
|
|
45
|
+
assert(HTMLComment == t.class)
|
|
46
|
+
assert("comment on me" == t.contents)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def test_full
|
|
50
|
+
page = "<HTML>
|
|
51
|
+
<HEAD>
|
|
52
|
+
<TITLE>This is the title</TITLE>
|
|
53
|
+
</HEAD>
|
|
54
|
+
<!-- Here comes the <a href=\"missing.link\">blah</a>
|
|
55
|
+
comment body
|
|
56
|
+
-->
|
|
57
|
+
<BODY>
|
|
58
|
+
<H1>This is the header</H1>
|
|
59
|
+
<P>
|
|
60
|
+
This is the paragraph, it contains
|
|
61
|
+
<a href=\"link.html\">links</a>,
|
|
62
|
+
<img src=\"blah.gif\" optional alt='images
|
|
63
|
+
are
|
|
64
|
+
really cool'>. Ok, here is some more text and
|
|
65
|
+
<A href=\"http://another.link.com/\" target=\"_blank\">another link</A>.
|
|
66
|
+
</P>
|
|
67
|
+
</body>
|
|
68
|
+
</HTML>
|
|
69
|
+
"
|
|
70
|
+
toke = HTMLTokenizer.new(page)
|
|
71
|
+
|
|
72
|
+
assert("<h1>" == toke.getTag("h1", "h2", "h3").to_s.downcase)
|
|
73
|
+
assert(HTMLTag.new("<a href=\"link.html\">") == toke.getTag("IMG", "A"))
|
|
74
|
+
assert("links" == toke.getTrimmedText)
|
|
75
|
+
assert(toke.getTag("IMG", "A").attr_hash['optional'])
|
|
76
|
+
assert("_blank" == toke.getTag("IMG", "A").attr_hash['target'])
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
require "test/unit"
|
|
2
|
+
require "openid/consumer/discovery"
|
|
3
|
+
require "openid/consumer/responses"
|
|
4
|
+
|
|
5
|
+
module OpenID
|
|
6
|
+
class Consumer
|
|
7
|
+
module TestResponses
|
|
8
|
+
class TestSuccessResponse < Test::Unit::TestCase
|
|
9
|
+
def setup
|
|
10
|
+
@endpoint = OpenIDServiceEndpoint.new
|
|
11
|
+
@endpoint.claimed_id = 'identity_url'
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def test_extension_response
|
|
15
|
+
q = {
|
|
16
|
+
'ns.sreg' => 'urn:sreg',
|
|
17
|
+
'ns.unittest' => 'urn:unittest',
|
|
18
|
+
'unittest.one' => '1',
|
|
19
|
+
'unittest.two' => '2',
|
|
20
|
+
'sreg.nickname' => 'j3h',
|
|
21
|
+
'return_to' => 'return_to',
|
|
22
|
+
}
|
|
23
|
+
signed_list = q.keys.map { |k| 'openid.' + k }
|
|
24
|
+
msg = Message.from_openid_args(q)
|
|
25
|
+
resp = SuccessResponse.new(@endpoint, msg, signed_list)
|
|
26
|
+
utargs = resp.extension_response('urn:unittest', false)
|
|
27
|
+
assert_equal(utargs, {'one' => '1', 'two' => '2'})
|
|
28
|
+
sregargs = resp.extension_response('urn:sreg', false)
|
|
29
|
+
assert_equal(sregargs, {'nickname' => 'j3h'})
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def test_extension_response_signed
|
|
33
|
+
args = {
|
|
34
|
+
'ns.sreg' => 'urn:sreg',
|
|
35
|
+
'ns.unittest' => 'urn:unittest',
|
|
36
|
+
'unittest.one' => '1',
|
|
37
|
+
'unittest.two' => '2',
|
|
38
|
+
'sreg.nickname' => 'j3h',
|
|
39
|
+
'sreg.dob' => 'yesterday',
|
|
40
|
+
'return_to' => 'return_to',
|
|
41
|
+
'signed' => 'sreg.nickname,unittest.one,sreg.dob',
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
signed_list = ['openid.sreg.nickname',
|
|
45
|
+
'openid.unittest.one',
|
|
46
|
+
'openid.sreg.dob',]
|
|
47
|
+
|
|
48
|
+
msg = Message.from_openid_args(args)
|
|
49
|
+
resp = SuccessResponse.new(@endpoint, msg, signed_list)
|
|
50
|
+
|
|
51
|
+
# All args in this NS are signed, so expect all.
|
|
52
|
+
sregargs = resp.extension_response('urn:sreg', true)
|
|
53
|
+
assert_equal(sregargs, {'nickname' => 'j3h', 'dob' => 'yesterday'})
|
|
54
|
+
|
|
55
|
+
# Not all args in this NS are signed, so expect nil when
|
|
56
|
+
# asking for them.
|
|
57
|
+
utargs = resp.extension_response('urn:unittest', true)
|
|
58
|
+
assert_equal(nil, utargs)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|