/
applications_request_spec.rb
259 lines (197 loc) · 7.09 KB
/
applications_request_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# frozen_string_literal: true
require "spec_helper"
feature "Adding applications" do
context "in application form" do
background do
i_am_logged_in
visit "/oauth/applications/new"
end
scenario "adding a valid app" do
fill_in "doorkeeper_application[name]", with: "My Application"
fill_in "doorkeeper_application[redirect_uri]",
with: "https://example.com"
click_button "Submit"
i_should_see "Application created"
i_should_see "My Application"
end
scenario "adding invalid app" do
click_button "Submit"
i_should_see "Whoops! Check your form for possible errors"
end
scenario "adding app ignoring bad scope" do
config_is_set("enforce_configured_scopes", false)
fill_in "doorkeeper_application[name]", with: "My Application"
fill_in "doorkeeper_application[redirect_uri]",
with: "https://example.com"
fill_in "doorkeeper_application[scopes]", with: "blahblah"
click_button "Submit"
i_should_see "Application created"
i_should_see "My Application"
end
scenario "adding app validating bad scope" do
config_is_set("enforce_configured_scopes", true)
fill_in "doorkeeper_application[name]", with: "My Application"
fill_in "doorkeeper_application[redirect_uri]",
with: "https://example.com"
fill_in "doorkeeper_application[scopes]", with: "blahblah"
click_button "Submit"
i_should_see "Whoops! Check your form for possible errors"
end
scenario "adding app validating scope, blank scope is accepted" do
config_is_set("enforce_configured_scopes", true)
fill_in "doorkeeper_application[name]", with: "My Application"
fill_in "doorkeeper_application[redirect_uri]",
with: "https://example.com"
fill_in "doorkeeper_application[scopes]", with: ""
click_button "Submit"
i_should_see "Application created"
i_should_see "My Application"
end
scenario "adding app validating scope, multiple scopes configured" do
config_is_set("enforce_configured_scopes", true)
scopes = Doorkeeper::OAuth::Scopes.from_array(%w[read write admin])
config_is_set("optional_scopes", scopes)
fill_in "doorkeeper_application[name]", with: "My Application"
fill_in "doorkeeper_application[redirect_uri]",
with: "https://example.com"
fill_in "doorkeeper_application[scopes]", with: "read write"
click_button "Submit"
i_should_see "Application created"
i_should_see "My Application"
end
scenario "adding app validating scope, bad scope with multiple scopes configured" do
config_is_set("enforce_configured_scopes", true)
scopes = Doorkeeper::OAuth::Scopes.from_array(%w[read write admin])
config_is_set("optional_scopes", scopes)
fill_in "doorkeeper_application[name]", with: "My Application"
fill_in "doorkeeper_application[redirect_uri]",
with: "https://example.com"
fill_in "doorkeeper_application[scopes]", with: "read blah"
click_button "Submit"
i_should_see "Whoops! Check your form for possible errors"
i_should_see Regexp.new(
I18n.t("activerecord.errors.models.doorkeeper/application.attributes.scopes.not_match_configured"),
true
)
end
context "redirect URI" do
scenario "adding app with blank redirect URI when configured flows requires redirect uri" do
config_is_set("grant_flows", %w[authorization_code implicit client_credentials])
fill_in "doorkeeper_application[name]", with: "My Application"
fill_in "doorkeeper_application[redirect_uri]",
with: ""
click_button "Submit"
i_should_see "Whoops! Check your form for possible errors"
end
scenario "adding app with blank redirect URI when configured flows without redirect uri" do
config_is_set("grant_flows", %w[client_credentials password])
# Visit it once again to consider grant flows
visit "/oauth/applications/new"
i_should_see I18n.t("doorkeeper.applications.help.blank_redirect_uri")
fill_in "doorkeeper_application[name]", with: "My Application"
fill_in "doorkeeper_application[redirect_uri]",
with: ""
click_button "Submit"
i_should_see "Application created"
i_should_see "My Application"
end
end
end
end
feature "Listing applications" do
background do
i_am_logged_in
FactoryBot.create :application, name: "Oauth Dude"
FactoryBot.create :application, name: "Awesome App"
end
scenario "application list" do
visit "/oauth/applications"
i_should_see "Awesome App"
i_should_see "Oauth Dude"
end
end
feature "Renders assets" do
scenario "admin stylesheets" do
visit "/assets/doorkeeper/admin/application.css"
i_should_see "Bootstrap"
i_should_see ".doorkeeper-admin"
end
scenario "application stylesheets" do
visit "/assets/doorkeeper/application.css"
i_should_see "Bootstrap"
i_should_see "#oauth-permissions"
i_should_see "#container"
end
end
feature "Show application" do
given :app do
i_am_logged_in
FactoryBot.create :application, name: "Just another oauth app"
end
scenario "visiting application page" do
visit "/oauth/applications/#{app.id}"
i_should_see "Just another oauth app"
end
end
feature "Edit application" do
let :app do
FactoryBot.create :application, name: "OMG my app"
end
background do
i_am_logged_in
visit "/oauth/applications/#{app.id}/edit"
end
scenario "updating a valid app" do
fill_in "doorkeeper_application[name]", with: "Serious app"
click_button "Submit"
i_should_see "Application updated"
i_should_see "Serious app"
i_should_not_see "OMG my app"
end
scenario "updating an invalid app" do
fill_in "doorkeeper_application[name]", with: ""
click_button "Submit"
i_should_see "Whoops! Check your form for possible errors"
end
end
feature "Remove application" do
background do
i_am_logged_in
@app = FactoryBot.create :application
end
scenario "deleting an application from list" do
visit "/oauth/applications"
i_should_see @app.name
within(:css, "tr#application_#{@app.id}") do
click_button "Destroy"
end
i_should_see "Application deleted"
i_should_not_see @app.name
end
scenario "deleting an application from show" do
visit "/oauth/applications/#{@app.id}"
click_button "Destroy"
i_should_see "Application deleted"
end
end
context "when admin authenticator block is default" do
let(:app) { FactoryBot.create :application, name: "app" }
feature "application list" do
scenario "fails with forbidden" do
visit "/oauth/applications"
should_have_status 403
end
end
feature "adding an app" do
scenario "fails with forbidden" do
visit "/oauth/applications/new"
should_have_status 403
end
end
feature "editing an app" do
scenario "fails with forbidden" do
visit "/oauth/applications/#{app.id}/edit"
should_have_status 403
end
end
end