1 # frozen_string_literal: true
6 class PermissionsControllerTest < ActionDispatch::IntegrationTest
8 # test all routes which lead to this controller
11 { :path => "/api/0.6/permissions", :method => :get },
12 { :controller => "api/permissions", :action => "show" }
15 { :path => "/api/0.6/permissions.json", :method => :get },
16 { :controller => "api/permissions", :action => "show", :format => "json" }
20 def test_permissions_anonymous
21 get api_permissions_path
22 assert_response :success
23 assert_select "osm > permissions", :count => 1 do
24 assert_select "permission", :count => 0
28 get api_permissions_path(:format => "json")
29 assert_response :success
30 assert_equal "application/json", @response.media_type
32 js = ActiveSupport::JSON.decode(@response.body)
34 assert_equal 0, js["permissions"].count
37 def test_permissions_oauth2
39 auth_header = bearer_authorization_header(user, :scopes => %w[read_prefs write_api])
40 get api_permissions_path, :headers => auth_header
41 assert_response :success
42 assert_select "osm > permissions", :count => 1 do
43 assert_select "permission", :count => 2
44 assert_select "permission[name='allow_read_prefs']", :count => 1
45 assert_select "permission[name='allow_write_api']", :count => 1
46 assert_select "permission[name='allow_read_gpx']", :count => 0