3 class Oauth2ApplicationsControllerTest < ActionDispatch::IntegrationTest
5 # test all routes which lead to this controller
8 { :path => "/oauth2/applications", :method => :get },
9 { :controller => "oauth2_applications", :action => "index" }
12 { :path => "/oauth2/applications", :method => :post },
13 { :controller => "oauth2_applications", :action => "create" }
16 { :path => "/oauth2/applications/new", :method => :get },
17 { :controller => "oauth2_applications", :action => "new" }
20 { :path => "/oauth2/applications/1/edit", :method => :get },
21 { :controller => "oauth2_applications", :action => "edit", :id => "1" }
24 { :path => "/oauth2/applications/1", :method => :get },
25 { :controller => "oauth2_applications", :action => "show", :id => "1" }
28 { :path => "/oauth2/applications/1", :method => :patch },
29 { :controller => "oauth2_applications", :action => "update", :id => "1" }
32 { :path => "/oauth2/applications/1", :method => :put },
33 { :controller => "oauth2_applications", :action => "update", :id => "1" }
36 { :path => "/oauth2/applications/1", :method => :delete },
37 { :controller => "oauth2_applications", :action => "destroy", :id => "1" }
43 create_list(:oauth_application, 2, :owner => user)
45 get oauth_applications_path
46 assert_response :redirect
47 assert_redirected_to login_path(:referer => oauth_applications_path)
51 get oauth_applications_path
52 assert_response :success
53 assert_template "oauth2_applications/index"
60 get new_oauth_application_path
61 assert_response :redirect
62 assert_redirected_to login_path(:referer => new_oauth_application_path)
66 get new_oauth_application_path
67 assert_response :success
68 assert_template "oauth2_applications/new"
69 assert_select "form", 1 do
70 assert_select "input#oauth2_application_name", 1
71 assert_select "textarea#oauth2_application_redirect_uri", 1
72 assert_select "input#oauth2_application_confidential", 1
73 Oauth.scopes.each do |scope|
74 assert_select "input#oauth2_application_scopes_#{scope.name}", 1
82 assert_difference "Doorkeeper::Application.count", 0 do
83 post oauth_applications_path
85 assert_response :forbidden
89 assert_difference "Doorkeeper::Application.count", 0 do
90 post oauth_applications_path(:oauth2_application => {
91 :name => "Test Application"
94 assert_response :success
95 assert_template "oauth2_applications/new"
97 assert_difference "Doorkeeper::Application.count", 0 do
98 post oauth_applications_path(:oauth2_application => {
99 :name => "Test Application",
100 :redirect_uri => "https://test.example.com/",
101 :scopes => ["bad_scope"]
104 assert_response :success
105 assert_template "oauth2_applications/new"
107 assert_difference "Doorkeeper::Application.count", 1 do
108 post oauth_applications_path(:oauth2_application => {
109 :name => "Test Application",
110 :redirect_uri => "https://test.example.com/",
111 :scopes => ["read_prefs"]
114 assert_response :redirect
115 assert_redirected_to oauth_application_path(:id => Doorkeeper::Application.find_by(:name => "Test Application").id)
118 def test_create_privileged
119 session_for(create(:user))
121 assert_difference "Doorkeeper::Application.count", 0 do
122 post oauth_applications_path(:oauth2_application => {
123 :name => "Test Application",
124 :redirect_uri => "https://test.example.com/",
125 :scopes => ["read_email"]
128 assert_response :success
129 assert_template "oauth2_applications/new"
131 session_for(create(:administrator_user))
133 assert_difference "Doorkeeper::Application.count", 1 do
134 post oauth_applications_path(:oauth2_application => {
135 :name => "Test Application",
136 :redirect_uri => "https://test.example.com/",
137 :scopes => ["read_email"]
140 assert_response :redirect
141 assert_redirected_to oauth_application_path(:id => Doorkeeper::Application.find_by(:name => "Test Application").id)
146 client = create(:oauth_application, :owner => user)
147 other_client = create(:oauth_application)
149 get oauth_application_path(:id => client)
150 assert_response :redirect
151 assert_redirected_to login_path(:referer => oauth_application_path(:id => client.id))
155 get oauth_application_path(:id => other_client)
156 assert_response :not_found
157 assert_template "oauth2_applications/not_found"
159 get oauth_application_path(:id => client)
160 assert_response :success
161 assert_template "oauth2_applications/show"
166 client = create(:oauth_application, :owner => user)
167 other_client = create(:oauth_application)
169 get edit_oauth_application_path(:id => client)
170 assert_response :redirect
171 assert_redirected_to login_path(:referer => edit_oauth_application_path(:id => client.id))
175 get edit_oauth_application_path(:id => other_client)
176 assert_response :not_found
177 assert_template "oauth2_applications/not_found"
179 get edit_oauth_application_path(:id => client)
180 assert_response :success
181 assert_template "oauth2_applications/edit"
182 assert_select "form", 1 do
183 assert_select "input#oauth2_application_name", 1
184 assert_select "textarea#oauth2_application_redirect_uri", 1
185 assert_select "input#oauth2_application_confidential", 1
186 Oauth.scopes.each do |scope|
187 assert_select "input#oauth2_application_scopes_#{scope.name}", 1
194 client = create(:oauth_application, :owner => user)
195 other_client = create(:oauth_application)
197 put oauth_application_path(:id => client)
198 assert_response :forbidden
202 put oauth_application_path(:id => other_client)
203 assert_response :not_found
204 assert_template "oauth2_applications/not_found"
206 put oauth_application_path(:id => client,
207 :oauth2_application => {
211 assert_response :success
212 assert_template "oauth2_applications/edit"
214 put oauth_application_path(:id => client,
215 :oauth2_application => {
217 :redirect_uri => "https://new.example.com/url"
219 assert_response :redirect
220 assert_redirected_to oauth_application_path(:id => client.id)
225 client = create(:oauth_application, :owner => user)
226 other_client = create(:oauth_application)
228 assert_difference "Doorkeeper::Application.count", 0 do
229 delete oauth_application_path(:id => client)
231 assert_response :forbidden
235 assert_difference "Doorkeeper::Application.count", 0 do
236 delete oauth_application_path(:id => other_client)
238 assert_response :not_found
239 assert_template "oauth2_applications/not_found"
241 assert_difference "Doorkeeper::Application.count", -1 do
242 delete oauth_application_path(:id => client)
244 assert_response :redirect
245 assert_redirected_to oauth_applications_path