annotate .svn/pristine/43/431e564a1e03f4cc7d0102d7d18816df7d2cc0e3.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

Fix failure to interpret Javascript when autocompleting members for project
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 11 Sep 2014 10:24:38 +0100
parents cbb26bc654de
children
rev   line source
Chris@909 1 require File.expand_path('../../../test_helper', __FILE__)
Chris@909 2
Chris@909 3 class ApiTest::DisabledRestApiTest < ActionController::IntegrationTest
Chris@909 4 fixtures :projects, :trackers, :issue_statuses, :issues,
Chris@909 5 :enumerations, :users, :issue_categories,
Chris@909 6 :projects_trackers,
Chris@909 7 :roles,
Chris@909 8 :member_roles,
Chris@909 9 :members,
Chris@909 10 :enabled_modules,
Chris@909 11 :workflows
Chris@909 12
Chris@909 13 def setup
Chris@909 14 Setting.rest_api_enabled = '0'
Chris@909 15 Setting.login_required = '1'
Chris@909 16 end
Chris@909 17
Chris@909 18 def teardown
Chris@909 19 Setting.rest_api_enabled = '1'
Chris@909 20 Setting.login_required = '0'
Chris@909 21 end
Chris@909 22
Chris@909 23 # Using the NewsController because it's a simple API.
Chris@909 24 context "get /news with the API disabled" do
Chris@909 25
Chris@909 26 context "in :xml format" do
Chris@909 27 context "with a valid api token" do
Chris@909 28 setup do
Chris@909 29 @user = User.generate_with_protected!
Chris@909 30 @token = Token.generate!(:user => @user, :action => 'api')
Chris@909 31 get "/news.xml?key=#{@token.value}"
Chris@909 32 end
Chris@909 33
Chris@909 34 should_respond_with :unauthorized
Chris@909 35 should_respond_with_content_type :xml
Chris@909 36 should "not login as the user" do
Chris@909 37 assert_equal User.anonymous, User.current
Chris@909 38 end
Chris@909 39 end
Chris@909 40
Chris@909 41 context "with a valid HTTP authentication" do
Chris@909 42 setup do
Chris@909 43 @user = User.generate_with_protected!(:password => 'my_password', :password_confirmation => 'my_password')
Chris@909 44 @authorization = ActionController::HttpAuthentication::Basic.encode_credentials(@user.login, 'my_password')
Chris@909 45 get "/news.xml", nil, :authorization => @authorization
Chris@909 46 end
Chris@909 47
Chris@909 48 should_respond_with :unauthorized
Chris@909 49 should_respond_with_content_type :xml
Chris@909 50 should "not login as the user" do
Chris@909 51 assert_equal User.anonymous, User.current
Chris@909 52 end
Chris@909 53 end
Chris@909 54
Chris@909 55 context "with a valid HTTP authentication using the API token" do
Chris@909 56 setup do
Chris@909 57 @user = User.generate_with_protected!
Chris@909 58 @token = Token.generate!(:user => @user, :action => 'api')
Chris@909 59 @authorization = ActionController::HttpAuthentication::Basic.encode_credentials(@token.value, 'X')
Chris@909 60 get "/news.xml", nil, :authorization => @authorization
Chris@909 61 end
Chris@909 62
Chris@909 63 should_respond_with :unauthorized
Chris@909 64 should_respond_with_content_type :xml
Chris@909 65 should "not login as the user" do
Chris@909 66 assert_equal User.anonymous, User.current
Chris@909 67 end
Chris@909 68 end
Chris@909 69 end
Chris@909 70
Chris@909 71 context "in :json format" do
Chris@909 72 context "with a valid api token" do
Chris@909 73 setup do
Chris@909 74 @user = User.generate_with_protected!
Chris@909 75 @token = Token.generate!(:user => @user, :action => 'api')
Chris@909 76 get "/news.json?key=#{@token.value}"
Chris@909 77 end
Chris@909 78
Chris@909 79 should_respond_with :unauthorized
Chris@909 80 should_respond_with_content_type :json
Chris@909 81 should "not login as the user" do
Chris@909 82 assert_equal User.anonymous, User.current
Chris@909 83 end
Chris@909 84 end
Chris@909 85
Chris@909 86 context "with a valid HTTP authentication" do
Chris@909 87 setup do
Chris@909 88 @user = User.generate_with_protected!(:password => 'my_password', :password_confirmation => 'my_password')
Chris@909 89 @authorization = ActionController::HttpAuthentication::Basic.encode_credentials(@user.login, 'my_password')
Chris@909 90 get "/news.json", nil, :authorization => @authorization
Chris@909 91 end
Chris@909 92
Chris@909 93 should_respond_with :unauthorized
Chris@909 94 should_respond_with_content_type :json
Chris@909 95 should "not login as the user" do
Chris@909 96 assert_equal User.anonymous, User.current
Chris@909 97 end
Chris@909 98 end
Chris@909 99
Chris@909 100 context "with a valid HTTP authentication using the API token" do
Chris@909 101 setup do
Chris@909 102 @user = User.generate_with_protected!
Chris@909 103 @token = Token.generate!(:user => @user, :action => 'api')
Chris@909 104 @authorization = ActionController::HttpAuthentication::Basic.encode_credentials(@token.value, 'DoesNotMatter')
Chris@909 105 get "/news.json", nil, :authorization => @authorization
Chris@909 106 end
Chris@909 107
Chris@909 108 should_respond_with :unauthorized
Chris@909 109 should_respond_with_content_type :json
Chris@909 110 should "not login as the user" do
Chris@909 111 assert_equal User.anonymous, User.current
Chris@909 112 end
Chris@909 113 end
Chris@909 114
Chris@909 115 end
Chris@909 116 end
Chris@909 117 end