annotate .svn/pristine/00/00dbd874dfe947c78eb0cddc2e6a0cbc57c3f815.svn-base @ 1327:287f201c2802 redmine-2.2-integration

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