entp-ruby-openid 2.2
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/INSTALL +47 -0
- data/LICENSE +210 -0
- data/NOTICE +2 -0
- data/README +85 -0
- data/UPGRADE +127 -0
- data/admin/runtests.rb +45 -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 +125 -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/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 +22 -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 +150 -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/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 +12 -0
- data/lib/openid/server.rb +1544 -0
- data/lib/openid/store.rb +10 -0
- data/lib/openid/store/filesystem.rb +272 -0
- data/lib/openid/store/interface.rb +75 -0
- data/lib/openid/store/memcache.rb +109 -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 +119 -0
- data/lib/openid/version.rb +3 -0
- data/lib/openid/yadis.rb +15 -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 +91 -0
- data/test/data/test_discover/openid_utf8.html +11 -0
- data/test/support/test_data_mixin.rb +127 -0
- data/test/support/test_util.rb +53 -0
- data/test/support/yadis_data.rb +131 -0
- data/test/support/yadis_data/accept.txt +124 -0
- data/test/support/yadis_data/dh.txt +29 -0
- data/test/support/yadis_data/example-xrds.xml +14 -0
- data/test/support/yadis_data/linkparse.txt +587 -0
- data/test/support/yadis_data/n2b64 +650 -0
- data/test/support/yadis_data/test1-discover.txt +137 -0
- data/test/support/yadis_data/test1-parsehtml.txt +152 -0
- data/test/support/yadis_data/test_discover/malformed_meta_tag.html +19 -0
- data/test/support/yadis_data/test_discover/openid.html +11 -0
- data/test/support/yadis_data/test_discover/openid2.html +11 -0
- data/test/support/yadis_data/test_discover/openid2_xrds.xml +12 -0
- data/test/support/yadis_data/test_discover/openid2_xrds_no_local_id.xml +11 -0
- data/test/support/yadis_data/test_discover/openid_1_and_2.html +11 -0
- data/test/support/yadis_data/test_discover/openid_1_and_2_xrds.xml +16 -0
- data/test/support/yadis_data/test_discover/openid_1_and_2_xrds_bad_delegate.xml +17 -0
- data/test/support/yadis_data/test_discover/openid_and_yadis.html +12 -0
- data/test/support/yadis_data/test_discover/openid_no_delegate.html +10 -0
- data/test/support/yadis_data/test_discover/openid_utf8.html +11 -0
- data/test/support/yadis_data/test_discover/yadis_0entries.xml +12 -0
- data/test/support/yadis_data/test_discover/yadis_2_bad_local_id.xml +15 -0
- data/test/support/yadis_data/test_discover/yadis_2entries_delegate.xml +22 -0
- data/test/support/yadis_data/test_discover/yadis_2entries_idp.xml +21 -0
- data/test/support/yadis_data/test_discover/yadis_another_delegate.xml +14 -0
- data/test/support/yadis_data/test_discover/yadis_idp.xml +12 -0
- data/test/support/yadis_data/test_discover/yadis_idp_delegate.xml +13 -0
- data/test/support/yadis_data/test_discover/yadis_no_delegate.xml +11 -0
- data/test/support/yadis_data/test_xrds/=j3h.2007.11.14.xrds +25 -0
- data/test/support/yadis_data/test_xrds/README +12 -0
- data/test/support/yadis_data/test_xrds/delegated-20060809-r1.xrds +34 -0
- data/test/support/yadis_data/test_xrds/delegated-20060809-r2.xrds +34 -0
- data/test/support/yadis_data/test_xrds/delegated-20060809.xrds +34 -0
- data/test/support/yadis_data/test_xrds/no-xrd.xml +7 -0
- data/test/support/yadis_data/test_xrds/not-xrds.xml +2 -0
- data/test/support/yadis_data/test_xrds/prefixsometimes.xrds +34 -0
- data/test/support/yadis_data/test_xrds/ref.xrds +109 -0
- data/test/support/yadis_data/test_xrds/sometimesprefix.xrds +34 -0
- data/test/support/yadis_data/test_xrds/spoof1.xrds +25 -0
- data/test/support/yadis_data/test_xrds/spoof2.xrds +25 -0
- data/test/support/yadis_data/test_xrds/spoof3.xrds +37 -0
- data/test/support/yadis_data/test_xrds/status222.xrds +9 -0
- data/test/support/yadis_data/test_xrds/subsegments.xrds +58 -0
- data/test/support/yadis_data/test_xrds/valid-populated-xrds.xml +39 -0
- data/test/support/yadis_data/trustroot.txt +153 -0
- data/test/support/yadis_data/urinorm.txt +79 -0
- data/test/test_accept.rb +170 -0
- data/test/test_association.rb +268 -0
- data/test/test_associationmanager.rb +918 -0
- data/test/test_ax.rb +690 -0
- data/test/test_checkid_request.rb +293 -0
- data/test/test_consumer.rb +260 -0
- data/test/test_cryptutil.rb +119 -0
- data/test/test_dh.rb +85 -0
- data/test/test_discover.rb +848 -0
- data/test/test_discovery_manager.rb +259 -0
- data/test/test_extension.rb +46 -0
- data/test/test_extras.rb +35 -0
- data/test/test_fetchers.rb +554 -0
- data/test/test_filters.rb +269 -0
- data/test/test_helper.rb +4 -0
- data/test/test_idres.rb +961 -0
- data/test/test_kvform.rb +164 -0
- data/test/test_kvpost.rb +64 -0
- data/test/test_linkparse.rb +100 -0
- data/test/test_message.rb +1115 -0
- data/test/test_nonce.rb +89 -0
- data/test/test_oauth.rb +176 -0
- data/test/test_openid_yadis.rb +177 -0
- data/test/test_pape.rb +248 -0
- data/test/test_parsehtml.rb +79 -0
- data/test/test_responses.rb +63 -0
- data/test/test_server.rb +2455 -0
- data/test/test_sreg.rb +479 -0
- data/test/test_stores.rb +292 -0
- data/test/test_trustroot.rb +111 -0
- data/test/test_urinorm.rb +34 -0
- data/test/test_util.rb +145 -0
- data/test/test_xrds.rb +167 -0
- data/test/test_xri.rb +48 -0
- data/test/test_xrires.rb +67 -0
- data/test/test_yadis_discovery.rb +218 -0
- metadata +268 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
|
2
|
+
require 'test/unit'
|
|
3
|
+
RAILS_ENV = "test"
|
|
4
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../../../../config/environment.rb'))
|
|
5
|
+
|
|
6
|
+
module StoreTestCase
|
|
7
|
+
@@allowed_handle = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
|
|
8
|
+
@@allowed_nonce = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
9
|
+
|
|
10
|
+
def _gen_nonce
|
|
11
|
+
OpenID::CryptUtil.random_string(8, @@allowed_nonce)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def _gen_handle(n)
|
|
15
|
+
OpenID::CryptUtil.random_string(n, @@allowed_handle)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def _gen_secret(n, chars=nil)
|
|
19
|
+
OpenID::CryptUtil.random_string(n, chars)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def _gen_assoc(issued, lifetime=600)
|
|
23
|
+
secret = _gen_secret(20)
|
|
24
|
+
handle = _gen_handle(128)
|
|
25
|
+
OpenID::Association.new(handle, secret, Time.now + issued, lifetime,
|
|
26
|
+
'HMAC-SHA1')
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def _check_retrieve(url, handle=nil, expected=nil)
|
|
30
|
+
ret_assoc = @store.get_association(url, handle)
|
|
31
|
+
|
|
32
|
+
if expected.nil?
|
|
33
|
+
assert_nil(ret_assoc)
|
|
34
|
+
else
|
|
35
|
+
assert_equal(expected, ret_assoc)
|
|
36
|
+
assert_equal(expected.handle, ret_assoc.handle)
|
|
37
|
+
assert_equal(expected.secret, ret_assoc.secret)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def _check_remove(url, handle, expected)
|
|
42
|
+
present = @store.remove_association(url, handle)
|
|
43
|
+
assert_equal(expected, present)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def test_store
|
|
47
|
+
server_url = "http://www.myopenid.com/openid"
|
|
48
|
+
assoc = _gen_assoc(issued=0)
|
|
49
|
+
|
|
50
|
+
# Make sure that a missing association returns no result
|
|
51
|
+
_check_retrieve(server_url)
|
|
52
|
+
|
|
53
|
+
# Check that after storage, getting returns the same result
|
|
54
|
+
@store.store_association(server_url, assoc)
|
|
55
|
+
_check_retrieve(server_url, nil, assoc)
|
|
56
|
+
|
|
57
|
+
# more than once
|
|
58
|
+
_check_retrieve(server_url, nil, assoc)
|
|
59
|
+
|
|
60
|
+
# Storing more than once has no ill effect
|
|
61
|
+
@store.store_association(server_url, assoc)
|
|
62
|
+
_check_retrieve(server_url, nil, assoc)
|
|
63
|
+
|
|
64
|
+
# Removing an association that does not exist returns not present
|
|
65
|
+
_check_remove(server_url, assoc.handle + 'x', false)
|
|
66
|
+
|
|
67
|
+
# Removing an association that does not exist returns not present
|
|
68
|
+
_check_remove(server_url + 'x', assoc.handle, false)
|
|
69
|
+
|
|
70
|
+
# Removing an association that is present returns present
|
|
71
|
+
_check_remove(server_url, assoc.handle, true)
|
|
72
|
+
|
|
73
|
+
# but not present on subsequent calls
|
|
74
|
+
_check_remove(server_url, assoc.handle, false)
|
|
75
|
+
|
|
76
|
+
# Put assoc back in the store
|
|
77
|
+
@store.store_association(server_url, assoc)
|
|
78
|
+
|
|
79
|
+
# More recent and expires after assoc
|
|
80
|
+
assoc2 = _gen_assoc(issued=1)
|
|
81
|
+
@store.store_association(server_url, assoc2)
|
|
82
|
+
|
|
83
|
+
# After storing an association with a different handle, but the
|
|
84
|
+
# same server_url, the handle with the later expiration is returned.
|
|
85
|
+
_check_retrieve(server_url, nil, assoc2)
|
|
86
|
+
|
|
87
|
+
# We can still retrieve the older association
|
|
88
|
+
_check_retrieve(server_url, assoc.handle, assoc)
|
|
89
|
+
|
|
90
|
+
# Plus we can retrieve the association with the later expiration
|
|
91
|
+
# explicitly
|
|
92
|
+
_check_retrieve(server_url, assoc2.handle, assoc2)
|
|
93
|
+
|
|
94
|
+
# More recent, and expires earlier than assoc2 or assoc. Make sure
|
|
95
|
+
# that we're picking the one with the latest issued date and not
|
|
96
|
+
# taking into account the expiration.
|
|
97
|
+
assoc3 = _gen_assoc(issued=2, lifetime=100)
|
|
98
|
+
@store.store_association(server_url, assoc3)
|
|
99
|
+
|
|
100
|
+
_check_retrieve(server_url, nil, assoc3)
|
|
101
|
+
_check_retrieve(server_url, assoc.handle, assoc)
|
|
102
|
+
_check_retrieve(server_url, assoc2.handle, assoc2)
|
|
103
|
+
_check_retrieve(server_url, assoc3.handle, assoc3)
|
|
104
|
+
|
|
105
|
+
_check_remove(server_url, assoc2.handle, true)
|
|
106
|
+
|
|
107
|
+
_check_retrieve(server_url, nil, assoc3)
|
|
108
|
+
_check_retrieve(server_url, assoc.handle, assoc)
|
|
109
|
+
_check_retrieve(server_url, assoc2.handle, nil)
|
|
110
|
+
_check_retrieve(server_url, assoc3.handle, assoc3)
|
|
111
|
+
|
|
112
|
+
_check_remove(server_url, assoc2.handle, false)
|
|
113
|
+
_check_remove(server_url, assoc3.handle, true)
|
|
114
|
+
|
|
115
|
+
_check_retrieve(server_url, nil, assoc)
|
|
116
|
+
_check_retrieve(server_url, assoc.handle, assoc)
|
|
117
|
+
_check_retrieve(server_url, assoc2.handle, nil)
|
|
118
|
+
_check_retrieve(server_url, assoc3.handle, nil)
|
|
119
|
+
|
|
120
|
+
_check_remove(server_url, assoc2.handle, false)
|
|
121
|
+
_check_remove(server_url, assoc.handle, true)
|
|
122
|
+
_check_remove(server_url, assoc3.handle, false)
|
|
123
|
+
|
|
124
|
+
_check_retrieve(server_url, nil, nil)
|
|
125
|
+
_check_retrieve(server_url, assoc.handle, nil)
|
|
126
|
+
_check_retrieve(server_url, assoc2.handle, nil)
|
|
127
|
+
_check_retrieve(server_url, assoc3.handle, nil)
|
|
128
|
+
|
|
129
|
+
_check_remove(server_url, assoc2.handle, false)
|
|
130
|
+
_check_remove(server_url, assoc.handle, false)
|
|
131
|
+
_check_remove(server_url, assoc3.handle, false)
|
|
132
|
+
|
|
133
|
+
assocValid1 = _gen_assoc(-3600, 7200)
|
|
134
|
+
assocValid2 = _gen_assoc(-5)
|
|
135
|
+
assocExpired1 = _gen_assoc(-7200, 3600)
|
|
136
|
+
assocExpired2 = _gen_assoc(-7200, 3600)
|
|
137
|
+
|
|
138
|
+
@store.cleanup_associations
|
|
139
|
+
@store.store_association(server_url + '1', assocValid1)
|
|
140
|
+
@store.store_association(server_url + '1', assocExpired1)
|
|
141
|
+
@store.store_association(server_url + '2', assocExpired2)
|
|
142
|
+
@store.store_association(server_url + '3', assocValid2)
|
|
143
|
+
|
|
144
|
+
cleaned = @store.cleanup_associations()
|
|
145
|
+
assert_equal(2, cleaned, "cleaned up associations")
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def _check_use_nonce(nonce, expected, server_url, msg='')
|
|
149
|
+
stamp, salt = OpenID::Nonce::split_nonce(nonce)
|
|
150
|
+
actual = @store.use_nonce(server_url, stamp, salt)
|
|
151
|
+
assert_equal(expected, actual, msg)
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def test_nonce
|
|
155
|
+
server_url = "http://www.myopenid.com/openid"
|
|
156
|
+
[server_url, ''].each{|url|
|
|
157
|
+
nonce1 = OpenID::Nonce::mk_nonce
|
|
158
|
+
|
|
159
|
+
_check_use_nonce(nonce1, true, url, "#{url}: nonce allowed by default")
|
|
160
|
+
_check_use_nonce(nonce1, false, url, "#{url}: nonce not allowed twice")
|
|
161
|
+
_check_use_nonce(nonce1, false, url, "#{url}: nonce not allowed third time")
|
|
162
|
+
|
|
163
|
+
# old nonces shouldn't pass
|
|
164
|
+
old_nonce = OpenID::Nonce::mk_nonce(3600)
|
|
165
|
+
_check_use_nonce(old_nonce, false, url, "Old nonce #{old_nonce.inspect} passed")
|
|
166
|
+
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
now = Time.now.to_i
|
|
170
|
+
old_nonce1 = OpenID::Nonce::mk_nonce(now - 20000)
|
|
171
|
+
old_nonce2 = OpenID::Nonce::mk_nonce(now - 10000)
|
|
172
|
+
recent_nonce = OpenID::Nonce::mk_nonce(now - 600)
|
|
173
|
+
|
|
174
|
+
orig_skew = OpenID::Nonce.skew
|
|
175
|
+
OpenID::Nonce.skew = 0
|
|
176
|
+
count = @store.cleanup_nonces
|
|
177
|
+
OpenID::Nonce.skew = 1000000
|
|
178
|
+
ts, salt = OpenID::Nonce::split_nonce(old_nonce1)
|
|
179
|
+
assert(@store.use_nonce(server_url, ts, salt), "oldnonce1")
|
|
180
|
+
ts, salt = OpenID::Nonce::split_nonce(old_nonce2)
|
|
181
|
+
assert(@store.use_nonce(server_url, ts, salt), "oldnonce2")
|
|
182
|
+
ts, salt = OpenID::Nonce::split_nonce(recent_nonce)
|
|
183
|
+
assert(@store.use_nonce(server_url, ts, salt), "recent_nonce")
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
OpenID::Nonce.skew = 1000
|
|
187
|
+
cleaned = @store.cleanup_nonces
|
|
188
|
+
assert_equal(2, cleaned, "Cleaned #{cleaned} nonces")
|
|
189
|
+
|
|
190
|
+
OpenID::Nonce.skew = 100000
|
|
191
|
+
ts, salt = OpenID::Nonce::split_nonce(old_nonce1)
|
|
192
|
+
assert(@store.use_nonce(server_url, ts, salt), "oldnonce1 after cleanup")
|
|
193
|
+
ts, salt = OpenID::Nonce::split_nonce(old_nonce2)
|
|
194
|
+
assert(@store.use_nonce(server_url, ts, salt), "oldnonce2 after cleanup")
|
|
195
|
+
ts, salt = OpenID::Nonce::split_nonce(recent_nonce)
|
|
196
|
+
assert(!@store.use_nonce(server_url, ts, salt), "recent_nonce after cleanup")
|
|
197
|
+
|
|
198
|
+
OpenID::Nonce.skew = orig_skew
|
|
199
|
+
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
class TestARStore < Test::Unit::TestCase
|
|
205
|
+
include StoreTestCase
|
|
206
|
+
|
|
207
|
+
def setup
|
|
208
|
+
@store = ActiveRecordStore.new
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
end
|
|
212
|
+
|
data/examples/discover
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
require "openid/consumer/discovery"
|
|
3
|
+
require 'openid/fetchers'
|
|
4
|
+
|
|
5
|
+
OpenID::fetcher_use_env_http_proxy
|
|
6
|
+
|
|
7
|
+
$names = [[:server_url, "Server URL "],
|
|
8
|
+
[:local_id, "Local ID "],
|
|
9
|
+
[:canonical_id, "Canonical ID"],
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
def show_services(user_input, normalized, services)
|
|
13
|
+
puts " Claimed identifier: #{normalized}"
|
|
14
|
+
if services.empty?
|
|
15
|
+
puts " No OpenID services found"
|
|
16
|
+
puts
|
|
17
|
+
else
|
|
18
|
+
puts " Discovered services:"
|
|
19
|
+
n = 0
|
|
20
|
+
services.each do |service|
|
|
21
|
+
n += 1
|
|
22
|
+
puts " #{n}."
|
|
23
|
+
$names.each do |meth, name|
|
|
24
|
+
val = service.send(meth)
|
|
25
|
+
if val
|
|
26
|
+
printf(" %s: %s\n", name, val)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
puts " Type URIs:"
|
|
30
|
+
for type_uri in service.type_uris
|
|
31
|
+
puts " * #{type_uri}"
|
|
32
|
+
end
|
|
33
|
+
puts
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
ARGV.each do |openid_identifier|
|
|
39
|
+
puts "=" * 50
|
|
40
|
+
puts "Running discovery on #{openid_identifier}"
|
|
41
|
+
begin
|
|
42
|
+
normalized_identifier, services = OpenID.discover(openid_identifier)
|
|
43
|
+
rescue OpenID::DiscoveryFailure => why
|
|
44
|
+
puts "Discovery failed: #{why.message}"
|
|
45
|
+
puts
|
|
46
|
+
else
|
|
47
|
+
show_services(openid_identifier, normalized_identifier, services)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
== Welcome to Rails
|
|
2
|
+
|
|
3
|
+
Rails is a web-application and persistence framework that includes everything
|
|
4
|
+
needed to create database-backed web-applications according to the
|
|
5
|
+
Model-View-Control pattern of separation. This pattern splits the view (also
|
|
6
|
+
called the presentation) into "dumb" templates that are primarily responsible
|
|
7
|
+
for inserting pre-built data in between HTML tags. The model contains the
|
|
8
|
+
"smart" domain objects (such as Account, Product, Person, Post) that holds all
|
|
9
|
+
the business logic and knows how to persist themselves to a database. The
|
|
10
|
+
controller handles the incoming requests (such as Save New Account, Update
|
|
11
|
+
Product, Show Post) by manipulating the model and directing data to the view.
|
|
12
|
+
|
|
13
|
+
In Rails, the model is handled by what's called an object-relational mapping
|
|
14
|
+
layer entitled Active Record. This layer allows you to present the data from
|
|
15
|
+
database rows as objects and embellish these data objects with business logic
|
|
16
|
+
methods. You can read more about Active Record in
|
|
17
|
+
link:files/vendor/rails/activerecord/README.html.
|
|
18
|
+
|
|
19
|
+
The controller and view are handled by the Action Pack, which handles both
|
|
20
|
+
layers by its two parts: Action View and Action Controller. These two layers
|
|
21
|
+
are bundled in a single package due to their heavy interdependence. This is
|
|
22
|
+
unlike the relationship between the Active Record and Action Pack that is much
|
|
23
|
+
more separate. Each of these packages can be used independently outside of
|
|
24
|
+
Rails. You can read more about Action Pack in
|
|
25
|
+
link:files/vendor/rails/actionpack/README.html.
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
== Getting started
|
|
29
|
+
|
|
30
|
+
1. Run the WEBrick servlet: <tt>ruby script/server</tt> (run with --help for options)
|
|
31
|
+
...or if you have lighttpd installed: <tt>ruby script/lighttpd</tt> (it's faster)
|
|
32
|
+
2. Go to http://localhost:3000/ and get "Congratulations, you've put Ruby on Rails!"
|
|
33
|
+
3. Follow the guidelines on the "Congratulations, you've put Ruby on Rails!" screen
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
== Example for Apache conf
|
|
37
|
+
|
|
38
|
+
<VirtualHost *:80>
|
|
39
|
+
ServerName rails
|
|
40
|
+
DocumentRoot /path/application/public/
|
|
41
|
+
ErrorLog /path/application/log/server.log
|
|
42
|
+
|
|
43
|
+
<Directory /path/application/public/>
|
|
44
|
+
Options ExecCGI FollowSymLinks
|
|
45
|
+
AllowOverride all
|
|
46
|
+
Allow from all
|
|
47
|
+
Order allow,deny
|
|
48
|
+
</Directory>
|
|
49
|
+
</VirtualHost>
|
|
50
|
+
|
|
51
|
+
NOTE: Be sure that CGIs can be executed in that directory as well. So ExecCGI
|
|
52
|
+
should be on and ".cgi" should respond. All requests from 127.0.0.1 go
|
|
53
|
+
through CGI, so no Apache restart is necessary for changes. All other requests
|
|
54
|
+
go through FCGI (or mod_ruby), which requires a restart to show changes.
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
== Debugging Rails
|
|
58
|
+
|
|
59
|
+
Have "tail -f" commands running on both the server.log, production.log, and
|
|
60
|
+
test.log files. Rails will automatically display debugging and runtime
|
|
61
|
+
information to these files. Debugging info will also be shown in the browser
|
|
62
|
+
on requests from 127.0.0.1.
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
== Breakpoints
|
|
66
|
+
|
|
67
|
+
Breakpoint support is available through the script/breakpointer client. This
|
|
68
|
+
means that you can break out of execution at any point in the code, investigate
|
|
69
|
+
and change the model, AND then resume execution! Example:
|
|
70
|
+
|
|
71
|
+
class WeblogController < ActionController::Base
|
|
72
|
+
def index
|
|
73
|
+
@posts = Post.find_all
|
|
74
|
+
breakpoint "Breaking out from the list"
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
So the controller will accept the action, run the first line, then present you
|
|
79
|
+
with a IRB prompt in the breakpointer window. Here you can do things like:
|
|
80
|
+
|
|
81
|
+
Executing breakpoint "Breaking out from the list" at .../webrick_server.rb:16 in 'breakpoint'
|
|
82
|
+
|
|
83
|
+
>> @posts.inspect
|
|
84
|
+
=> "[#<Post:0x14a6be8 @attributes={\"title\"=>nil, \"body\"=>nil, \"id\"=>\"1\"}>,
|
|
85
|
+
#<Post:0x14a6620 @attributes={\"title\"=>\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]"
|
|
86
|
+
>> @posts.first.title = "hello from a breakpoint"
|
|
87
|
+
=> "hello from a breakpoint"
|
|
88
|
+
|
|
89
|
+
...and even better is that you can examine how your runtime objects actually work:
|
|
90
|
+
|
|
91
|
+
>> f = @posts.first
|
|
92
|
+
=> #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
|
|
93
|
+
>> f.
|
|
94
|
+
Display all 152 possibilities? (y or n)
|
|
95
|
+
|
|
96
|
+
Finally, when you're ready to resume execution, you press CTRL-D
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
== Console
|
|
100
|
+
|
|
101
|
+
You can interact with the domain model by starting the console through script/console.
|
|
102
|
+
Here you'll have all parts of the application configured, just like it is when the
|
|
103
|
+
application is running. You can inspect domain models, change values, and save to the
|
|
104
|
+
database. Starting the script without arguments will launch it in the development environment.
|
|
105
|
+
Passing an argument will specify a different environment, like <tt>console production</tt>.
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
== Description of contents
|
|
109
|
+
|
|
110
|
+
app
|
|
111
|
+
Holds all the code that's specific to this particular application.
|
|
112
|
+
|
|
113
|
+
app/controllers
|
|
114
|
+
Holds controllers that should be named like weblog_controller.rb for
|
|
115
|
+
automated URL mapping. All controllers should descend from
|
|
116
|
+
ActionController::Base.
|
|
117
|
+
|
|
118
|
+
app/models
|
|
119
|
+
Holds models that should be named like post.rb.
|
|
120
|
+
Most models will descend from ActiveRecord::Base.
|
|
121
|
+
|
|
122
|
+
app/views
|
|
123
|
+
Holds the template files for the view that should be named like
|
|
124
|
+
weblog/index.rhtml for the WeblogController#index action. All views use eRuby
|
|
125
|
+
syntax. This directory can also be used to keep stylesheets, images, and so on
|
|
126
|
+
that can be symlinked to public.
|
|
127
|
+
|
|
128
|
+
app/helpers
|
|
129
|
+
Holds view helpers that should be named like weblog_helper.rb.
|
|
130
|
+
|
|
131
|
+
config
|
|
132
|
+
Configuration files for the Rails environment, the routing map, the database, and other dependencies.
|
|
133
|
+
|
|
134
|
+
components
|
|
135
|
+
Self-contained mini-applications that can bundle together controllers, models, and views.
|
|
136
|
+
|
|
137
|
+
lib
|
|
138
|
+
Application specific libraries. Basically, any kind of custom code that doesn't
|
|
139
|
+
belong under controllers, models, or helpers. This directory is in the load path.
|
|
140
|
+
|
|
141
|
+
public
|
|
142
|
+
The directory available for the web server. Contains subdirectories for images, stylesheets,
|
|
143
|
+
and javascripts. Also contains the dispatchers and the default HTML files.
|
|
144
|
+
|
|
145
|
+
script
|
|
146
|
+
Helper scripts for automation and generation.
|
|
147
|
+
|
|
148
|
+
test
|
|
149
|
+
Unit and functional tests along with fixtures.
|
|
150
|
+
|
|
151
|
+
vendor
|
|
152
|
+
External libraries that the application depends on. Also includes the plugins subdirectory.
|
|
153
|
+
This directory is in the load path.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
|
2
|
+
# for example lib/tasks/switchtower.rake, and they will automatically be available to Rake.
|
|
3
|
+
|
|
4
|
+
require(File.join(File.dirname(__FILE__), 'config', 'boot'))
|
|
5
|
+
|
|
6
|
+
require 'rake'
|
|
7
|
+
require 'rake/testtask'
|
|
8
|
+
require 'rake/rdoctask'
|
|
9
|
+
|
|
10
|
+
require 'tasks/rails'
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
require 'pathname'
|
|
2
|
+
|
|
3
|
+
require "openid"
|
|
4
|
+
require 'openid/extensions/sreg'
|
|
5
|
+
require 'openid/extensions/pape'
|
|
6
|
+
require 'openid/store/filesystem'
|
|
7
|
+
|
|
8
|
+
class ConsumerController < ApplicationController
|
|
9
|
+
layout nil
|
|
10
|
+
|
|
11
|
+
def index
|
|
12
|
+
# render an openid form
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def start
|
|
16
|
+
begin
|
|
17
|
+
identifier = params[:openid_identifier]
|
|
18
|
+
if identifier.nil?
|
|
19
|
+
flash[:error] = "Enter an OpenID identifier"
|
|
20
|
+
redirect_to :action => 'index'
|
|
21
|
+
return
|
|
22
|
+
end
|
|
23
|
+
oidreq = consumer.begin(identifier)
|
|
24
|
+
rescue OpenID::OpenIDError => e
|
|
25
|
+
flash[:error] = "Discovery failed for #{identifier}: #{e}"
|
|
26
|
+
redirect_to :action => 'index'
|
|
27
|
+
return
|
|
28
|
+
end
|
|
29
|
+
if params[:use_sreg]
|
|
30
|
+
sregreq = OpenID::SReg::Request.new
|
|
31
|
+
# required fields
|
|
32
|
+
sregreq.request_fields(['email','nickname'], true)
|
|
33
|
+
# optional fields
|
|
34
|
+
sregreq.request_fields(['dob', 'fullname'], false)
|
|
35
|
+
oidreq.add_extension(sregreq)
|
|
36
|
+
oidreq.return_to_args['did_sreg'] = 'y'
|
|
37
|
+
end
|
|
38
|
+
if params[:use_pape]
|
|
39
|
+
papereq = OpenID::PAPE::Request.new
|
|
40
|
+
papereq.add_policy_uri(OpenID::PAPE::AUTH_PHISHING_RESISTANT)
|
|
41
|
+
papereq.max_auth_age = 2*60*60
|
|
42
|
+
oidreq.add_extension(papereq)
|
|
43
|
+
oidreq.return_to_args['did_pape'] = 'y'
|
|
44
|
+
end
|
|
45
|
+
if params[:force_post]
|
|
46
|
+
oidreq.return_to_args['force_post']='x'*2048
|
|
47
|
+
end
|
|
48
|
+
return_to = url_for :action => 'complete', :only_path => false
|
|
49
|
+
realm = url_for :action => 'index', :id => nil, :only_path => false
|
|
50
|
+
|
|
51
|
+
if oidreq.send_redirect?(realm, return_to, params[:immediate])
|
|
52
|
+
redirect_to oidreq.redirect_url(realm, return_to, params[:immediate])
|
|
53
|
+
else
|
|
54
|
+
render :text => oidreq.html_markup(realm, return_to, params[:immediate], {'id' => 'openid_form'})
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def complete
|
|
59
|
+
# FIXME - url_for some action is not necessarily the current URL.
|
|
60
|
+
current_url = url_for(:action => 'complete', :only_path => false)
|
|
61
|
+
parameters = params.reject { |k,v|
|
|
62
|
+
# params keys are String; Rails 3.1 path_parameters keys are Symbol
|
|
63
|
+
request.path_parameters[k.to_sym]
|
|
64
|
+
}
|
|
65
|
+
oidresp = consumer.complete(parameters, current_url)
|
|
66
|
+
case oidresp.status
|
|
67
|
+
when OpenID::Consumer::FAILURE
|
|
68
|
+
if oidresp.display_identifier
|
|
69
|
+
flash[:error] = ("Verification of #{oidresp.display_identifier}"\
|
|
70
|
+
" failed: #{oidresp.message}")
|
|
71
|
+
else
|
|
72
|
+
flash[:error] = "Verification failed: #{oidresp.message}"
|
|
73
|
+
end
|
|
74
|
+
when OpenID::Consumer::SUCCESS
|
|
75
|
+
flash[:success] = ("Verification of #{oidresp.display_identifier}"\
|
|
76
|
+
" succeeded.")
|
|
77
|
+
if params[:did_sreg]
|
|
78
|
+
sreg_resp = OpenID::SReg::Response.from_success_response(oidresp)
|
|
79
|
+
sreg_message = "Simple Registration data was requested"
|
|
80
|
+
if sreg_resp.empty?
|
|
81
|
+
sreg_message << ", but none was returned."
|
|
82
|
+
else
|
|
83
|
+
sreg_message << ". The following data were sent:"
|
|
84
|
+
sreg_resp.data.each {|k,v|
|
|
85
|
+
sreg_message << "<br/><b>#{k}</b>: #{v}"
|
|
86
|
+
}
|
|
87
|
+
end
|
|
88
|
+
flash[:sreg_results] = sreg_message
|
|
89
|
+
end
|
|
90
|
+
if params[:did_pape]
|
|
91
|
+
pape_resp = OpenID::PAPE::Response.from_success_response(oidresp)
|
|
92
|
+
pape_message = "A phishing resistant authentication method was requested"
|
|
93
|
+
if pape_resp.auth_policies.member? OpenID::PAPE::AUTH_PHISHING_RESISTANT
|
|
94
|
+
pape_message << ", and the server reported one."
|
|
95
|
+
else
|
|
96
|
+
pape_message << ", but the server did not report one."
|
|
97
|
+
end
|
|
98
|
+
if pape_resp.auth_time
|
|
99
|
+
pape_message << "<br><b>Authentication time:</b> #{pape_resp.auth_time} seconds"
|
|
100
|
+
end
|
|
101
|
+
if pape_resp.nist_auth_level
|
|
102
|
+
pape_message << "<br><b>NIST Auth Level:</b> #{pape_resp.nist_auth_level}"
|
|
103
|
+
end
|
|
104
|
+
flash[:pape_results] = pape_message
|
|
105
|
+
end
|
|
106
|
+
when OpenID::Consumer::SETUP_NEEDED
|
|
107
|
+
flash[:alert] = "Immediate request failed - Setup Needed"
|
|
108
|
+
when OpenID::Consumer::CANCEL
|
|
109
|
+
flash[:alert] = "OpenID transaction cancelled."
|
|
110
|
+
else
|
|
111
|
+
end
|
|
112
|
+
redirect_to :action => 'index'
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
private
|
|
116
|
+
|
|
117
|
+
def consumer
|
|
118
|
+
if @consumer.nil?
|
|
119
|
+
dir = Pathname.new(RAILS_ROOT).join('db').join('cstore')
|
|
120
|
+
store = OpenID::Store::Filesystem.new(dir)
|
|
121
|
+
@consumer = OpenID::Consumer.new(session, store)
|
|
122
|
+
end
|
|
123
|
+
return @consumer
|
|
124
|
+
end
|
|
125
|
+
end
|