4 class PermissionsControllerTest < ActionDispatch::IntegrationTest
6 # test all routes which lead to this controller
9 { :path => "/api/0.6/permissions", :method => :get },
10 { :controller => "api/permissions", :action => "show" }
13 { :path => "/api/0.6/permissions.json", :method => :get },
14 { :controller => "api/permissions", :action => "show", :format => "json" }
18 def test_permissions_anonymous
20 assert_response :success
21 assert_select "osm > permissions", :count => 1 do
22 assert_select "permission", :count => 0
26 get permissions_path(:format => "json")
27 assert_response :success
28 assert_equal "application/json", @response.media_type
30 js = ActiveSupport::JSON.decode(@response.body)
32 assert_equal 0, js["permissions"].count
35 def test_permissions_basic_auth
36 auth_header = basic_authorization_header create(:user).email, "test"
37 get permissions_path, :headers => auth_header
38 assert_response :success
39 assert_select "osm > permissions", :count => 1 do
40 assert_select "permission", :count => Oauth.scopes.size
41 Oauth.scopes.each do |p|
42 assert_select "permission[name='allow_#{p.name}']", :count => 1
47 get permissions_path(:format => "json"), :headers => auth_header
48 assert_response :success
49 assert_equal "application/json", @response.media_type
51 js = ActiveSupport::JSON.decode(@response.body)
53 assert_equal Oauth.scopes.size, js["permissions"].count
54 Oauth.scopes.each do |p|
55 assert_includes js["permissions"], "allow_#{p.name}"
59 def test_permissions_oauth2
61 token = create(:oauth_access_token,
62 :resource_owner_id => user.id,
63 :scopes => %w[read_prefs write_api])
64 get permissions_path, :headers => bearer_authorization_header(token.token)
65 assert_response :success
66 assert_select "osm > permissions", :count => 1 do
67 assert_select "permission", :count => 2
68 assert_select "permission[name='allow_read_prefs']", :count => 1
69 assert_select "permission[name='allow_write_api']", :count => 1
70 assert_select "permission[name='allow_read_gpx']", :count => 0