You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

jsonp_test.rb 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2016 Jean-Philippe Lang
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. require File.expand_path('../../../test_helper', __FILE__)
  18. class Redmine::ApiTest::JsonpTest < Redmine::ApiTest::Base
  19. fixtures :trackers
  20. def test_should_ignore_jsonp_callback_with_jsonp_disabled
  21. with_settings :jsonp_enabled => '0' do
  22. get '/trackers.json?jsonp=handler'
  23. end
  24. assert_response :success
  25. assert_match %r{^\{"trackers":.+\}$}, response.body
  26. assert_equal 'application/json; charset=utf-8', response.headers['Content-Type']
  27. end
  28. def test_jsonp_should_accept_callback_param
  29. with_settings :jsonp_enabled => '1' do
  30. get '/trackers.json?callback=handler'
  31. end
  32. assert_response :success
  33. assert_match %r{^handler\(\{"trackers":.+\}\)$}, response.body
  34. assert_equal 'application/javascript; charset=utf-8', response.headers['Content-Type']
  35. end
  36. def test_jsonp_should_accept_jsonp_param
  37. with_settings :jsonp_enabled => '1' do
  38. get '/trackers.json?jsonp=handler'
  39. end
  40. assert_response :success
  41. assert_match %r{^handler\(\{"trackers":.+\}\)$}, response.body
  42. assert_equal 'application/javascript; charset=utf-8', response.headers['Content-Type']
  43. end
  44. def test_jsonp_should_strip_invalid_characters_from_callback
  45. with_settings :jsonp_enabled => '1' do
  46. get '/trackers.json?callback=+-aA$1_.'
  47. end
  48. assert_response :success
  49. assert_match %r{^aA1_.\(\{"trackers":.+\}\)$}, response.body
  50. assert_equal 'application/javascript; charset=utf-8', response.headers['Content-Type']
  51. end
  52. def test_jsonp_without_callback_should_return_json
  53. with_settings :jsonp_enabled => '1' do
  54. get '/trackers.json?callback='
  55. end
  56. assert_response :success
  57. assert_match %r{^\{"trackers":.+\}$}, response.body
  58. assert_equal 'application/json; charset=utf-8', response.headers['Content-Type']
  59. end
  60. end