houston-oauth-plugin 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/CHANGELOG +187 -0
- data/Gemfile +27 -0
- data/Guardfile +8 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +542 -0
- data/Rakefile +1 -0
- data/UPGRADE.rdoc +21 -0
- data/generators/oauth_consumer/USAGE +10 -0
- data/generators/oauth_consumer/oauth_consumer_generator.rb +52 -0
- data/generators/oauth_consumer/templates/consumer_token.rb +11 -0
- data/generators/oauth_consumer/templates/controller.rb +27 -0
- data/generators/oauth_consumer/templates/index.html.erb +29 -0
- data/generators/oauth_consumer/templates/index.html.haml +18 -0
- data/generators/oauth_consumer/templates/index.html.slim +15 -0
- data/generators/oauth_consumer/templates/migration.rb +23 -0
- data/generators/oauth_consumer/templates/oauth_config.rb +73 -0
- data/generators/oauth_consumer/templates/show.html.erb +7 -0
- data/generators/oauth_consumer/templates/show.html.haml +8 -0
- data/generators/oauth_consumer/templates/show.html.slim +8 -0
- data/generators/oauth_provider/USAGE +20 -0
- data/generators/oauth_provider/lib/insert_routes.rb +67 -0
- data/generators/oauth_provider/oauth_provider_generator.rb +127 -0
- data/generators/oauth_provider/templates/_form.html.erb +17 -0
- data/generators/oauth_provider/templates/_form.html.haml +21 -0
- data/generators/oauth_provider/templates/access_token.rb +16 -0
- data/generators/oauth_provider/templates/authorize.html.erb +14 -0
- data/generators/oauth_provider/templates/authorize.html.haml +16 -0
- data/generators/oauth_provider/templates/authorize_failure.html.erb +1 -0
- data/generators/oauth_provider/templates/authorize_failure.html.haml +1 -0
- data/generators/oauth_provider/templates/authorize_success.html.erb +1 -0
- data/generators/oauth_provider/templates/authorize_success.html.haml +1 -0
- data/generators/oauth_provider/templates/client_application.rb +57 -0
- data/generators/oauth_provider/templates/client_application_spec.rb +29 -0
- data/generators/oauth_provider/templates/client_application_test.rb +42 -0
- data/generators/oauth_provider/templates/client_applications.yml +23 -0
- data/generators/oauth_provider/templates/clients_controller.rb +52 -0
- data/generators/oauth_provider/templates/clients_controller_spec.rb +176 -0
- data/generators/oauth_provider/templates/clients_controller_test.rb +280 -0
- data/generators/oauth_provider/templates/controller.rb +23 -0
- data/generators/oauth_provider/templates/edit.html.erb +7 -0
- data/generators/oauth_provider/templates/edit.html.haml +4 -0
- data/generators/oauth_provider/templates/index.html.erb +43 -0
- data/generators/oauth_provider/templates/index.html.haml +39 -0
- data/generators/oauth_provider/templates/migration.rb +47 -0
- data/generators/oauth_provider/templates/new.html.erb +5 -0
- data/generators/oauth_provider/templates/new.html.haml +5 -0
- data/generators/oauth_provider/templates/oauth2_authorize.html.erb +16 -0
- data/generators/oauth_provider/templates/oauth2_authorize.html.haml +17 -0
- data/generators/oauth_provider/templates/oauth2_token.rb +20 -0
- data/generators/oauth_provider/templates/oauth2_token_spec.rb +52 -0
- data/generators/oauth_provider/templates/oauth2_verifier.rb +35 -0
- data/generators/oauth_provider/templates/oauth2_verifier_spec.rb +44 -0
- data/generators/oauth_provider/templates/oauth_nonce.rb +13 -0
- data/generators/oauth_provider/templates/oauth_nonce_spec.rb +24 -0
- data/generators/oauth_provider/templates/oauth_nonce_test.rb +26 -0
- data/generators/oauth_provider/templates/oauth_nonces.yml +13 -0
- data/generators/oauth_provider/templates/oauth_token.rb +30 -0
- data/generators/oauth_provider/templates/oauth_token_spec.rb +309 -0
- data/generators/oauth_provider/templates/oauth_token_test.rb +57 -0
- data/generators/oauth_provider/templates/oauth_tokens.yml +17 -0
- data/generators/oauth_provider/templates/request_token.rb +40 -0
- data/generators/oauth_provider/templates/show.html.erb +27 -0
- data/generators/oauth_provider/templates/show.html.haml +30 -0
- data/init.rb +1 -0
- data/install.rb +2 -0
- data/lib/generators/active_record/oauth_consumer_generator.rb +33 -0
- data/lib/generators/active_record/oauth_consumer_templates/consumer_token.rb +11 -0
- data/lib/generators/active_record/oauth_consumer_templates/migration.rb +20 -0
- data/lib/generators/active_record/oauth_provider_generator.rb +39 -0
- data/lib/generators/active_record/oauth_provider_templates/access_token.rb +16 -0
- data/lib/generators/active_record/oauth_provider_templates/client_application.rb +57 -0
- data/lib/generators/active_record/oauth_provider_templates/migration.rb +47 -0
- data/lib/generators/active_record/oauth_provider_templates/oauth2_token.rb +20 -0
- data/lib/generators/active_record/oauth_provider_templates/oauth2_verifier.rb +35 -0
- data/lib/generators/active_record/oauth_provider_templates/oauth_nonce.rb +13 -0
- data/lib/generators/active_record/oauth_provider_templates/oauth_token.rb +30 -0
- data/lib/generators/active_record/oauth_provider_templates/request_token.rb +40 -0
- data/lib/generators/erb/oauth_consumer_generator.rb +14 -0
- data/lib/generators/erb/oauth_consumer_templates/index.html.erb +29 -0
- data/lib/generators/erb/oauth_consumer_templates/show.html.erb +7 -0
- data/lib/generators/erb/oauth_provider_generator.rb +23 -0
- data/lib/generators/erb/oauth_provider_templates/_form.html.erb +17 -0
- data/lib/generators/erb/oauth_provider_templates/authorize.html.erb +14 -0
- data/lib/generators/erb/oauth_provider_templates/authorize_failure.html.erb +1 -0
- data/lib/generators/erb/oauth_provider_templates/authorize_success.html.erb +1 -0
- data/lib/generators/erb/oauth_provider_templates/edit.html.erb +7 -0
- data/lib/generators/erb/oauth_provider_templates/index.html.erb +43 -0
- data/lib/generators/erb/oauth_provider_templates/new.html.erb +5 -0
- data/lib/generators/erb/oauth_provider_templates/oauth2_authorize.html.erb +16 -0
- data/lib/generators/erb/oauth_provider_templates/show.html.erb +27 -0
- data/lib/generators/haml/oauth_consumer_generator.rb +21 -0
- data/lib/generators/haml/oauth_consumer_templates/index.html.haml +18 -0
- data/lib/generators/haml/oauth_consumer_templates/show.html.haml +8 -0
- data/lib/generators/haml/oauth_provider_generator.rb +28 -0
- data/lib/generators/haml/oauth_provider_templates/_form.html.haml +21 -0
- data/lib/generators/haml/oauth_provider_templates/authorize.html.haml +16 -0
- data/lib/generators/haml/oauth_provider_templates/authorize_failure.html.haml +1 -0
- data/lib/generators/haml/oauth_provider_templates/authorize_success.html.haml +1 -0
- data/lib/generators/haml/oauth_provider_templates/edit.html.haml +4 -0
- data/lib/generators/haml/oauth_provider_templates/index.html.haml +39 -0
- data/lib/generators/haml/oauth_provider_templates/new.html.haml +5 -0
- data/lib/generators/haml/oauth_provider_templates/oauth2_authorize.html.haml +17 -0
- data/lib/generators/haml/oauth_provider_templates/show.html.haml +30 -0
- data/lib/generators/mongoid/oauth_consumer_generator.rb +15 -0
- data/lib/generators/mongoid/oauth_consumer_templates/consumer_token.rb +41 -0
- data/lib/generators/mongoid/oauth_provider_generator.rb +21 -0
- data/lib/generators/mongoid/oauth_provider_templates/access_token.rb +16 -0
- data/lib/generators/mongoid/oauth_provider_templates/client_application.rb +71 -0
- data/lib/generators/mongoid/oauth_provider_templates/oauth2_token.rb +20 -0
- data/lib/generators/mongoid/oauth_provider_templates/oauth2_verifier.rb +35 -0
- data/lib/generators/mongoid/oauth_provider_templates/oauth_nonce.rb +24 -0
- data/lib/generators/mongoid/oauth_provider_templates/oauth_token.rb +44 -0
- data/lib/generators/mongoid/oauth_provider_templates/request_token.rb +36 -0
- data/lib/generators/oauth_consumer/USAGE +11 -0
- data/lib/generators/oauth_consumer/oauth_consumer_generator.rb +31 -0
- data/lib/generators/oauth_consumer/templates/controller.rb +59 -0
- data/lib/generators/oauth_consumer/templates/oauth_config.rb +68 -0
- data/lib/generators/oauth_inflections.rb +6 -0
- data/lib/generators/oauth_plugin.rb +0 -0
- data/lib/generators/oauth_provider/USAGE +18 -0
- data/lib/generators/oauth_provider/oauth_provider_generator.rb +37 -0
- data/lib/generators/oauth_provider/templates/clients_controller.rb +52 -0
- data/lib/generators/oauth_provider/templates/controller.rb +23 -0
- data/lib/generators/rspec/oauth_provider_generator.rb +35 -0
- data/lib/generators/rspec/templates/client_application_spec.rb +29 -0
- data/lib/generators/rspec/templates/client_applications.yml +23 -0
- data/lib/generators/rspec/templates/clients_controller_spec.rb +176 -0
- data/lib/generators/rspec/templates/oauth2_token_spec.rb +52 -0
- data/lib/generators/rspec/templates/oauth2_verifier_spec.rb +44 -0
- data/lib/generators/rspec/templates/oauth_nonce_spec.rb +24 -0
- data/lib/generators/rspec/templates/oauth_nonces.yml +13 -0
- data/lib/generators/rspec/templates/oauth_token_spec.rb +309 -0
- data/lib/generators/rspec/templates/oauth_tokens.yml +17 -0
- data/lib/generators/slim/oauth_consumer_generator.rb +21 -0
- data/lib/generators/slim/oauth_consumer_templates/index.html.slim +15 -0
- data/lib/generators/slim/oauth_consumer_templates/show.html.slim +8 -0
- data/lib/generators/test_unit/oauth_provider_generator.rb +33 -0
- data/lib/generators/test_unit/templates/client_application_test.rb +42 -0
- data/lib/generators/test_unit/templates/client_applications.yml +23 -0
- data/lib/generators/test_unit/templates/clients_controller_test.rb +280 -0
- data/lib/generators/test_unit/templates/oauth_nonce_test.rb +26 -0
- data/lib/generators/test_unit/templates/oauth_nonces.yml +13 -0
- data/lib/generators/test_unit/templates/oauth_token_test.rb +57 -0
- data/lib/generators/test_unit/templates/oauth_tokens.yml +17 -0
- data/lib/oauth-plugin.rb +24 -0
- data/lib/oauth-plugin/version.rb +5 -0
- data/lib/oauth/controllers/application_controller_methods.rb +140 -0
- data/lib/oauth/controllers/consumer_controller.rb +153 -0
- data/lib/oauth/controllers/provider_controller.rb +181 -0
- data/lib/oauth/models/consumers/service_loader.rb +28 -0
- data/lib/oauth/models/consumers/services/agree2_token.rb +15 -0
- data/lib/oauth/models/consumers/services/fireeagle_token.rb +39 -0
- data/lib/oauth/models/consumers/services/google_token.rb +21 -0
- data/lib/oauth/models/consumers/services/oauth2_token.rb +49 -0
- data/lib/oauth/models/consumers/services/opentransact_token.rb +15 -0
- data/lib/oauth/models/consumers/services/picomoney_token.rb +17 -0
- data/lib/oauth/models/consumers/services/twitter_token.rb +24 -0
- data/lib/oauth/models/consumers/simple_client.rb +50 -0
- data/lib/oauth/models/consumers/token.rb +121 -0
- data/lib/oauth/provider/authorizer.rb +83 -0
- data/lib/oauth/rack/oauth_filter.rb +97 -0
- data/oauth-plugin.gemspec +40 -0
- data/rails/init.rb +1 -0
- data/spec/dummy_provider_models.rb +53 -0
- data/spec/oauth/provider/authorizer_spec.rb +202 -0
- data/spec/rack/oauth_filter_spec.rb +244 -0
- data/spec/spec_helper.rb +3 -0
- data/tasks/oauth_tasks.rake +4 -0
- data/uninstall.rb +1 -0
- metadata +373 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rails/generators/erb/controller/controller_generator'
|
2
|
+
|
3
|
+
module Slim
|
4
|
+
module Generators
|
5
|
+
class OauthConsumerGenerator < Erb::Generators::Base
|
6
|
+
source_root File.expand_path('../oauth_consumer_templates', __FILE__)
|
7
|
+
|
8
|
+
argument :name, :type => :string, :default => 'Oauth'
|
9
|
+
|
10
|
+
def copy_view_files
|
11
|
+
template 'index.html.slim', File.join('app/views', class_path, 'oauth_consumers', 'index.html.slim')
|
12
|
+
template 'show.html.slim', File.join('app/views', class_path, 'oauth_consumers', 'show.html.slim')
|
13
|
+
end
|
14
|
+
|
15
|
+
protected
|
16
|
+
def handler
|
17
|
+
:slim
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
h1 Services
|
2
|
+
|
3
|
+
-if @consumer_tokens.empty?
|
4
|
+
p You are currently not connected to any external services.
|
5
|
+
-else
|
6
|
+
p You are connected to the following services:
|
7
|
+
ul
|
8
|
+
-@consumer_tokens.each do |token|
|
9
|
+
li = link_to token.class.service_name.to_s.humanize, oauth_consumer_path(token.class.service_name)
|
10
|
+
|
11
|
+
-unless @services.empty?
|
12
|
+
h3 You can connect to the following services:
|
13
|
+
ul
|
14
|
+
-@services.each do |service|
|
15
|
+
li = link_to service.to_s.humanize,oauth_consumer_path(service)
|
@@ -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
|