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
56 def test_index_with_moderator_app
58 create(:oauth_application, :owner => user, :scopes => "write_redactions")
62 get oauth_applications_path
63 assert_response :success
69 get new_oauth_application_path
70 assert_redirected_to login_path(:referer => new_oauth_application_path)
74 get new_oauth_application_path
75 assert_response :success
76 assert_template "oauth2_applications/new"
77 assert_select "form", 1 do
78 assert_select "input#oauth2_application_name", 1
79 assert_select "textarea#oauth2_application_redirect_uri", 1
80 assert_select "input#oauth2_application_confidential", 1
81 Oauth.scopes.each do |scope|
82 assert_select "input#oauth2_application_scopes_#{scope.name}", 1
90 assert_difference "Doorkeeper::Application.count", 0 do
91 post oauth_applications_path
93 assert_response :forbidden
97 assert_difference "Doorkeeper::Application.count", 0 do
98 post oauth_applications_path(:oauth2_application => {
99 :name => "Test Application"
102 assert_response :success
103 assert_template "oauth2_applications/new"
105 assert_difference "Doorkeeper::Application.count", 0 do
106 post oauth_applications_path(:oauth2_application => {
107 :name => "Test Application",
108 :redirect_uri => "https://test.example.com/",
109 :scopes => ["bad_scope"]
112 assert_response :success
113 assert_template "oauth2_applications/new"
115 assert_difference "Doorkeeper::Application.count", 1 do
116 post oauth_applications_path(:oauth2_application => {
117 :name => "Test Application",
118 :redirect_uri => "https://test.example.com/",
119 :scopes => ["read_prefs"]
122 assert_redirected_to oauth_application_path(:id => Doorkeeper::Application.find_by(:name => "Test Application").id)
125 def test_create_privileged
126 session_for(create(:user))
128 assert_difference "Doorkeeper::Application.count", 0 do
129 post oauth_applications_path(:oauth2_application => {
130 :name => "Test Application",
131 :redirect_uri => "https://test.example.com/",
132 :scopes => ["read_email"]
135 assert_response :success
136 assert_template "oauth2_applications/new"
138 session_for(create(:administrator_user))
140 assert_difference "Doorkeeper::Application.count", 1 do
141 post oauth_applications_path(:oauth2_application => {
142 :name => "Test Application",
143 :redirect_uri => "https://test.example.com/",
144 :scopes => ["read_email"]
147 assert_redirected_to oauth_application_path(:id => Doorkeeper::Application.find_by(:name => "Test Application").id)
152 client = create(:oauth_application, :owner => user)
153 other_client = create(:oauth_application)
155 get oauth_application_path(:id => client)
156 assert_redirected_to login_path(:referer => oauth_application_path(:id => client.id))
160 get oauth_application_path(:id => other_client)
161 assert_response :not_found
162 assert_template "oauth2_applications/not_found"
164 get oauth_application_path(:id => client)
165 assert_response :success
166 assert_template "oauth2_applications/show"
171 client = create(:oauth_application, :owner => user)
172 other_client = create(:oauth_application)
174 get edit_oauth_application_path(:id => client)
175 assert_redirected_to login_path(:referer => edit_oauth_application_path(:id => client.id))
179 get edit_oauth_application_path(:id => other_client)
180 assert_response :not_found
181 assert_template "oauth2_applications/not_found"
183 get edit_oauth_application_path(:id => client)
184 assert_response :success
185 assert_template "oauth2_applications/edit"
186 assert_select "form", 1 do
187 assert_select "input#oauth2_application_name", 1
188 assert_select "textarea#oauth2_application_redirect_uri", 1
189 assert_select "input#oauth2_application_confidential", 1
190 Oauth.scopes.each do |scope|
191 assert_select "input#oauth2_application_scopes_#{scope.name}", 1
198 client = create(:oauth_application, :owner => user)
199 other_client = create(:oauth_application)
201 put oauth_application_path(:id => client)
202 assert_response :forbidden
206 put oauth_application_path(:id => other_client)
207 assert_response :not_found
208 assert_template "oauth2_applications/not_found"
210 put oauth_application_path(:id => client,
211 :oauth2_application => {
215 assert_response :success
216 assert_template "oauth2_applications/edit"
218 put oauth_application_path(:id => client,
219 :oauth2_application => {
221 :redirect_uri => "https://new.example.com/url"
223 assert_redirected_to oauth_application_path(:id => client.id)
228 client = create(:oauth_application, :owner => user)
229 other_client = create(:oauth_application)
231 assert_difference "Doorkeeper::Application.count", 0 do
232 delete oauth_application_path(:id => client)
234 assert_response :forbidden
238 assert_difference "Doorkeeper::Application.count", 0 do
239 delete oauth_application_path(:id => other_client)
241 assert_response :not_found
242 assert_template "oauth2_applications/not_found"
244 assert_difference "Doorkeeper::Application.count", -1 do
245 delete oauth_application_path(:id => client)
247 assert_redirected_to oauth_applications_path