pelle-oauth-plugin 0.3.5

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.
Files changed (69) hide show
  1. data/.gitignore +5 -0
  2. data/CHANGELOG +76 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +375 -0
  5. data/Rakefile +38 -0
  6. data/VERSION +1 -0
  7. data/generators/oauth_consumer/USAGE +10 -0
  8. data/generators/oauth_consumer/oauth_consumer_generator.rb +49 -0
  9. data/generators/oauth_consumer/templates/consumer_token.rb +5 -0
  10. data/generators/oauth_consumer/templates/controller.rb +14 -0
  11. data/generators/oauth_consumer/templates/migration.rb +20 -0
  12. data/generators/oauth_consumer/templates/oauth_config.rb +37 -0
  13. data/generators/oauth_consumer/templates/show.html.erb +7 -0
  14. data/generators/oauth_consumer/templates/show.html.haml +8 -0
  15. data/generators/oauth_provider/USAGE +20 -0
  16. data/generators/oauth_provider/lib/insert_routes.rb +67 -0
  17. data/generators/oauth_provider/oauth_provider_generator.rb +124 -0
  18. data/generators/oauth_provider/templates/_form.html.erb +17 -0
  19. data/generators/oauth_provider/templates/_form.html.haml +21 -0
  20. data/generators/oauth_provider/templates/access_token.rb +10 -0
  21. data/generators/oauth_provider/templates/authorize.html.erb +14 -0
  22. data/generators/oauth_provider/templates/authorize.html.haml +16 -0
  23. data/generators/oauth_provider/templates/authorize_failure.html.erb +1 -0
  24. data/generators/oauth_provider/templates/authorize_failure.html.haml +1 -0
  25. data/generators/oauth_provider/templates/authorize_success.html.erb +1 -0
  26. data/generators/oauth_provider/templates/authorize_success.html.haml +1 -0
  27. data/generators/oauth_provider/templates/client_application.rb +55 -0
  28. data/generators/oauth_provider/templates/client_application_spec.rb +29 -0
  29. data/generators/oauth_provider/templates/client_application_test.rb +42 -0
  30. data/generators/oauth_provider/templates/client_applications.yml +23 -0
  31. data/generators/oauth_provider/templates/clients_controller.rb +52 -0
  32. data/generators/oauth_provider/templates/clients_controller_spec.rb +239 -0
  33. data/generators/oauth_provider/templates/clients_controller_test.rb +280 -0
  34. data/generators/oauth_provider/templates/controller.rb +5 -0
  35. data/generators/oauth_provider/templates/controller_spec.rb +367 -0
  36. data/generators/oauth_provider/templates/controller_spec_helper.rb +80 -0
  37. data/generators/oauth_provider/templates/controller_test.rb +310 -0
  38. data/generators/oauth_provider/templates/controller_test_helper.rb +115 -0
  39. data/generators/oauth_provider/templates/edit.html.erb +7 -0
  40. data/generators/oauth_provider/templates/edit.html.haml +4 -0
  41. data/generators/oauth_provider/templates/index.html.erb +43 -0
  42. data/generators/oauth_provider/templates/index.html.haml +39 -0
  43. data/generators/oauth_provider/templates/migration.rb +46 -0
  44. data/generators/oauth_provider/templates/new.html.erb +5 -0
  45. data/generators/oauth_provider/templates/new.html.haml +5 -0
  46. data/generators/oauth_provider/templates/oauth_nonce.rb +13 -0
  47. data/generators/oauth_provider/templates/oauth_nonce_spec.rb +24 -0
  48. data/generators/oauth_provider/templates/oauth_nonce_test.rb +26 -0
  49. data/generators/oauth_provider/templates/oauth_nonces.yml +13 -0
  50. data/generators/oauth_provider/templates/oauth_token.rb +31 -0
  51. data/generators/oauth_provider/templates/oauth_token_spec.rb +309 -0
  52. data/generators/oauth_provider/templates/oauth_token_test.rb +57 -0
  53. data/generators/oauth_provider/templates/oauth_tokens.yml +17 -0
  54. data/generators/oauth_provider/templates/request_token.rb +40 -0
  55. data/generators/oauth_provider/templates/show.html.erb +27 -0
  56. data/generators/oauth_provider/templates/show.html.haml +30 -0
  57. data/init.rb +7 -0
  58. data/install.rb +2 -0
  59. data/lib/oauth/controllers/application_controller_methods.rb +110 -0
  60. data/lib/oauth/controllers/consumer_controller.rb +69 -0
  61. data/lib/oauth/controllers/provider_controller.rb +78 -0
  62. data/lib/oauth/models/consumers/service_loader.rb +18 -0
  63. data/lib/oauth/models/consumers/services/agree2_token.rb +14 -0
  64. data/lib/oauth/models/consumers/services/twitter_token.rb +19 -0
  65. data/lib/oauth/models/consumers/token.rb +60 -0
  66. data/oauth-plugin.gemspec +104 -0
  67. data/tasks/oauth_tasks.rake +4 -0
  68. data/uninstall.rb +1 -0
  69. metadata +129 -0
@@ -0,0 +1,239 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require File.dirname(__FILE__) + '/oauth_controller_spec_helper'
3
+ require 'oauth/client/action_controller_request'
4
+
5
+ describe OauthClientsController, "index" do
6
+ include OAuthControllerSpecHelper
7
+ before(:each) do
8
+ login_as_application_owner
9
+ end
10
+
11
+ def do_get
12
+ get :index
13
+ end
14
+
15
+ it "should be successful" do
16
+ do_get
17
+ response.should be_success
18
+ end
19
+
20
+ it "should query current_users client applications" do
21
+ @user.should_receive(:client_applications).and_return(@client_applications)
22
+ do_get
23
+ end
24
+
25
+ it "should assign client_applications" do
26
+ do_get
27
+ assigns[:client_applications].should equal(@client_applications)
28
+ end
29
+
30
+ it "should render index template" do
31
+ do_get
32
+ response.should render_template('index')
33
+ end
34
+ end
35
+
36
+ describe OauthClientsController, "show" do
37
+ include OAuthControllerSpecHelper
38
+ before(:each) do
39
+ login_as_application_owner
40
+ end
41
+
42
+ def do_get
43
+ get :show, :id => '3'
44
+ end
45
+
46
+ it "should be successful" do
47
+ do_get
48
+ response.should be_success
49
+ end
50
+
51
+ it "should query current_users client applications" do
52
+ @user.should_receive(:client_applications).and_return(@client_applications)
53
+ @client_applications.should_receive(:find).with('3').and_return(@client_application)
54
+ do_get
55
+ end
56
+
57
+ it "should assign client_applications" do
58
+ do_get
59
+ assigns[:client_application].should equal(@client_application)
60
+ end
61
+
62
+ it "should render show template" do
63
+ do_get
64
+ response.should render_template('show')
65
+ end
66
+
67
+ end
68
+
69
+ describe OauthClientsController, "new" do
70
+ include OAuthControllerSpecHelper
71
+ before(:each) do
72
+ login_as_application_owner
73
+ ClientApplication.stub!(:new).and_return(@client_application)
74
+ end
75
+
76
+ def do_get
77
+ get :new
78
+ end
79
+
80
+ it "should be successful" do
81
+ do_get
82
+ response.should be_success
83
+ end
84
+
85
+ it "should assign client_applications" do
86
+ do_get
87
+ assigns[:client_application].should equal(@client_application)
88
+ end
89
+
90
+ it "should render show template" do
91
+ do_get
92
+ response.should render_template('new')
93
+ end
94
+
95
+ end
96
+
97
+ describe OauthClientsController, "edit" do
98
+ include OAuthControllerSpecHelper
99
+ before(:each) do
100
+ login_as_application_owner
101
+ end
102
+
103
+ def do_get
104
+ get :edit, :id => '3'
105
+ end
106
+
107
+ it "should be successful" do
108
+ do_get
109
+ response.should be_success
110
+ end
111
+
112
+ it "should query current_users client applications" do
113
+ @user.should_receive(:client_applications).and_return(@client_applications)
114
+ @client_applications.should_receive(:find).with('3').and_return(@client_application)
115
+ do_get
116
+ end
117
+
118
+ it "should assign client_applications" do
119
+ do_get
120
+ assigns[:client_application].should equal(@client_application)
121
+ end
122
+
123
+ it "should render edit template" do
124
+ do_get
125
+ response.should render_template('edit')
126
+ end
127
+
128
+ end
129
+
130
+ describe OauthClientsController, "create" do
131
+ include OAuthControllerSpecHelper
132
+
133
+ before(:each) do
134
+ login_as_application_owner
135
+ @client_applications.stub!(:build).and_return(@client_application)
136
+ @client_application.stub!(:save).and_return(true)
137
+ end
138
+
139
+ def do_valid_post
140
+ @client_application.should_receive(:save).and_return(true)
141
+ post :create, 'client_application'=>{'name' => 'my site'}
142
+ end
143
+
144
+ def do_invalid_post
145
+ @client_application.should_receive(:save).and_return(false)
146
+ post :create, :client_application=>{:name => 'my site'}
147
+ end
148
+
149
+ it "should query current_users client applications" do
150
+ @client_applications.should_receive(:build).and_return(@client_application)
151
+ do_valid_post
152
+ end
153
+
154
+ it "should redirect to new client_application" do
155
+ do_valid_post
156
+ response.should be_redirect
157
+ response.should redirect_to(:action => "show", :id => @client_application.id)
158
+ end
159
+
160
+ it "should assign client_applications" do
161
+ do_invalid_post
162
+ assigns[:client_application].should equal(@client_application)
163
+ end
164
+
165
+ it "should render show template" do
166
+ do_invalid_post
167
+ response.should render_template('new')
168
+ end
169
+ end
170
+
171
+ describe OauthClientsController, "destroy" do
172
+ include OAuthControllerSpecHelper
173
+ before(:each) do
174
+ login_as_application_owner
175
+ @client_application.stub!(:destroy)
176
+ end
177
+
178
+ def do_delete
179
+ delete :destroy, :id => '3'
180
+ end
181
+
182
+ it "should query current_users client applications" do
183
+ @user.should_receive(:client_applications).and_return(@client_applications)
184
+ @client_applications.should_receive(:find).with('3').and_return(@client_application)
185
+ do_delete
186
+ end
187
+
188
+ it "should destroy client applications" do
189
+ @client_application.should_receive(:destroy)
190
+ do_delete
191
+ end
192
+
193
+ it "should redirect to list" do
194
+ do_delete
195
+ response.should be_redirect
196
+ response.should redirect_to(:action => 'index')
197
+ end
198
+
199
+ end
200
+
201
+ describe OauthClientsController, "update" do
202
+ include OAuthControllerSpecHelper
203
+
204
+ before(:each) do
205
+ login_as_application_owner
206
+ end
207
+
208
+ def do_valid_update
209
+ @client_application.should_receive(:update_attributes).and_return(true)
210
+ put :update, :id => '1', 'client_application'=>{'name' => 'my site'}
211
+ end
212
+
213
+ def do_invalid_update
214
+ @client_application.should_receive(:update_attributes).and_return(false)
215
+ put :update, :id => '1', 'client_application'=>{'name' => 'my site'}
216
+ end
217
+
218
+ it "should query current_users client applications" do
219
+ @user.should_receive(:client_applications).and_return(@client_applications)
220
+ @client_applications.should_receive(:find).with('1').and_return(@client_application)
221
+ do_valid_update
222
+ end
223
+
224
+ it "should redirect to new client_application" do
225
+ do_valid_update
226
+ response.should be_redirect
227
+ response.should redirect_to(:action => "show", :id => @client_application.id)
228
+ end
229
+
230
+ it "should assign client_applications" do
231
+ do_invalid_update
232
+ assigns[:client_application].should equal(@client_application)
233
+ end
234
+
235
+ it "should render show template" do
236
+ do_invalid_update
237
+ response.should render_template('edit')
238
+ end
239
+ end
@@ -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,5 @@
1
+ require 'oauth/controllers/provider_controller'
2
+ class OauthController < ApplicationController
3
+ include OAuth::Controllers::ProviderController
4
+
5
+ end