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_redirected_to login_path(:referer => oauth_applications_path)
50 get oauth_applications_path
51 assert_response :success
52 assert_template "oauth2_applications/index"
53 assert_select "tbody tr", 2
59 get new_oauth_application_path
60 assert_redirected_to login_path(:referer => new_oauth_application_path)
64 get new_oauth_application_path
65 assert_response :success
66 assert_template "oauth2_applications/new"
67 assert_select "form", 1 do
68 assert_select "input#oauth2_application_name", 1
69 assert_select "textarea#oauth2_application_redirect_uri", 1
70 assert_select "input#oauth2_application_confidential", 1
71 Oauth.scopes.each do |scope|
72 assert_select "input#oauth2_application_scopes_#{scope.name}", 1
80 assert_difference "Doorkeeper::Application.count", 0 do
81 post oauth_applications_path
83 assert_response :forbidden
87 assert_difference "Doorkeeper::Application.count", 0 do
88 post oauth_applications_path(:oauth2_application => {
89 :name => "Test Application"
92 assert_response :success
93 assert_template "oauth2_applications/new"
95 assert_difference "Doorkeeper::Application.count", 0 do
96 post oauth_applications_path(:oauth2_application => {
97 :name => "Test Application",
98 :redirect_uri => "https://test.example.com/",
99 :scopes => ["bad_scope"]
102 assert_response :success
103 assert_template "oauth2_applications/new"
105 assert_difference "Doorkeeper::Application.count", 1 do
106 post oauth_applications_path(:oauth2_application => {
107 :name => "Test Application",
108 :redirect_uri => "https://test.example.com/",
109 :scopes => ["read_prefs"]
112 assert_redirected_to oauth_application_path(:id => Doorkeeper::Application.find_by(:name => "Test Application").id)
115 def test_create_privileged
116 session_for(create(:user))
118 assert_difference "Doorkeeper::Application.count", 0 do
119 post oauth_applications_path(:oauth2_application => {
120 :name => "Test Application",
121 :redirect_uri => "https://test.example.com/",
122 :scopes => ["read_email"]
125 assert_response :success
126 assert_template "oauth2_applications/new"
128 session_for(create(:administrator_user))
130 assert_difference "Doorkeeper::Application.count", 1 do
131 post oauth_applications_path(:oauth2_application => {
132 :name => "Test Application",
133 :redirect_uri => "https://test.example.com/",
134 :scopes => ["read_email"]
137 assert_redirected_to oauth_application_path(:id => Doorkeeper::Application.find_by(:name => "Test Application").id)
142 client = create(:oauth_application, :owner => user)
143 other_client = create(:oauth_application)
145 get oauth_application_path(:id => client)
146 assert_redirected_to login_path(:referer => oauth_application_path(:id => client.id))
150 get oauth_application_path(:id => other_client)
151 assert_response :not_found
152 assert_template "oauth2_applications/not_found"
154 get oauth_application_path(:id => client)
155 assert_response :success
156 assert_template "oauth2_applications/show"
161 client = create(:oauth_application, :owner => user)
162 other_client = create(:oauth_application)
164 get edit_oauth_application_path(:id => client)
165 assert_redirected_to login_path(:referer => edit_oauth_application_path(:id => client.id))
169 get edit_oauth_application_path(:id => other_client)
170 assert_response :not_found
171 assert_template "oauth2_applications/not_found"
173 get edit_oauth_application_path(:id => client)
174 assert_response :success
175 assert_template "oauth2_applications/edit"
176 assert_select "form", 1 do
177 assert_select "input#oauth2_application_name", 1
178 assert_select "textarea#oauth2_application_redirect_uri", 1
179 assert_select "input#oauth2_application_confidential", 1
180 Oauth.scopes.each do |scope|
181 assert_select "input#oauth2_application_scopes_#{scope.name}", 1
188 client = create(:oauth_application, :owner => user)
189 other_client = create(:oauth_application)
191 put oauth_application_path(:id => client)
192 assert_response :forbidden
196 put oauth_application_path(:id => other_client)
197 assert_response :not_found
198 assert_template "oauth2_applications/not_found"
200 put oauth_application_path(:id => client,
201 :oauth2_application => {
205 assert_response :success
206 assert_template "oauth2_applications/edit"
208 put oauth_application_path(:id => client,
209 :oauth2_application => {
211 :redirect_uri => "https://new.example.com/url"
213 assert_redirected_to oauth_application_path(:id => client.id)
218 client = create(:oauth_application, :owner => user)
219 other_client = create(:oauth_application)
221 assert_difference "Doorkeeper::Application.count", 0 do
222 delete oauth_application_path(:id => client)
224 assert_response :forbidden
228 assert_difference "Doorkeeper::Application.count", 0 do
229 delete oauth_application_path(:id => other_client)
231 assert_response :not_found
232 assert_template "oauth2_applications/not_found"
234 assert_difference "Doorkeeper::Application.count", -1 do
235 delete oauth_application_path(:id => client)
237 assert_redirected_to oauth_applications_path