To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / .svn / pristine / 00 / 00dbd874dfe947c78eb0cddc2e6a0cbc57c3f815.svn-base @ 1297:0a574315af3e

History | View | Annotate | Download (1.76 KB)

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