annotate .svn/pristine/00/00dbd874dfe947c78eb0cddc2e6a0cbc57c3f815.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author Chris Cannam
date Fri, 14 Jun 2013 09:28:30 +0100
parents 622f24f53b42
children
rev   line source
Chris@1295 1 require File.expand_path('../../../test_helper', __FILE__)
Chris@1295 2
Chris@1295 3 class ApiTest::DisabledRestApiTest < ActionController::IntegrationTest
Chris@1295 4 fixtures :projects, :trackers, :issue_statuses, :issues,
Chris@1295 5 :enumerations, :users, :issue_categories,
Chris@1295 6 :projects_trackers,
Chris@1295 7 :roles,
Chris@1295 8 :member_roles,
Chris@1295 9 :members,
Chris@1295 10 :enabled_modules,
Chris@1295 11 :workflows
Chris@1295 12
Chris@1295 13 def setup
Chris@1295 14 Setting.rest_api_enabled = '0'
Chris@1295 15 Setting.login_required = '1'
Chris@1295 16 end
Chris@1295 17
Chris@1295 18 def teardown
Chris@1295 19 Setting.rest_api_enabled = '1'
Chris@1295 20 Setting.login_required = '0'
Chris@1295 21 end
Chris@1295 22
Chris@1295 23 def test_with_a_valid_api_token
Chris@1295 24 @user = User.generate!
Chris@1295 25 @token = Token.create!(:user => @user, :action => 'api')
Chris@1295 26
Chris@1295 27 get "/news.xml?key=#{@token.value}"
Chris@1295 28 assert_response :unauthorized
Chris@1295 29 assert_equal User.anonymous, User.current
Chris@1295 30
Chris@1295 31 get "/news.json?key=#{@token.value}"
Chris@1295 32 assert_response :unauthorized
Chris@1295 33 assert_equal User.anonymous, User.current
Chris@1295 34 end
Chris@1295 35
Chris@1295 36 def test_with_valid_username_password_http_authentication
Chris@1295 37 @user = User.generate! do |user|
Chris@1295 38 user.password = 'my_password'
Chris@1295 39 end
Chris@1295 40
Chris@1295 41 get "/news.xml", nil, credentials(@user.login, 'my_password')
Chris@1295 42 assert_response :unauthorized
Chris@1295 43 assert_equal User.anonymous, User.current
Chris@1295 44
Chris@1295 45 get "/news.json", nil, credentials(@user.login, 'my_password')
Chris@1295 46 assert_response :unauthorized
Chris@1295 47 assert_equal User.anonymous, User.current
Chris@1295 48 end
Chris@1295 49
Chris@1295 50 def test_with_valid_token_http_authentication
Chris@1295 51 @user = User.generate!
Chris@1295 52 @token = Token.create!(:user => @user, :action => 'api')
Chris@1295 53
Chris@1295 54 get "/news.xml", nil, credentials(@token.value, 'X')
Chris@1295 55 assert_response :unauthorized
Chris@1295 56 assert_equal User.anonymous, User.current
Chris@1295 57
Chris@1295 58 get "/news.json", nil, credentials(@token.value, 'X')
Chris@1295 59 assert_response :unauthorized
Chris@1295 60 assert_equal User.anonymous, User.current
Chris@1295 61 end
Chris@1295 62 end