oauth2_provider_engine 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +3 -0
  3. data/Rakefile +40 -0
  4. data/app/assets/javascripts/oauth2_provider/application.js +52 -0
  5. data/app/assets/javascripts/oauth2_provider/highcharts.js +162 -0
  6. data/app/assets/javascripts/oauth2_provider/jquery.tagsinput.js +218 -0
  7. data/app/assets/stylesheets/oauth2_provider/gh-buttons.css +388 -0
  8. data/app/assets/stylesheets/oauth2_provider/gh-icons.png +0 -0
  9. data/app/assets/stylesheets/oauth2_provider/jquery.tagsinput.css +6 -0
  10. data/app/assets/stylesheets/oauth2_provider/reset.css +2 -0
  11. data/app/assets/stylesheets/oauth2_provider/template.css +52 -0
  12. data/app/controllers/oauth2_provider/accesses_controller.rb +39 -0
  13. data/app/controllers/oauth2_provider/application_controller.rb +17 -0
  14. data/app/controllers/oauth2_provider/authorize_controller.rb +141 -0
  15. data/app/controllers/oauth2_provider/clients_controller.rb +85 -0
  16. data/app/controllers/oauth2_provider/scopes_controller.rb +63 -0
  17. data/app/controllers/oauth2_provider/token_controller.rb +187 -0
  18. data/app/helpers/clients_helper.rb +5 -0
  19. data/app/helpers/oauth2_provider/application_helper.rb +4 -0
  20. data/app/models/oauth2_provider/client.rb +129 -0
  21. data/app/models/oauth2_provider/document.rb +15 -0
  22. data/app/models/oauth2_provider/oauth_access.rb +80 -0
  23. data/app/models/oauth2_provider/oauth_authorization.rb +70 -0
  24. data/app/models/oauth2_provider/oauth_daily_request.rb +54 -0
  25. data/app/models/oauth2_provider/oauth_refresh_token.rb +20 -0
  26. data/app/models/oauth2_provider/oauth_token.rb +78 -0
  27. data/app/models/oauth2_provider/scope.rb +39 -0
  28. data/app/views/layouts/oauth2_provider/application.html.erb +62 -0
  29. data/app/views/oauth2_provider/accesses/index.html.erb +25 -0
  30. data/app/views/oauth2_provider/accesses/show.html.erb +35 -0
  31. data/app/views/oauth2_provider/clients/_form.html.erb +50 -0
  32. data/app/views/oauth2_provider/clients/edit.html.erb +9 -0
  33. data/app/views/oauth2_provider/clients/index.html.erb +43 -0
  34. data/app/views/oauth2_provider/clients/new.html.erb +8 -0
  35. data/app/views/oauth2_provider/clients/show.html.erb +49 -0
  36. data/app/views/oauth2_provider/scopes/_form.html.erb +35 -0
  37. data/app/views/oauth2_provider/scopes/edit.html.erb +8 -0
  38. data/app/views/oauth2_provider/scopes/index.html.erb +27 -0
  39. data/app/views/oauth2_provider/scopes/new.html.erb +7 -0
  40. data/app/views/oauth2_provider/scopes/show.html.erb +19 -0
  41. data/app/views/shared/authorize.html.erb +34 -0
  42. data/app/views/shared/token.json.erb +8 -0
  43. data/config/locales/en.yml +31 -0
  44. data/config/oauth.yml +4 -0
  45. data/config/routes.rb +25 -0
  46. data/lib/oauth2_provider.rb +38 -0
  47. data/lib/oauth2_provider/controller_mixin.rb +53 -0
  48. data/lib/oauth2_provider/engine.rb +4 -0
  49. data/lib/oauth2_provider_engine.rb +1 -0
  50. data/lib/oauth2_provider_engine/version.rb +3 -0
  51. data/test/dummy/CHANGELOG.rdoc +67 -0
  52. data/test/dummy/Gemfile +53 -0
  53. data/test/dummy/Gemfile.lock +254 -0
  54. data/test/dummy/README.rdoc +522 -0
  55. data/test/dummy/Rakefile +7 -0
  56. data/test/dummy/VERSION +1 -0
  57. data/test/dummy/app/assets/stylesheets/reset.css +2 -0
  58. data/test/dummy/app/assets/stylesheets/template.css +52 -0
  59. data/test/dummy/app/controllers/application_controller.rb +52 -0
  60. data/test/dummy/app/controllers/pastas_controller.rb +23 -0
  61. data/test/dummy/app/controllers/pizzas_controller.rb +23 -0
  62. data/test/dummy/app/controllers/sessions_controller.rb +26 -0
  63. data/test/dummy/app/controllers/users_controller.rb +59 -0
  64. data/test/dummy/app/models/user.rb +50 -0
  65. data/test/dummy/app/views/layouts/application.html.erb +65 -0
  66. data/test/dummy/app/views/sessions/new.html.erb +25 -0
  67. data/test/dummy/app/views/shared/403.json.erb +4 -0
  68. data/test/dummy/app/views/shared/404.json.erb +6 -0
  69. data/test/dummy/app/views/shared/422.json.erb +5 -0
  70. data/test/dummy/app/views/shared/500.json.erb +4 -0
  71. data/test/dummy/app/views/shared/html/404.html.erb +0 -0
  72. data/test/dummy/app/views/shared/html/422.html.erb +0 -0
  73. data/test/dummy/app/views/users/_form.html.erb +27 -0
  74. data/test/dummy/app/views/users/edit.html.erb +8 -0
  75. data/test/dummy/app/views/users/index.html.erb +20 -0
  76. data/test/dummy/app/views/users/new.html.erb +46 -0
  77. data/test/dummy/app/views/users/show.html.erb +15 -0
  78. data/test/dummy/app/views/users/show.json.erb +6 -0
  79. data/test/dummy/config.ru +4 -0
  80. data/test/dummy/config/application.rb +57 -0
  81. data/test/dummy/config/boot.rb +13 -0
  82. data/test/dummy/config/cucumber.yml +8 -0
  83. data/test/dummy/config/environment.rb +5 -0
  84. data/test/dummy/config/environments/development.rb +32 -0
  85. data/test/dummy/config/environments/production.rb +58 -0
  86. data/test/dummy/config/environments/test.rb +35 -0
  87. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  88. data/test/dummy/config/initializers/inflections.rb +10 -0
  89. data/test/dummy/config/initializers/mime_types.rb +5 -0
  90. data/test/dummy/config/initializers/secret_token.rb +7 -0
  91. data/test/dummy/config/initializers/session_store.rb +8 -0
  92. data/test/dummy/config/initializers/test.rb +3 -0
  93. data/test/dummy/config/locales/en.yml +1 -0
  94. data/test/dummy/config/mongoid.yml +20 -0
  95. data/test/dummy/config/routes.rb +22 -0
  96. data/test/dummy/db/seeds.rb +7 -0
  97. data/test/dummy/doc/README_FOR_APP +2 -0
  98. data/test/dummy/lib/tasks/cucumber.rake +53 -0
  99. data/test/dummy/lib/tasks/watchr.rake +5 -0
  100. data/test/dummy/public/404.html +26 -0
  101. data/test/dummy/public/422.html +26 -0
  102. data/test/dummy/public/500.html +4 -0
  103. data/test/dummy/public/favicon.ico +0 -0
  104. data/test/dummy/public/robots.txt +5 -0
  105. data/test/dummy/script/cucumber +10 -0
  106. data/test/dummy/script/rails +6 -0
  107. data/test/dummy/spec/acceptance/acceptance_helper.rb +5 -0
  108. data/test/dummy/spec/acceptance/accesses_controller_spec.rb +77 -0
  109. data/test/dummy/spec/acceptance/clients_controller_spec.rb +218 -0
  110. data/test/dummy/spec/acceptance/oauth_authorize_controller_spec.rb +241 -0
  111. data/test/dummy/spec/acceptance/oauth_token_controller_spec.rb +196 -0
  112. data/test/dummy/spec/acceptance/resource_controller_spec.rb +143 -0
  113. data/test/dummy/spec/acceptance/scopes_controller_spec.rb +227 -0
  114. data/test/dummy/spec/acceptance/support/helpers.rb +81 -0
  115. data/test/dummy/spec/acceptance/support/paths.rb +9 -0
  116. data/test/dummy/spec/acceptance/support/view_helpers.rb +52 -0
  117. data/test/dummy/spec/acceptance/users_controller_spec.rb +198 -0
  118. data/test/dummy/spec/extras/scope_spec.rb +105 -0
  119. data/test/dummy/spec/factories/oauth.rb +106 -0
  120. data/test/dummy/spec/models/oauth/client_spec.rb +123 -0
  121. data/test/dummy/spec/models/oauth/oauth_access_spec.rb +48 -0
  122. data/test/dummy/spec/models/oauth/oauth_authorization_spec.rb +50 -0
  123. data/test/dummy/spec/models/oauth/oauth_daily_request_spec.rb +14 -0
  124. data/test/dummy/spec/models/oauth/oauth_refresh_token_spec.rb +11 -0
  125. data/test/dummy/spec/models/oauth/oauth_token_spec.rb +55 -0
  126. data/test/dummy/spec/models/scope_spec.rb +17 -0
  127. data/test/dummy/spec/spec_helper.rb +39 -0
  128. data/test/dummy/spec/support/settings_helper.rb +28 -0
  129. data/test/dummy/test/initializers/capybara_headers_hack.rb +23 -0
  130. data/test/oauth2_provider_test.rb +7 -0
  131. data/test/test_helper.rb +15 -0
  132. metadata +387 -0
@@ -0,0 +1,5 @@
1
+ desc "Run watchr"
2
+ task :watchr do
3
+ sh %{bundle exec watchr .watchr.rb}
4
+ end
5
+
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,4 @@
1
+ {
2
+ "message": "We are sorry, but it seems we have some problems",
3
+ "info": "In the case the problem persist, please send us a mail describing your problem"
4
+ }
File without changes
@@ -0,0 +1,5 @@
1
+ # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
2
+ #
3
+ # To ban all spiders from the entire site uncomment the next two lines:
4
+ # User-Agent: *
5
+ # Disallow: /
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ vendored_cucumber_bin = Dir["#{File.dirname(__FILE__)}/../vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
4
+ if vendored_cucumber_bin
5
+ load File.expand_path(vendored_cucumber_bin)
6
+ else
7
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
8
+ require 'cucumber'
9
+ load Cucumber::BINARY
10
+ end
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,5 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+ require "steak"
3
+
4
+ # Put your acceptance spec helpers inside /spec/acceptance/support
5
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
@@ -0,0 +1,77 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/acceptance_helper')
2
+
3
+ feature "Oauth2Provider::AccessesController" do
4
+ before { host! "http://" + host }
5
+ before { @user = FactoryGirl.create(:user) }
6
+ before { @client = FactoryGirl.create(:client) }
7
+ before { @token = FactoryGirl.create(:oauth_token) }
8
+ before { @access = FactoryGirl.create(:oauth_access) }
9
+ before { Oauth2Provider::AccessesController.any_instance.stub(:user_url).with(@user).and_return( USER_URI ) }
10
+
11
+ context ".index" do
12
+ before { @uri = "/oauth/accesses" }
13
+
14
+ context "when not logged in" do
15
+ scenario "is not authorized" do
16
+ visit @uri
17
+ current_url.should == host + "/log_in"
18
+ end
19
+ end
20
+
21
+ context "when logged in" do
22
+ before { login(@user) }
23
+
24
+ scenario "view all resources" do
25
+ visit @uri
26
+ page.should have_content @access.client_uri
27
+ page.should have_content "Block!"
28
+ end
29
+
30
+ scenario "block a resource" do
31
+ visit @uri
32
+ page.should have_link "Block!"
33
+ page.click_link "Block!"
34
+ page.should have_link "Unblock!"
35
+ end
36
+ end
37
+ end
38
+
39
+
40
+ context ".show" do
41
+ before { @uri = "/oauth/accesses/" + @access.id.as_json }
42
+
43
+ context "when not logged in" do
44
+ scenario "is not authorized" do
45
+ visit @uri
46
+ current_url.should == host + "/log_in"
47
+ end
48
+ end
49
+
50
+ context "when logged in" do
51
+ before { login(@user) }
52
+ before { @access_not_owned = FactoryGirl.create(:oauth_access, resource_owner_uri: ANOTHER_USER_URI) }
53
+
54
+ scenario "view a resource" do
55
+ visit @uri
56
+ page.should have_content @access.client_uri
57
+ end
58
+
59
+ scenario "resource not found" do
60
+ @access.destroy
61
+ visit @uri
62
+ page.should have_content "Resource not found"
63
+ end
64
+
65
+ scenario "resource not owned" do
66
+ visit "/oauth/accesses/" + @access_not_owned.id.as_json
67
+ page.should have_content "Resource not found"
68
+ end
69
+
70
+ scenario "illegal id" do
71
+ visit "/oauth/accesses/0"
72
+ page.should have_content "Resource not found"
73
+ end
74
+ end
75
+ end
76
+
77
+ end
@@ -0,0 +1,218 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/acceptance_helper')
2
+
3
+ feature "ClientsController" do
4
+ before { Oauth2Provider::Client.destroy_all }
5
+ before { User.destroy_all }
6
+ before { Oauth2Provider::Scope.destroy_all }
7
+ before { host! "http://" + host }
8
+ before { @user = FactoryGirl.create(:user) }
9
+ before { @user_bob = FactoryGirl.create(:user_bob) }
10
+ before { @admin = FactoryGirl.create(:admin) }
11
+ before { @client = FactoryGirl.create(:client) }
12
+ before { @client_not_owned = FactoryGirl.create(:client_not_owned) }
13
+ before { @scope_read = FactoryGirl.create(:scope_pizzas_read) }
14
+ before { @scope_all = FactoryGirl.create(:scope_pizzas_all) }
15
+ before { Oauth2Provider::ClientsController.any_instance.stub(:user_url).with(@user).and_return( USER_URI ) }
16
+
17
+
18
+ context ".index" do
19
+ before { @uri = "/oauth/clients" }
20
+ before { @read_client = FactoryGirl.create(:client_read) }
21
+
22
+ context "when not logged in" do
23
+ scenario "is not authorized" do
24
+ visit @uri
25
+ current_url.should == host + "/log_in"
26
+ end
27
+ end
28
+
29
+ context "when logged in" do
30
+ context "when not admin" do
31
+ before { login(@user) }
32
+
33
+ scenario "view all resources" do
34
+ visit @uri
35
+ should_visualize_client(@client)
36
+ should_visualize_client(@read_client)
37
+ page.should_not have_content "Not owned client"
38
+ page.should_not have_content "Block!"
39
+ end
40
+ end
41
+
42
+ context "when admin" do
43
+ before do
44
+ login(@admin)
45
+ visit @uri
46
+ should_visualize_client(@client)
47
+ should_visualize_client(@read_client)
48
+ end
49
+
50
+ scenario "view all resource" do
51
+ page.should have_content "Not owned client"
52
+ end
53
+
54
+ scenario "block a resource" do
55
+ page.should have_link "Block!"
56
+ page.click_link "Block!"
57
+ page.should have_link "Unblock!"
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+
64
+ context ".show" do
65
+ before { @uri = "/oauth/clients/" + @client.id.as_json }
66
+
67
+ context "when not logged in" do
68
+ scenario "is not authorized" do
69
+ visit @uri
70
+ current_url.should == host + "/log_in"
71
+ end
72
+ end
73
+
74
+ context "when logged in" do
75
+ context "when not admin" do
76
+ before { login(@user) }
77
+
78
+ scenario "view a resource" do
79
+ visit @uri
80
+ should_visualize_client(@client)
81
+ end
82
+
83
+ scenario "resource not found" do
84
+ @client.destroy
85
+ visit @uri
86
+ page.should have_content "Resource not found"
87
+ end
88
+
89
+ scenario "resource not owned" do
90
+ visit "/oauth/clients/" + @client_not_owned.id.as_json
91
+ page.should have_content "Resource not found"
92
+ end
93
+
94
+ scenario "illegal id" do
95
+ visit "/oauth/clients/0"
96
+ page.should have_content "Resource not found"
97
+ end
98
+ end
99
+
100
+ context "when admin" do
101
+ before { login(@admin) }
102
+ scenario "view not owned resource" do
103
+ visit "/oauth/clients/" + @client_not_owned.id.as_json
104
+ should_visualize_client @client_not_owned
105
+ end
106
+ end
107
+
108
+ end
109
+ end
110
+
111
+
112
+ context ".create" do
113
+ before { @uri = "/oauth/clients/new" }
114
+
115
+ context "when not logged in" do
116
+ scenario "is not authorized" do
117
+ visit @uri
118
+ current_url.should == host + "/log_in"
119
+ end
120
+ end
121
+
122
+ context "when logged in" do
123
+ before { login(@user) }
124
+
125
+ context "when valid" do
126
+ before do
127
+ visit @uri
128
+ fill_client()
129
+ click_button 'Create Client'
130
+ @client = Oauth2Provider::Client.last
131
+ end
132
+
133
+ scenario "create a resource" do
134
+ should_visualize_client_details(@client)
135
+ page.should have_content "was successfully created"
136
+ end
137
+
138
+ scenario "assign URI field" do
139
+ @client.uri.should == host + "/oauth/clients/" + @client.id.as_json
140
+ end
141
+ end
142
+
143
+ context "when not valid" do
144
+ scenario "fails" do
145
+ visit @uri
146
+ fill_client("")
147
+ click_button 'Create Client'
148
+ page.should have_content "Name can't be blank"
149
+ end
150
+ end
151
+ end
152
+ end
153
+
154
+
155
+ context ".update" do
156
+ before { @uri = "/oauth/clients/" + @client.id.as_json + "/edit" }
157
+
158
+ context "when not logged in" do
159
+ scenario "is not authorized" do
160
+ visit @uri
161
+ current_url.should == host + "/log_in"
162
+ end
163
+ end
164
+
165
+ context "when logged in" do
166
+ context "when not admin" do
167
+ before { login(@user) }
168
+
169
+ scenario "update a resource" do
170
+ visit @uri
171
+ fill_client("Example Updated")
172
+ click_button 'Update Client'
173
+ should_visualize_client_details(@client.reload)
174
+ page.should have_content "Example Updated"
175
+ page.should have_content "was successfully updated"
176
+ end
177
+
178
+ scenario "resource not found" do
179
+ @client.destroy
180
+ visit @uri
181
+ page.should have_content "Resource not found"
182
+ end
183
+
184
+ scenario "resource not owned" do
185
+ visit "/oauth/clients/" + @client_not_owned.id.as_json + "/edit"
186
+ page.should have_content "Resource not found"
187
+ end
188
+
189
+ scenario "illegal id" do
190
+ visit "/oauth/clients/0"
191
+ page.should have_content "Resource not found"
192
+ end
193
+
194
+ context "when not valid" do
195
+ scenario "fails" do
196
+ visit @uri
197
+ fill_client("")
198
+ click_button 'Update Client'
199
+ page.should have_content "Name can't be blank"
200
+ end
201
+ end
202
+ end
203
+
204
+ context "when admin" do
205
+ before { login(@admin) }
206
+ scenario "view not owned resource" do
207
+ visit "/oauth/clients/" + @client_not_owned.id.as_json + "/edit"
208
+ page.should have_field("Name", with: "Not owned client")
209
+ end
210
+ end
211
+ end
212
+ end
213
+
214
+ context ".destroy" do
215
+ end
216
+
217
+ end
218
+
@@ -0,0 +1,241 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/acceptance_helper')
2
+
3
+ feature "OauthAuthorizeController" do
4
+ before { Oauth2Provider::Client.destroy_all }
5
+ before { Oauth2Provider::OauthAccess.destroy_all }
6
+ before { Oauth2Provider::OauthToken.destroy_all }
7
+
8
+ let(:user) { FactoryGirl.create(:user) }
9
+ let(:client) { FactoryGirl.create(:client) }
10
+ let(:client_read) { FactoryGirl.create(:client_read) }
11
+ let(:access) { FactoryGirl.create(:oauth_access) }
12
+ let(:write_scope) { "pizzas" }
13
+ let(:read_scope) { "pizzas/read" }
14
+
15
+ before { @scope = FactoryGirl.create(:scope_pizzas_read) }
16
+ before { @scope = FactoryGirl.create(:scope_pizzas_all) }
17
+ before { Oauth2Provider::AuthorizeController.any_instance.stub(:user_url).with(user).and_return( USER_URI ) }
18
+
19
+
20
+ context "Authorization code flow" do
21
+ before { login(user) }
22
+
23
+ context "when valid" do
24
+ background do
25
+ visit authorization_grant_page(client, write_scope)
26
+ page.should have_content client.name
27
+ end
28
+
29
+ scenario "#grant" do
30
+ click_button("Grant")
31
+ current_url.should == authorization_grant_uri(client)
32
+ end
33
+
34
+ scenario "#deny" do
35
+ click_button("Deny")
36
+ current_url.should == authorization_denied_uri(client)
37
+ end
38
+ end
39
+
40
+ context "when client is blocked" do
41
+ it "should not load authorization page" do
42
+ client.block!
43
+ visit authorization_grant_page(client, write_scope)
44
+ page.should have_content("Client blocked")
45
+ end
46
+ end
47
+
48
+ context "when access is blocked (resource owner block a client)" do
49
+ it "should not load authorization page" do
50
+ access.block!
51
+ visit authorization_grant_page(client, write_scope)
52
+ page.should have_content("Client blocked")
53
+ end
54
+ end
55
+
56
+ context "when send an extra state params" do
57
+ background do
58
+ visit(authorization_grant_page(client, write_scope) + "&state=extra")
59
+ end
60
+
61
+ scenario "#grant" do
62
+ click_button("Grant")
63
+ current_url.should == authorization_grant_uri(client) + "&state=extra"
64
+ end
65
+
66
+ scenario "#deny" do
67
+ click_button("Deny")
68
+ current_url.should == authorization_denied_uri(client) + "&state=extra"
69
+ end
70
+ end
71
+
72
+ context "when not valid" do
73
+ scenario "fails with not valid client uri" do
74
+ client.uri = "http://not.existing/"
75
+ visit authorization_grant_page(client, write_scope)
76
+ page.should_not have_content client.name
77
+ page.should have_content("Client not found")
78
+ end
79
+
80
+ scenario "fails with not valid scope" do
81
+ visit authorization_grant_page(client_read, write_scope)
82
+ page.should_not have_content client.name
83
+ page.should have_content("Client not authorized")
84
+ end
85
+ end
86
+
87
+ context "when not valid scope hacked in HTML page" do
88
+ background do
89
+ visit authorization_grant_page(client_read, read_scope)
90
+ page.should have_content client_read.name
91
+ end
92
+
93
+ scenario "fails #grant" do
94
+ page.find("#grant").fill_in("scope", with: "pizzas/create")
95
+ click_button("Grant")
96
+ page.should have_content("Client not authorized")
97
+ end
98
+
99
+ scenario "fails #deny" do
100
+ page.find("#deny").fill_in("scope", with: "pizzas/create")
101
+ click_button("Deny")
102
+ page.should have_content("Client not authorized")
103
+ end
104
+ end
105
+ end
106
+
107
+
108
+ context "Implicit token flow" do
109
+ before { use_javascript }
110
+ before { login(user) }
111
+
112
+ context "when valid" do
113
+ background do
114
+ visit implicit_grant_page(client, write_scope)
115
+ page.should have_content client.name
116
+ end
117
+
118
+ scenario "#grant" do
119
+ click_button("Grant")
120
+ current_url.should == implicit_grant_uri(client)
121
+ end
122
+
123
+ scenario "#deny" do
124
+ click_button("Deny")
125
+ current_url.should == implicit_denied_uri(client)
126
+ end
127
+ end
128
+
129
+ context "when client is blocked" do
130
+ it "should not load authorization page" do
131
+ client.block!
132
+ visit implicit_grant_page(client, write_scope)
133
+ page.should have_content("Client blocked")
134
+ end
135
+ end
136
+
137
+ context "when access is blocked (resource owner block a client)" do
138
+ it "should not load authorization page" do
139
+ access.block!
140
+ visit implicit_grant_page(client, write_scope)
141
+ page.should have_content("Client blocked")
142
+ end
143
+ end
144
+
145
+ context "when send an extra state params" do
146
+ background do
147
+ visit(implicit_grant_page(client, write_scope) + "&state=extra")
148
+ end
149
+
150
+ scenario "#grant" do
151
+ click_button("Grant")
152
+ current_url.should == implicit_grant_uri(client) + "&state=extra"
153
+ end
154
+
155
+ scenario "#deny" do
156
+ click_button("Deny")
157
+ current_url.should == implicit_denied_uri(client) + "&state=extra"
158
+ end
159
+ end
160
+
161
+ context "when not valid" do
162
+ scenario "fails with not valid client uri" do
163
+ client.uri = "http://not.existing/"
164
+ visit implicit_grant_page(client, write_scope)
165
+ page.should_not have_content client.name
166
+ page.should have_content("Client not found")
167
+ end
168
+
169
+ scenario "fails with not valid scope" do
170
+ visit implicit_grant_page(client_read, write_scope)
171
+ page.should_not have_content client_read.name
172
+ page.should have_content("Client not authorized")
173
+ end
174
+ end
175
+
176
+ after { use_default }
177
+ end
178
+
179
+
180
+ context "Refresh implicit token flow" do
181
+ before { use_javascript }
182
+ before { @token = FactoryGirl.create(:oauth_token) }
183
+ before { login(user) }
184
+
185
+ scenario "should create new token" do
186
+ visit implicit_grant_page(client, write_scope)
187
+ current_url.should == implicit_grant_uri(client)
188
+ end
189
+
190
+ context "when send an extra state params" do
191
+ scenario "it should be in the callback" do
192
+ visit(implicit_grant_page(client, write_scope) + "&state=extra")
193
+ current_url.should == implicit_grant_uri(client) + "&state=extra"
194
+ end
195
+ end
196
+
197
+ context "when client is blocked" do
198
+ it "should not load authorization page" do
199
+ client.block!
200
+ visit implicit_grant_page(client, write_scope)
201
+ page.should have_content("Client blocked")
202
+ end
203
+ end
204
+
205
+ # TODO: in reality it should not authomatically redirect
206
+ # and should show the authorization page (no errors)
207
+ # TODO: miss the scope test
208
+ context "when access is blocked (resource owner block a client)" do
209
+ it "should not load authorization page" do
210
+ access.block!
211
+ visit implicit_grant_page(client, write_scope)
212
+ page.should have_content("Client blocked")
213
+ end
214
+ end
215
+
216
+ context "when token is blocked (resource owner log out)" do
217
+ it "should not load authorization page" do
218
+ @token.block!
219
+ visit implicit_grant_page(client, write_scope)
220
+ page.should have_content("Access token blocked from the user")
221
+ end
222
+ end
223
+
224
+ context "when not valid" do
225
+ scenario "fails with not valid client uri" do
226
+ client.uri = "http://not.existing/"
227
+ visit implicit_grant_page(client, write_scope)
228
+ page.should_not have_content client.name
229
+ page.should have_content("Client not found")
230
+ end
231
+
232
+ scenario "fails with not valid scope" do
233
+ visit implicit_grant_page(client_read, write_scope)
234
+ page.should_not have_content client_read.name
235
+ page.should have_content("Client not authorized")
236
+ end
237
+ end
238
+
239
+ after { use_default }
240
+ end
241
+ end