]> git.openstreetmap.org Git - rails.git/blob - test/controllers/api/permissions_controller_test.rb
Remove the floating from the sidebar close buttons
[rails.git] / test / controllers / api / permissions_controller_test.rb
1 require "test_helper"
2
3 module Api
4   class PermissionsControllerTest < ActionDispatch::IntegrationTest
5     ##
6     # test all routes which lead to this controller
7     def test_routes
8       assert_routing(
9         { :path => "/api/0.6/permissions", :method => :get },
10         { :controller => "api/permissions", :action => "show" }
11       )
12     end
13
14     def test_permissions_anonymous
15       get permissions_path
16       assert_response :success
17       assert_select "osm > permissions", :count => 1 do
18         assert_select "permission", :count => 0
19       end
20     end
21
22     def test_permissions_basic_auth
23       auth_header = basic_authorization_header create(:user).email, "test"
24       get permissions_path, :headers => auth_header
25       assert_response :success
26       assert_select "osm > permissions", :count => 1 do
27         assert_select "permission", :count => ClientApplication.all_permissions.size
28         ClientApplication.all_permissions.each do |p|
29           assert_select "permission[name='#{p}']", :count => 1
30         end
31       end
32     end
33
34     def test_permissions_oauth1
35       token = create(:access_token,
36                      :allow_read_prefs => true,
37                      :allow_write_api => true,
38                      :allow_read_gpx => false)
39       signed_get permissions_path, :oauth => { :token => token }
40       assert_response :success
41       assert_select "osm > permissions", :count => 1 do
42         assert_select "permission", :count => 2
43         assert_select "permission[name='allow_read_prefs']", :count => 1
44         assert_select "permission[name='allow_write_api']", :count => 1
45         assert_select "permission[name='allow_read_gpx']", :count => 0
46       end
47     end
48
49     def test_permissions_oauth2
50       user = create(:user)
51       token = create(:oauth_access_token,
52                      :resource_owner_id => user.id,
53                      :scopes => %w[read_prefs write_api])
54       get permissions_path, :headers => bearer_authorization_header(token.token)
55       assert_response :success
56       assert_select "osm > permissions", :count => 1 do
57         assert_select "permission", :count => 2
58         assert_select "permission[name='allow_read_prefs']", :count => 1
59         assert_select "permission[name='allow_write_api']", :count => 1
60         assert_select "permission[name='allow_read_gpx']", :count => 0
61       end
62     end
63   end
64 end