comparison test/integration/api_test/jsonp_test.rb @ 1295:622f24f53b42 redmine-2.3

Update to Redmine SVN revision 11972 on 2.3-stable branch
author Chris Cannam
date Fri, 14 Jun 2013 09:02:21 +0100
parents 433d4f72a19b
children e248c7af89ec
comparison
equal deleted inserted replaced
1294:3e4c3460b6ca 1295:622f24f53b42
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 # 3 #
4 # This program is free software; you can redistribute it and/or 4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 7 # of the License, or (at your option) any later version.
15 # along with this program; if not, write to the Free Software 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. 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 require File.expand_path('../../../test_helper', __FILE__) 18 require File.expand_path('../../../test_helper', __FILE__)
19 19
20 class ApiTest::JsonpTest < ActionController::IntegrationTest 20 class Redmine::ApiTest::JsonpTest < Redmine::ApiTest::Base
21 fixtures :trackers 21 fixtures :trackers
22 22
23 def test_should_ignore_jsonp_callback_with_jsonp_disabled
24 with_settings :jsonp_enabled => '0' do
25 get '/trackers.json?jsonp=handler'
26 end
27
28 assert_response :success
29 assert_match %r{^\{"trackers":.+\}$}, response.body
30 assert_equal 'application/json; charset=utf-8', response.headers['Content-Type']
31 end
32
23 def test_jsonp_should_accept_callback_param 33 def test_jsonp_should_accept_callback_param
24 get '/trackers.json?callback=handler' 34 with_settings :jsonp_enabled => '1' do
35 get '/trackers.json?callback=handler'
36 end
25 37
26 assert_response :success 38 assert_response :success
27 assert_match %r{^handler\(\{"trackers":.+\}\)$}, response.body 39 assert_match %r{^handler\(\{"trackers":.+\}\)$}, response.body
28 assert_equal 'application/javascript; charset=utf-8', response.headers['Content-Type'] 40 assert_equal 'application/javascript; charset=utf-8', response.headers['Content-Type']
29 end 41 end
30 42
31 def test_jsonp_should_accept_jsonp_param 43 def test_jsonp_should_accept_jsonp_param
32 get '/trackers.json?jsonp=handler' 44 with_settings :jsonp_enabled => '1' do
45 get '/trackers.json?jsonp=handler'
46 end
33 47
34 assert_response :success 48 assert_response :success
35 assert_match %r{^handler\(\{"trackers":.+\}\)$}, response.body 49 assert_match %r{^handler\(\{"trackers":.+\}\)$}, response.body
36 assert_equal 'application/javascript; charset=utf-8', response.headers['Content-Type'] 50 assert_equal 'application/javascript; charset=utf-8', response.headers['Content-Type']
37 end 51 end
38 52
39 def test_jsonp_should_strip_invalid_characters_from_callback 53 def test_jsonp_should_strip_invalid_characters_from_callback
40 get '/trackers.json?callback=+-aA$1_' 54 with_settings :jsonp_enabled => '1' do
55 get '/trackers.json?callback=+-aA$1_'
56 end
41 57
42 assert_response :success 58 assert_response :success
43 assert_match %r{^aA1_\(\{"trackers":.+\}\)$}, response.body 59 assert_match %r{^aA1_\(\{"trackers":.+\}\)$}, response.body
44 assert_equal 'application/javascript; charset=utf-8', response.headers['Content-Type'] 60 assert_equal 'application/javascript; charset=utf-8', response.headers['Content-Type']
45 end 61 end
46 62
47 def test_jsonp_without_callback_should_return_json 63 def test_jsonp_without_callback_should_return_json
48 get '/trackers.json?callback=' 64 with_settings :jsonp_enabled => '1' do
65 get '/trackers.json?callback='
66 end
49 67
50 assert_response :success 68 assert_response :success
51 assert_match %r{^\{"trackers":.+\}$}, response.body 69 assert_match %r{^\{"trackers":.+\}$}, response.body
52 assert_equal 'application/json; charset=utf-8', response.headers['Content-Type'] 70 assert_equal 'application/json; charset=utf-8', response.headers['Content-Type']
53 end 71 end