panjiva-oauth-plugin 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (167) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +12 -0
  3. data/CHANGELOG +178 -0
  4. data/Gemfile +27 -0
  5. data/Guardfile +8 -0
  6. data/MIT-LICENSE +20 -0
  7. data/README.rdoc +531 -0
  8. data/Rakefile +2 -0
  9. data/UPGRADE.rdoc +21 -0
  10. data/generators/oauth_consumer/USAGE +10 -0
  11. data/generators/oauth_consumer/oauth_consumer_generator.rb +50 -0
  12. data/generators/oauth_consumer/templates/consumer_token.rb +11 -0
  13. data/generators/oauth_consumer/templates/controller.rb +27 -0
  14. data/generators/oauth_consumer/templates/index.html.erb +29 -0
  15. data/generators/oauth_consumer/templates/index.html.haml +18 -0
  16. data/generators/oauth_consumer/templates/migration.rb +20 -0
  17. data/generators/oauth_consumer/templates/oauth_config.rb +73 -0
  18. data/generators/oauth_consumer/templates/show.html.erb +7 -0
  19. data/generators/oauth_consumer/templates/show.html.haml +8 -0
  20. data/generators/oauth_provider/USAGE +20 -0
  21. data/generators/oauth_provider/lib/insert_routes.rb +67 -0
  22. data/generators/oauth_provider/oauth_provider_generator.rb +127 -0
  23. data/generators/oauth_provider/templates/_form.html.erb +17 -0
  24. data/generators/oauth_provider/templates/_form.html.haml +21 -0
  25. data/generators/oauth_provider/templates/access_token.rb +16 -0
  26. data/generators/oauth_provider/templates/authorize.html.erb +14 -0
  27. data/generators/oauth_provider/templates/authorize.html.haml +16 -0
  28. data/generators/oauth_provider/templates/authorize_failure.html.erb +1 -0
  29. data/generators/oauth_provider/templates/authorize_failure.html.haml +1 -0
  30. data/generators/oauth_provider/templates/authorize_success.html.erb +1 -0
  31. data/generators/oauth_provider/templates/authorize_success.html.haml +1 -0
  32. data/generators/oauth_provider/templates/client_application.rb +57 -0
  33. data/generators/oauth_provider/templates/client_application_spec.rb +29 -0
  34. data/generators/oauth_provider/templates/client_application_test.rb +42 -0
  35. data/generators/oauth_provider/templates/client_applications.yml +23 -0
  36. data/generators/oauth_provider/templates/clients_controller.rb +52 -0
  37. data/generators/oauth_provider/templates/clients_controller_spec.rb +176 -0
  38. data/generators/oauth_provider/templates/clients_controller_test.rb +280 -0
  39. data/generators/oauth_provider/templates/controller.rb +23 -0
  40. data/generators/oauth_provider/templates/edit.html.erb +7 -0
  41. data/generators/oauth_provider/templates/edit.html.haml +4 -0
  42. data/generators/oauth_provider/templates/index.html.erb +43 -0
  43. data/generators/oauth_provider/templates/index.html.haml +39 -0
  44. data/generators/oauth_provider/templates/migration.rb +47 -0
  45. data/generators/oauth_provider/templates/new.html.erb +5 -0
  46. data/generators/oauth_provider/templates/new.html.haml +5 -0
  47. data/generators/oauth_provider/templates/oauth2_authorize.html.erb +16 -0
  48. data/generators/oauth_provider/templates/oauth2_authorize.html.haml +17 -0
  49. data/generators/oauth_provider/templates/oauth2_token.rb +20 -0
  50. data/generators/oauth_provider/templates/oauth2_token_spec.rb +52 -0
  51. data/generators/oauth_provider/templates/oauth2_verifier.rb +35 -0
  52. data/generators/oauth_provider/templates/oauth2_verifier_spec.rb +44 -0
  53. data/generators/oauth_provider/templates/oauth_nonce.rb +13 -0
  54. data/generators/oauth_provider/templates/oauth_nonce_spec.rb +24 -0
  55. data/generators/oauth_provider/templates/oauth_nonce_test.rb +26 -0
  56. data/generators/oauth_provider/templates/oauth_nonces.yml +13 -0
  57. data/generators/oauth_provider/templates/oauth_token.rb +30 -0
  58. data/generators/oauth_provider/templates/oauth_token_spec.rb +309 -0
  59. data/generators/oauth_provider/templates/oauth_token_test.rb +57 -0
  60. data/generators/oauth_provider/templates/oauth_tokens.yml +17 -0
  61. data/generators/oauth_provider/templates/request_token.rb +40 -0
  62. data/generators/oauth_provider/templates/show.html.erb +27 -0
  63. data/generators/oauth_provider/templates/show.html.haml +30 -0
  64. data/init.rb +1 -0
  65. data/install.rb +2 -0
  66. data/lib/generators/active_record/oauth_consumer_generator.rb +33 -0
  67. data/lib/generators/active_record/oauth_consumer_templates/consumer_token.rb +11 -0
  68. data/lib/generators/active_record/oauth_consumer_templates/migration.rb +20 -0
  69. data/lib/generators/active_record/oauth_provider_generator.rb +39 -0
  70. data/lib/generators/active_record/oauth_provider_templates/access_token.rb +16 -0
  71. data/lib/generators/active_record/oauth_provider_templates/client_application.rb +57 -0
  72. data/lib/generators/active_record/oauth_provider_templates/migration.rb +47 -0
  73. data/lib/generators/active_record/oauth_provider_templates/oauth2_token.rb +20 -0
  74. data/lib/generators/active_record/oauth_provider_templates/oauth2_verifier.rb +35 -0
  75. data/lib/generators/active_record/oauth_provider_templates/oauth_nonce.rb +13 -0
  76. data/lib/generators/active_record/oauth_provider_templates/oauth_token.rb +30 -0
  77. data/lib/generators/active_record/oauth_provider_templates/request_token.rb +40 -0
  78. data/lib/generators/erb/oauth_consumer_generator.rb +14 -0
  79. data/lib/generators/erb/oauth_consumer_templates/index.html.erb +29 -0
  80. data/lib/generators/erb/oauth_consumer_templates/show.html.erb +7 -0
  81. data/lib/generators/erb/oauth_provider_generator.rb +23 -0
  82. data/lib/generators/erb/oauth_provider_templates/_form.html.erb +17 -0
  83. data/lib/generators/erb/oauth_provider_templates/authorize.html.erb +14 -0
  84. data/lib/generators/erb/oauth_provider_templates/authorize_failure.html.erb +1 -0
  85. data/lib/generators/erb/oauth_provider_templates/authorize_success.html.erb +1 -0
  86. data/lib/generators/erb/oauth_provider_templates/edit.html.erb +7 -0
  87. data/lib/generators/erb/oauth_provider_templates/index.html.erb +43 -0
  88. data/lib/generators/erb/oauth_provider_templates/new.html.erb +5 -0
  89. data/lib/generators/erb/oauth_provider_templates/oauth2_authorize.html.erb +16 -0
  90. data/lib/generators/erb/oauth_provider_templates/show.html.erb +27 -0
  91. data/lib/generators/haml/oauth_consumer_generator.rb +21 -0
  92. data/lib/generators/haml/oauth_consumer_templates/index.html.haml +18 -0
  93. data/lib/generators/haml/oauth_consumer_templates/show.html.haml +8 -0
  94. data/lib/generators/haml/oauth_provider_generator.rb +28 -0
  95. data/lib/generators/haml/oauth_provider_templates/_form.html.haml +21 -0
  96. data/lib/generators/haml/oauth_provider_templates/authorize.html.haml +16 -0
  97. data/lib/generators/haml/oauth_provider_templates/authorize_failure.html.haml +1 -0
  98. data/lib/generators/haml/oauth_provider_templates/authorize_success.html.haml +1 -0
  99. data/lib/generators/haml/oauth_provider_templates/edit.html.haml +4 -0
  100. data/lib/generators/haml/oauth_provider_templates/index.html.haml +39 -0
  101. data/lib/generators/haml/oauth_provider_templates/new.html.haml +5 -0
  102. data/lib/generators/haml/oauth_provider_templates/oauth2_authorize.html.haml +17 -0
  103. data/lib/generators/haml/oauth_provider_templates/show.html.haml +30 -0
  104. data/lib/generators/mongoid/oauth_consumer_generator.rb +15 -0
  105. data/lib/generators/mongoid/oauth_consumer_templates/consumer_token.rb +41 -0
  106. data/lib/generators/mongoid/oauth_provider_generator.rb +21 -0
  107. data/lib/generators/mongoid/oauth_provider_templates/access_token.rb +16 -0
  108. data/lib/generators/mongoid/oauth_provider_templates/client_application.rb +71 -0
  109. data/lib/generators/mongoid/oauth_provider_templates/oauth2_token.rb +20 -0
  110. data/lib/generators/mongoid/oauth_provider_templates/oauth2_verifier.rb +35 -0
  111. data/lib/generators/mongoid/oauth_provider_templates/oauth_nonce.rb +24 -0
  112. data/lib/generators/mongoid/oauth_provider_templates/oauth_token.rb +44 -0
  113. data/lib/generators/mongoid/oauth_provider_templates/request_token.rb +36 -0
  114. data/lib/generators/oauth_consumer/USAGE +11 -0
  115. data/lib/generators/oauth_consumer/oauth_consumer_generator.rb +31 -0
  116. data/lib/generators/oauth_consumer/templates/controller.rb +59 -0
  117. data/lib/generators/oauth_consumer/templates/oauth_config.rb +68 -0
  118. data/lib/generators/oauth_inflections.rb +6 -0
  119. data/lib/generators/oauth_plugin.rb +0 -0
  120. data/lib/generators/oauth_provider/USAGE +18 -0
  121. data/lib/generators/oauth_provider/oauth_provider_generator.rb +37 -0
  122. data/lib/generators/oauth_provider/templates/clients_controller.rb +52 -0
  123. data/lib/generators/oauth_provider/templates/controller.rb +23 -0
  124. data/lib/generators/rspec/oauth_provider_generator.rb +35 -0
  125. data/lib/generators/rspec/templates/client_application_spec.rb +29 -0
  126. data/lib/generators/rspec/templates/client_applications.yml +23 -0
  127. data/lib/generators/rspec/templates/clients_controller_spec.rb +176 -0
  128. data/lib/generators/rspec/templates/oauth2_token_spec.rb +52 -0
  129. data/lib/generators/rspec/templates/oauth2_verifier_spec.rb +44 -0
  130. data/lib/generators/rspec/templates/oauth_nonce_spec.rb +24 -0
  131. data/lib/generators/rspec/templates/oauth_nonces.yml +13 -0
  132. data/lib/generators/rspec/templates/oauth_token_spec.rb +309 -0
  133. data/lib/generators/rspec/templates/oauth_tokens.yml +17 -0
  134. data/lib/generators/test_unit/oauth_provider_generator.rb +33 -0
  135. data/lib/generators/test_unit/templates/client_application_test.rb +42 -0
  136. data/lib/generators/test_unit/templates/client_applications.yml +23 -0
  137. data/lib/generators/test_unit/templates/clients_controller_test.rb +280 -0
  138. data/lib/generators/test_unit/templates/oauth_nonce_test.rb +26 -0
  139. data/lib/generators/test_unit/templates/oauth_nonces.yml +13 -0
  140. data/lib/generators/test_unit/templates/oauth_token_test.rb +57 -0
  141. data/lib/generators/test_unit/templates/oauth_tokens.yml +17 -0
  142. data/lib/oauth-plugin.rb +24 -0
  143. data/lib/oauth-plugin/version.rb +5 -0
  144. data/lib/oauth/controllers/application_controller_methods.rb +136 -0
  145. data/lib/oauth/controllers/consumer_controller.rb +150 -0
  146. data/lib/oauth/controllers/provider_controller.rb +181 -0
  147. data/lib/oauth/models/consumers/service_loader.rb +28 -0
  148. data/lib/oauth/models/consumers/services/agree2_token.rb +15 -0
  149. data/lib/oauth/models/consumers/services/fireeagle_token.rb +39 -0
  150. data/lib/oauth/models/consumers/services/google_token.rb +21 -0
  151. data/lib/oauth/models/consumers/services/oauth2_token.rb +27 -0
  152. data/lib/oauth/models/consumers/services/opentransact_token.rb +15 -0
  153. data/lib/oauth/models/consumers/services/picomoney_token.rb +17 -0
  154. data/lib/oauth/models/consumers/services/twitter_token.rb +24 -0
  155. data/lib/oauth/models/consumers/simple_client.rb +50 -0
  156. data/lib/oauth/models/consumers/token.rb +93 -0
  157. data/lib/oauth/provider/authorizer.rb +83 -0
  158. data/lib/oauth/rack/oauth_filter.rb +93 -0
  159. data/oauth-plugin.gemspec +39 -0
  160. data/rails/init.rb +1 -0
  161. data/spec/dummy_provider_models.rb +53 -0
  162. data/spec/oauth/provider/authorizer_spec.rb +202 -0
  163. data/spec/rack/oauth_filter_spec.rb +244 -0
  164. data/spec/spec_helper.rb +3 -0
  165. data/tasks/oauth_tasks.rake +4 -0
  166. data/uninstall.rb +1 -0
  167. metadata +362 -0
@@ -0,0 +1,33 @@
1
+ require 'rails/generators/test_unit'
2
+
3
+ module TestUnit
4
+ module Generators
5
+ class OauthProviderGenerator < Base
6
+ source_root File.expand_path('../templates', __FILE__)
7
+
8
+ argument :name, :type => :string, :default => 'Oauth'
9
+ class_option :fixture, :type => :boolean
10
+
11
+ def copy_controller_test_files
12
+ template 'clients_controller_test.rb',
13
+ File.join('test/functional', class_path, "#{file_name}_clients_controller_test.rb")
14
+ end
15
+
16
+ def copy_models_test_files
17
+ template 'client_application_test.rb', File.join('test/unit', 'client_application_test.rb')
18
+ template 'oauth_token_test.rb', File.join('test/unit', 'oauth_token_test.rb')
19
+ template 'oauth_nonce_test.rb', File.join('test/unit', 'oauth_nonce_test.rb')
20
+ end
21
+
22
+ hook_for :fixture_replacement
23
+
24
+ def create_fixture_file
25
+ if options[:fixtures] && options[:fixture_replacement].nil?
26
+ template 'client_applications.yml', File.join('test/fixtures', 'client_applications.yml')
27
+ template 'oauth_tokens.yml', File.join('test/fixtures', 'oauth_tokens.yml')
28
+ template 'oauth_nonces.yml', File.join('test/fixtures', 'oauth_nonces.yml')
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,42 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+ module OAuthHelpers
3
+
4
+ def create_consumer
5
+ @consumer=OAuth::Consumer.new(@application.key,@application.secret,
6
+ {
7
+ :site=>@application.oauth_server.base_url
8
+ })
9
+ end
10
+
11
+ end
12
+
13
+ class ClientApplicationTest < ActiveSupport::TestCase
14
+ include OAuthHelpers
15
+ fixtures :users,:client_applications,:oauth_tokens
16
+
17
+ def setup
18
+ @application = ClientApplication.create :name=>"Agree2",:url=>"http://agree2.com",:user=>users(:quentin)
19
+ create_consumer
20
+ end
21
+
22
+ def test_should_be_valid
23
+ assert @application.valid?
24
+ end
25
+
26
+
27
+ def test_should_not_have_errors
28
+ assert_equal [], @application.errors.full_messages
29
+ end
30
+
31
+ def test_should_have_key_and_secret
32
+ assert_not_nil @application.key
33
+ assert_not_nil @application.secret
34
+ end
35
+
36
+ def test_should_have_credentials
37
+ assert_not_nil @application.credentials
38
+ assert_equal @application.key, @application.credentials.key
39
+ assert_equal @application.secret, @application.credentials.secret
40
+ end
41
+
42
+ end
@@ -0,0 +1,23 @@
1
+ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
+ one:
3
+ id: 1
4
+ name: MyString
5
+ url: http://test.com
6
+ support_url: http://test.com/support
7
+ callback_url: http://test.com/callback
8
+ key: one_key
9
+ secret: MyString
10
+ user_id: 1
11
+ created_at: 2007-11-17 16:56:51
12
+ updated_at: 2007-11-17 16:56:51
13
+ two:
14
+ id: 2
15
+ name: MyString
16
+ url: http://test.com
17
+ support_url: http://test.com/support
18
+ callback_url: http://test.com/callback
19
+ key: two_key
20
+ secret: MyString
21
+ user_id: 1
22
+ created_at: 2007-11-17 16:56:51
23
+ updated_at: 2007-11-17 16:56:51
@@ -0,0 +1,280 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+ require File.dirname(__FILE__) + '/../oauth_controller_test_helper'
3
+ require 'oauth/client/action_controller_request'
4
+
5
+ class OauthClientsController; def rescue_action(e) raise e end; end
6
+
7
+ class OauthClientsControllerIndexTest < ActionController::TestCase
8
+ include OAuthControllerTestHelper
9
+ tests OauthClientsController
10
+
11
+ def setup
12
+ @controller = OauthClientsController.new
13
+ @request = ActionController::TestRequest.new
14
+ @response = ActionController::TestResponse.new
15
+
16
+ login_as_application_owner
17
+ end
18
+
19
+ def do_get
20
+ get :index
21
+ end
22
+
23
+ def test_should_be_successful
24
+ do_get
25
+ assert @response.success?
26
+ end
27
+
28
+ def test_should_query_current_users_client_applications
29
+ @user.expects(:client_applications).returns(@client_applications)
30
+ do_get
31
+ end
32
+
33
+ def test_should_assign_client_applications
34
+ do_get
35
+ assert_equal @client_applications, assigns(:client_applications)
36
+ end
37
+
38
+ def test_should_render_index_template
39
+ do_get
40
+ assert_template 'index'
41
+ end
42
+ end
43
+
44
+ class OauthClientsControllerShowTest < ActionController::TestCase
45
+ include OAuthControllerTestHelper
46
+ tests OauthClientsController
47
+
48
+ def setup
49
+ @controller = OauthClientsController.new
50
+ @request = ActionController::TestRequest.new
51
+ @response = ActionController::TestResponse.new
52
+
53
+ login_as_application_owner
54
+ end
55
+
56
+ def do_get
57
+ get :show, :id=>'3'
58
+ end
59
+
60
+ def test_should_be_successful
61
+ do_get
62
+ assert @response.success?
63
+ end
64
+
65
+ def test_should_query_current_users_client_applications
66
+ @user.expects(:client_applications).returns(@client_applications)
67
+ @client_applications.expects(:find).with('3').returns(@client_application)
68
+ do_get
69
+ end
70
+
71
+ def test_should_assign_client_applications
72
+ do_get
73
+ assert_equal @client_application, assigns(:client_application)
74
+ end
75
+
76
+ def test_should_render_show_template
77
+ do_get
78
+ assert_template 'show'
79
+ end
80
+
81
+ end
82
+
83
+ class OauthClientsControllerNewTest < ActionController::TestCase
84
+ include OAuthControllerTestHelper
85
+ tests OauthClientsController
86
+
87
+ def setup
88
+ @controller = OauthClientsController.new
89
+ @request = ActionController::TestRequest.new
90
+ @response = ActionController::TestResponse.new
91
+
92
+ login_as_application_owner
93
+ ClientApplication.stubs(:new).returns(@client_application)
94
+ end
95
+
96
+ def do_get
97
+ get :new
98
+ end
99
+
100
+ def test_should_be_successful
101
+ do_get
102
+ assert @response.success?
103
+ end
104
+
105
+ def test_should_assign_client_applications
106
+ do_get
107
+ assert_equal @client_application, assigns(:client_application)
108
+ end
109
+
110
+ def test_should_render_show_template
111
+ do_get
112
+ assert_template 'new'
113
+ end
114
+
115
+ end
116
+
117
+ class OauthClientsControllerEditTest < ActionController::TestCase
118
+ include OAuthControllerTestHelper
119
+ tests OauthClientsController
120
+
121
+ def setup
122
+ @controller = OauthClientsController.new
123
+ @request = ActionController::TestRequest.new
124
+ @response = ActionController::TestResponse.new
125
+
126
+ login_as_application_owner
127
+ end
128
+
129
+ def do_get
130
+ get :edit, :id=>'3'
131
+ end
132
+
133
+ def test_should_be_successful
134
+ do_get
135
+ assert @response.success?
136
+ end
137
+
138
+ def test_should_query_current_users_client_applications
139
+ @user.expects(:client_applications).returns(@client_applications)
140
+ @client_applications.expects(:find).with('3').returns(@client_application)
141
+ do_get
142
+ end
143
+
144
+ def test_should_assign_client_applications
145
+ do_get
146
+ assert_equal @client_application, assigns(:client_application)
147
+ end
148
+
149
+ def test_should_render_edit_template
150
+ do_get
151
+ assert_template 'edit'
152
+ end
153
+
154
+ end
155
+
156
+ class OauthClientsControllerCreateTest < ActionController::TestCase
157
+ include OAuthControllerTestHelper
158
+ tests OauthClientsController
159
+
160
+ def setup
161
+ @controller = OauthClientsController.new
162
+ @request = ActionController::TestRequest.new
163
+ @response = ActionController::TestResponse.new
164
+
165
+ login_as_application_owner
166
+ @client_applications.stubs(:build).returns(@client_application)
167
+ @client_application.stubs(:save).returns(true)
168
+ end
169
+
170
+ def do_valid_post
171
+ @client_application.expects(:save).returns(true)
172
+ post :create,'client_application'=>{'name'=>'my site'}
173
+ end
174
+
175
+ def do_invalid_post
176
+ @client_application.expects(:save).returns(false)
177
+ post :create,:client_application=>{:name=>'my site'}
178
+ end
179
+
180
+ def test_should_query_current_users_client_applications
181
+ @client_applications.expects(:build).returns(@client_application)
182
+ do_valid_post
183
+ end
184
+
185
+ def test_should_redirect_to_new_client_application
186
+ do_valid_post
187
+ assert_response :redirect
188
+ assert_redirected_to(:action => "show", :id => @client_application.id)
189
+ end
190
+
191
+ def test_should_assign_client_applications
192
+ do_invalid_post
193
+ assert_equal @client_application, assigns(:client_application)
194
+ end
195
+
196
+ def test_should_render_show_template
197
+ do_invalid_post
198
+ assert_template('new')
199
+ end
200
+ end
201
+
202
+ class OauthClientsControllerDestroyTest < ActionController::TestCase
203
+ include OAuthControllerTestHelper
204
+ tests OauthClientsController
205
+
206
+ def setup
207
+ @controller = OauthClientsController.new
208
+ @request = ActionController::TestRequest.new
209
+ @response = ActionController::TestResponse.new
210
+
211
+ login_as_application_owner
212
+ @client_application.stubs(:destroy)
213
+ end
214
+
215
+ def do_delete
216
+ delete :destroy,:id=>'3'
217
+ end
218
+
219
+ def test_should_query_current_users_client_applications
220
+ @user.expects(:client_applications).returns(@client_applications)
221
+ @client_applications.expects(:find).with('3').returns(@client_application)
222
+ do_delete
223
+ end
224
+
225
+ def test_should_destroy_client_applications
226
+ @client_application.expects(:destroy)
227
+ do_delete
228
+ end
229
+
230
+ def test_should_redirect_to_list
231
+ do_delete
232
+ assert_response :redirect
233
+ assert_redirected_to :action => 'index'
234
+ end
235
+
236
+ end
237
+
238
+ class OauthClientsControllerUpdateTest < ActionController::TestCase
239
+ include OAuthControllerTestHelper
240
+ tests OauthClientsController
241
+
242
+ def setup
243
+ @controller = OauthClientsController.new
244
+ @request = ActionController::TestRequest.new
245
+ @response = ActionController::TestResponse.new
246
+ login_as_application_owner
247
+ end
248
+
249
+ def do_valid_update
250
+ @client_application.expects(:update_attributes).returns(true)
251
+ put :update, :id => '1', 'client_application' => {'name'=>'my site'}
252
+ end
253
+
254
+ def do_invalid_update
255
+ @client_application.expects(:update_attributes).returns(false)
256
+ put :update, :id=>'1', 'client_application' => {'name'=>'my site'}
257
+ end
258
+
259
+ def test_should_query_current_users_client_applications
260
+ @user.expects(:client_applications).returns(@client_applications)
261
+ @client_applications.expects(:find).with('1').returns(@client_application)
262
+ do_valid_update
263
+ end
264
+
265
+ def test_should_redirect_to_new_client_application
266
+ do_valid_update
267
+ assert_response :redirect
268
+ assert_redirected_to :action => "show", :id => @client_application.id
269
+ end
270
+
271
+ def test_should_assign_client_applications
272
+ do_invalid_update
273
+ assert_equal @client_application, assigns(:client_application)
274
+ end
275
+
276
+ def test_should_render_show_template
277
+ do_invalid_update
278
+ assert_template('edit')
279
+ end
280
+ end
@@ -0,0 +1,26 @@
1
+ require 'oauth/helper'
2
+ require File.dirname(__FILE__) + '/../test_helper'
3
+
4
+ class ClientNoneTest < ActiveSupport::TestCase
5
+ include OAuth::Helper
6
+
7
+ def setup
8
+ @oauth_nonce = OauthNonce.remember(generate_key,Time.now.to_i)
9
+ end
10
+
11
+ def test_should_be_valid
12
+ assert @oauth_nonce.valid?
13
+ end
14
+
15
+ def test_should_not_have_errors
16
+ assert_equal [], @oauth_nonce.errors.full_messages
17
+ end
18
+
19
+ def test_should_not_be_a_new_record
20
+ assert !@oauth_nonce.new_record?
21
+ end
22
+
23
+ def test_shuold_not_allow_a_second_one_with_the_same_values
24
+ assert_equal false, OauthNonce.remember(@oauth_nonce.nonce, @oauth_nonce.timestamp)
25
+ end
26
+ end
@@ -0,0 +1,13 @@
1
+ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
+ one:
3
+ id: 1
4
+ nonce: a_nonce
5
+ timestamp: 1
6
+ created_at: 2007-11-25 17:27:04
7
+ updated_at: 2007-11-25 17:27:04
8
+ two:
9
+ id: 2
10
+ nonce: b_nonce
11
+ timestamp: 2
12
+ created_at: 2007-11-25 17:27:04
13
+ updated_at: 2007-11-25 17:27:04
@@ -0,0 +1,57 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class RequestTokenTest < ActiveSupport::TestCase
4
+
5
+ fixtures :client_applications, :users, :oauth_tokens
6
+
7
+ def setup
8
+ @token = RequestToken.create :client_application=>client_applications(:one)
9
+ end
10
+
11
+ def test_should_be_valid
12
+ assert @token.valid?
13
+ end
14
+
15
+ def test_should_not_have_errors
16
+ assert @token.errors.empty?
17
+ end
18
+
19
+ def test_should_have_a_token
20
+ assert_not_nil @token.token
21
+ end
22
+
23
+ def test_should_have_a_secret
24
+ assert_not_nil @token.secret
25
+ end
26
+
27
+ def test_should_not_be_authorized
28
+ assert !@token.authorized?
29
+ end
30
+
31
+ def test_should_not_be_invalidated
32
+ assert !@token.invalidated?
33
+ end
34
+
35
+ def test_should_authorize_request
36
+ @token.authorize!(users(:quentin))
37
+ assert @token.authorized?
38
+ assert_not_nil @token.authorized_at
39
+ assert_equal users(:quentin), @token.user
40
+ end
41
+
42
+ def test_should_not_exchange_without_approval
43
+ assert_equal false, @token.exchange!
44
+ assert_equal false, @token.invalidated?
45
+ end
46
+
47
+ def test_should_not_exchange_without_approval
48
+ @token.authorize!(users(:quentin))
49
+ @access = @token.exchange!
50
+ assert_not_equal false, @access
51
+ assert @token.invalidated?
52
+
53
+ assert_equal users(:quentin), @access.user
54
+ assert @access.authorized?
55
+ end
56
+
57
+ end