Mercurial > hg > soundsoftware-site
comparison test/integration/api_test/disabled_rest_api_test.rb @ 909:cbb26bc654de redmine-1.3
Update to Redmine 1.3-stable branch (Redmine SVN rev 8964)
author | Chris Cannam |
---|---|
date | Fri, 24 Feb 2012 19:09:32 +0000 |
parents | 8661b858af72 |
children | 433d4f72a19b |
comparison
equal
deleted
inserted
replaced
908:c6c2cbd0afee | 909:cbb26bc654de |
---|---|
1 require File.expand_path('../../../test_helper', __FILE__) | 1 require File.expand_path('../../../test_helper', __FILE__) |
2 | 2 |
3 class ApiTest::DisabledRestApiTest < ActionController::IntegrationTest | 3 class ApiTest::DisabledRestApiTest < ActionController::IntegrationTest |
4 fixtures :all | 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 | |
5 | 12 |
6 def setup | 13 def setup |
7 Setting.rest_api_enabled = '0' | 14 Setting.rest_api_enabled = '0' |
8 Setting.login_required = '1' | 15 Setting.login_required = '1' |
9 end | 16 end |
10 | 17 |
11 def teardown | 18 def teardown |
12 Setting.rest_api_enabled = '1' | 19 Setting.rest_api_enabled = '1' |
13 Setting.login_required = '0' | 20 Setting.login_required = '0' |
14 end | 21 end |
15 | 22 |
16 # Using the NewsController because it's a simple API. | 23 # Using the NewsController because it's a simple API. |
17 context "get /news with the API disabled" do | 24 context "get /news with the API disabled" do |
18 | 25 |
19 context "in :xml format" do | 26 context "in :xml format" do |
20 context "with a valid api token" do | 27 context "with a valid api token" do |
21 setup do | 28 setup do |
22 @user = User.generate_with_protected! | 29 @user = User.generate_with_protected! |
23 @token = Token.generate!(:user => @user, :action => 'api') | 30 @token = Token.generate!(:user => @user, :action => 'api') |
24 get "/news.xml?key=#{@token.value}" | 31 get "/news.xml?key=#{@token.value}" |
25 end | 32 end |
26 | 33 |
27 should_respond_with :unauthorized | 34 should_respond_with :unauthorized |
28 should_respond_with_content_type :xml | 35 should_respond_with_content_type :xml |
29 should "not login as the user" do | 36 should "not login as the user" do |
30 assert_equal User.anonymous, User.current | 37 assert_equal User.anonymous, User.current |
31 end | 38 end |
35 setup do | 42 setup do |
36 @user = User.generate_with_protected!(:password => 'my_password', :password_confirmation => 'my_password') | 43 @user = User.generate_with_protected!(:password => 'my_password', :password_confirmation => 'my_password') |
37 @authorization = ActionController::HttpAuthentication::Basic.encode_credentials(@user.login, 'my_password') | 44 @authorization = ActionController::HttpAuthentication::Basic.encode_credentials(@user.login, 'my_password') |
38 get "/news.xml", nil, :authorization => @authorization | 45 get "/news.xml", nil, :authorization => @authorization |
39 end | 46 end |
40 | 47 |
41 should_respond_with :unauthorized | 48 should_respond_with :unauthorized |
42 should_respond_with_content_type :xml | 49 should_respond_with_content_type :xml |
43 should "not login as the user" do | 50 should "not login as the user" do |
44 assert_equal User.anonymous, User.current | 51 assert_equal User.anonymous, User.current |
45 end | 52 end |
50 @user = User.generate_with_protected! | 57 @user = User.generate_with_protected! |
51 @token = Token.generate!(:user => @user, :action => 'api') | 58 @token = Token.generate!(:user => @user, :action => 'api') |
52 @authorization = ActionController::HttpAuthentication::Basic.encode_credentials(@token.value, 'X') | 59 @authorization = ActionController::HttpAuthentication::Basic.encode_credentials(@token.value, 'X') |
53 get "/news.xml", nil, :authorization => @authorization | 60 get "/news.xml", nil, :authorization => @authorization |
54 end | 61 end |
55 | 62 |
56 should_respond_with :unauthorized | 63 should_respond_with :unauthorized |
57 should_respond_with_content_type :xml | 64 should_respond_with_content_type :xml |
58 should "not login as the user" do | 65 should "not login as the user" do |
59 assert_equal User.anonymous, User.current | 66 assert_equal User.anonymous, User.current |
60 end | 67 end |
66 setup do | 73 setup do |
67 @user = User.generate_with_protected! | 74 @user = User.generate_with_protected! |
68 @token = Token.generate!(:user => @user, :action => 'api') | 75 @token = Token.generate!(:user => @user, :action => 'api') |
69 get "/news.json?key=#{@token.value}" | 76 get "/news.json?key=#{@token.value}" |
70 end | 77 end |
71 | 78 |
72 should_respond_with :unauthorized | 79 should_respond_with :unauthorized |
73 should_respond_with_content_type :json | 80 should_respond_with_content_type :json |
74 should "not login as the user" do | 81 should "not login as the user" do |
75 assert_equal User.anonymous, User.current | 82 assert_equal User.anonymous, User.current |
76 end | 83 end |
80 setup do | 87 setup do |
81 @user = User.generate_with_protected!(:password => 'my_password', :password_confirmation => 'my_password') | 88 @user = User.generate_with_protected!(:password => 'my_password', :password_confirmation => 'my_password') |
82 @authorization = ActionController::HttpAuthentication::Basic.encode_credentials(@user.login, 'my_password') | 89 @authorization = ActionController::HttpAuthentication::Basic.encode_credentials(@user.login, 'my_password') |
83 get "/news.json", nil, :authorization => @authorization | 90 get "/news.json", nil, :authorization => @authorization |
84 end | 91 end |
85 | 92 |
86 should_respond_with :unauthorized | 93 should_respond_with :unauthorized |
87 should_respond_with_content_type :json | 94 should_respond_with_content_type :json |
88 should "not login as the user" do | 95 should "not login as the user" do |
89 assert_equal User.anonymous, User.current | 96 assert_equal User.anonymous, User.current |
90 end | 97 end |
102 should_respond_with_content_type :json | 109 should_respond_with_content_type :json |
103 should "not login as the user" do | 110 should "not login as the user" do |
104 assert_equal User.anonymous, User.current | 111 assert_equal User.anonymous, User.current |
105 end | 112 end |
106 end | 113 end |
107 | 114 |
108 end | 115 end |
109 end | 116 end |
110 end | 117 end |