|
1 |
# Redmine - project management software
|
|
2 |
# Copyright (C) 2006-2010 Jean-Philippe Lang
|
|
3 |
#
|
|
4 |
# This program is free software; you can redistribute it and/or
|
|
5 |
# modify it under the terms of the GNU General Public License
|
|
6 |
# as published by the Free Software Foundation; either version 2
|
|
7 |
# of the License, or (at your option) any later version.
|
|
8 |
#
|
|
9 |
# This program is distributed in the hope that it will be useful,
|
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
# GNU General Public License for more details.
|
|
13 |
#
|
|
14 |
# You should have received a copy of the GNU General Public License
|
|
15 |
# along with this program; if not, write to the Free Software
|
|
16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
17 |
|
|
18 |
require "#{File.dirname(__FILE__)}/../test_helper"
|
|
19 |
|
|
20 |
class UsersApiTest < ActionController::IntegrationTest
|
|
21 |
fixtures :users, :roles
|
|
22 |
|
|
23 |
def setup
|
|
24 |
Setting.rest_api_enabled = '1'
|
|
25 |
end
|
|
26 |
|
|
27 |
def teardown
|
|
28 |
Setting.rest_api_enabled = '0'
|
|
29 |
end
|
|
30 |
|
|
31 |
context "get /users.xml with authorized user" do
|
|
32 |
setup do
|
|
33 |
get '/users.xml', nil, :authorization => credentials('admin')
|
|
34 |
end
|
|
35 |
|
|
36 |
should_respond_with :success
|
|
37 |
should_respond_with_content_type 'application/xml'
|
|
38 |
|
|
39 |
end
|
|
40 |
|
|
41 |
context "get /users.xml with unauthorized user" do
|
|
42 |
setup do
|
|
43 |
get '/users.xml', nil, :authorization => credentials('jsmith')
|
|
44 |
end
|
|
45 |
|
|
46 |
should_respond_with :forbidden
|
|
47 |
|
|
48 |
end
|
|
49 |
|
|
50 |
context "get /users.xml with name " do
|
|
51 |
setup do
|
|
52 |
get '/users.xml?name=jsmith', nil, :authorization => credentials('admin')
|
|
53 |
end
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
should_respond_with_content_type 'application/xml'
|
|
58 |
|
|
59 |
should "show only users with the name jsmith " do
|
|
60 |
|
|
61 |
c = ARCondition.new(["LOWER(login) LIKE ? OR LOWER(firstname) LIKE ? OR LOWER(lastname) LIKE ? OR LOWER(mail) LIKE ?", "jsmith","jsmith","jsmith","jsmith"])
|
|
62 |
@user_count = User.count(:conditions => c.conditions)
|
|
63 |
assert_tag :tag => 'users', :children => { :count => @user_count, :only => {:tag => "user"} }
|
|
64 |
end
|
|
65 |
|
|
66 |
end
|
|
67 |
|
|
68 |
|
|
69 |
context "get /users.xml with status 1 " do
|
|
70 |
setup do
|
|
71 |
get '/users.xml?status=1', nil, :authorization => credentials('admin')
|
|
72 |
end
|
|
73 |
|
|
74 |
|
|
75 |
|
|
76 |
should_respond_with_content_type 'application/xml'
|
|
77 |
|
|
78 |
should "show only users with the status 1 " do
|
|
79 |
|
|
80 |
c = ARCondition.new(["status = 1"])
|
|
81 |
@user_count = User.count(:conditions => c.conditions)
|
|
82 |
assert_tag :tag => 'users', :children => { :count => @user_count, :only => {:tag => "user"} }
|
|
83 |
end
|
|
84 |
|
|
85 |
end
|
|
86 |
|
|
87 |
|
|
88 |
def credentials(user, password=nil)
|
|
89 |
ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user)
|
|
90 |
end
|
|
91 |
end
|