annotate test/integration/api_test/disabled_rest_api_test.rb @ 1480:75fd8eace091 issue_556

Close obsolete branch issue_556
author Chris Cannam
date Sat, 13 Jul 2013 15:26:30 +0100
parents 433d4f72a19b
children 622f24f53b42
rev   line source
Chris@119 1 require File.expand_path('../../../test_helper', __FILE__)
chris@37 2
chris@37 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@37 12
chris@37 13 def setup
chris@37 14 Setting.rest_api_enabled = '0'
chris@37 15 Setting.login_required = '1'
chris@37 16 end
chris@37 17
chris@37 18 def teardown
chris@37 19 Setting.rest_api_enabled = '1'
chris@37 20 Setting.login_required = '0'
chris@37 21 end
Chris@909 22
Chris@1115 23 def test_with_a_valid_api_token
Chris@1115 24 @user = User.generate!
Chris@1115 25 @token = Token.create!(:user => @user, :action => 'api')
chris@37 26
Chris@1115 27 get "/news.xml?key=#{@token.value}"
Chris@1115 28 assert_response :unauthorized
Chris@1115 29 assert_equal User.anonymous, User.current
Chris@909 30
Chris@1115 31 get "/news.json?key=#{@token.value}"
Chris@1115 32 assert_response :unauthorized
Chris@1115 33 assert_equal User.anonymous, User.current
Chris@1115 34 end
chris@37 35
Chris@1115 36 def test_with_valid_username_password_http_authentication
Chris@1115 37 @user = User.generate! do |user|
Chris@1115 38 user.password = 'my_password'
chris@37 39 end
chris@37 40
Chris@1115 41 get "/news.xml", nil, credentials(@user.login, 'my_password')
Chris@1115 42 assert_response :unauthorized
Chris@1115 43 assert_equal User.anonymous, User.current
Chris@909 44
Chris@1115 45 get "/news.json", nil, credentials(@user.login, 'my_password')
Chris@1115 46 assert_response :unauthorized
Chris@1115 47 assert_equal User.anonymous, User.current
Chris@1115 48 end
chris@37 49
Chris@1115 50 def test_with_valid_token_http_authentication
Chris@1115 51 @user = User.generate!
Chris@1115 52 @token = Token.create!(:user => @user, :action => 'api')
Chris@909 53
Chris@1115 54 get "/news.xml", nil, credentials(@token.value, 'X')
Chris@1115 55 assert_response :unauthorized
Chris@1115 56 assert_equal User.anonymous, User.current
chris@37 57
Chris@1115 58 get "/news.json", nil, credentials(@token.value, 'X')
Chris@1115 59 assert_response :unauthorized
Chris@1115 60 assert_equal User.anonymous, User.current
chris@37 61 end
chris@37 62 end