comparison .svn/pristine/c5/c52f7b6c9c463e8a51ddc62dfba2a59799b361b2.svn-base @ 1295:622f24f53b42 redmine-2.3

Update to Redmine SVN revision 11972 on 2.3-stable branch
author Chris Cannam
date Fri, 14 Jun 2013 09:02:21 +0100
parents
children
comparison
equal deleted inserted replaced
1294:3e4c3460b6ca 1295:622f24f53b42
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 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.expand_path('../test_case', __FILE__)
19 require 'tmpdir'
20
21 class RedminePmTest::RepositorySubversionTest < RedminePmTest::TestCase
22 fixtures :projects, :users, :members, :roles, :member_roles, :auth_sources
23
24 SVN_BIN = Redmine::Configuration['scm_subversion_command'] || "svn"
25
26 def test_anonymous_read_on_public_repo_with_permission_should_succeed
27 assert_success "ls", svn_url
28 end
29
30 def test_anonymous_read_on_public_repo_without_permission_should_fail
31 Role.anonymous.remove_permission! :browse_repository
32 assert_failure "ls", svn_url
33 end
34
35 def test_anonymous_read_on_private_repo_should_fail
36 Project.find(1).update_attribute :is_public, false
37 assert_failure "ls", svn_url
38 end
39
40 def test_anonymous_commit_on_public_repo_should_fail
41 Role.anonymous.add_permission! :commit_access
42 assert_failure "mkdir --message Creating_a_directory", svn_url(random_filename)
43 end
44
45 def test_anonymous_commit_on_private_repo_should_fail
46 Role.anonymous.add_permission! :commit_access
47 Project.find(1).update_attribute :is_public, false
48 assert_failure "mkdir --message Creating_a_directory", svn_url(random_filename)
49 end
50
51 def test_non_member_read_on_public_repo_with_permission_should_succeed
52 Role.anonymous.remove_permission! :browse_repository
53 with_credentials "miscuser8", "foo" do
54 assert_success "ls", svn_url
55 end
56 end
57
58 def test_non_member_read_on_public_repo_without_permission_should_fail
59 Role.anonymous.remove_permission! :browse_repository
60 Role.non_member.remove_permission! :browse_repository
61 with_credentials "miscuser8", "foo" do
62 assert_failure "ls", svn_url
63 end
64 end
65
66 def test_non_member_read_on_private_repo_should_fail
67 Project.find(1).update_attribute :is_public, false
68 with_credentials "miscuser8", "foo" do
69 assert_failure "ls", svn_url
70 end
71 end
72
73 def test_non_member_commit_on_public_repo_should_fail
74 Role.non_member.add_permission! :commit_access
75 assert_failure "mkdir --message Creating_a_directory", svn_url(random_filename)
76 end
77
78 def test_non_member_commit_on_private_repo_should_fail
79 Role.non_member.add_permission! :commit_access
80 Project.find(1).update_attribute :is_public, false
81 assert_failure "mkdir --message Creating_a_directory", svn_url(random_filename)
82 end
83
84 def test_member_read_on_public_repo_with_permission_should_succeed
85 Role.anonymous.remove_permission! :browse_repository
86 Role.non_member.remove_permission! :browse_repository
87 with_credentials "dlopper", "foo" do
88 assert_success "ls", svn_url
89 end
90 end
91
92 def test_member_read_on_public_repo_without_permission_should_fail
93 Role.anonymous.remove_permission! :browse_repository
94 Role.non_member.remove_permission! :browse_repository
95 Role.find(2).remove_permission! :browse_repository
96 with_credentials "dlopper", "foo" do
97 assert_failure "ls", svn_url
98 end
99 end
100
101 def test_member_read_on_private_repo_with_permission_should_succeed
102 Project.find(1).update_attribute :is_public, false
103 with_credentials "dlopper", "foo" do
104 assert_success "ls", svn_url
105 end
106 end
107
108 def test_member_read_on_private_repo_without_permission_should_fail
109 Role.find(2).remove_permission! :browse_repository
110 Project.find(1).update_attribute :is_public, false
111 with_credentials "dlopper", "foo" do
112 assert_failure "ls", svn_url
113 end
114 end
115
116 def test_member_commit_on_public_repo_with_permission_should_succeed
117 Role.find(2).add_permission! :commit_access
118 with_credentials "dlopper", "foo" do
119 assert_success "mkdir --message Creating_a_directory", svn_url(random_filename)
120 end
121 end
122
123 def test_member_commit_on_public_repo_without_permission_should_fail
124 Role.find(2).remove_permission! :commit_access
125 with_credentials "dlopper", "foo" do
126 assert_failure "mkdir --message Creating_a_directory", svn_url(random_filename)
127 end
128 end
129
130 def test_member_commit_on_private_repo_with_permission_should_succeed
131 Role.find(2).add_permission! :commit_access
132 Project.find(1).update_attribute :is_public, false
133 with_credentials "dlopper", "foo" do
134 assert_success "mkdir --message Creating_a_directory", svn_url(random_filename)
135 end
136 end
137
138 def test_member_commit_on_private_repo_without_permission_should_fail
139 Role.find(2).remove_permission! :commit_access
140 Project.find(1).update_attribute :is_public, false
141 with_credentials "dlopper", "foo" do
142 assert_failure "mkdir --message Creating_a_directory", svn_url(random_filename)
143 end
144 end
145
146 def test_invalid_credentials_should_fail
147 Project.find(1).update_attribute :is_public, false
148 with_credentials "dlopper", "foo" do
149 assert_success "ls", svn_url
150 end
151 with_credentials "dlopper", "wrong" do
152 assert_failure "ls", svn_url
153 end
154 end
155
156 def test_anonymous_read_should_fail_with_login_required
157 assert_success "ls", svn_url
158 with_settings :login_required => '1' do
159 assert_failure "ls", svn_url
160 end
161 end
162
163 def test_authenticated_read_should_succeed_with_login_required
164 with_settings :login_required => '1' do
165 with_credentials "miscuser8", "foo" do
166 assert_success "ls", svn_url
167 end
168 end
169 end
170
171 def test_read_on_archived_projects_should_fail
172 Project.find(1).update_attribute :status, Project::STATUS_ARCHIVED
173 assert_failure "ls", svn_url
174 end
175
176 def test_read_on_archived_private_projects_should_fail
177 Project.find(1).update_attribute :status, Project::STATUS_ARCHIVED
178 Project.find(1).update_attribute :is_public, false
179 with_credentials "dlopper", "foo" do
180 assert_failure "ls", svn_url
181 end
182 end
183
184 def test_read_on_closed_projects_should_succeed
185 Project.find(1).update_attribute :status, Project::STATUS_CLOSED
186 assert_success "ls", svn_url
187 end
188
189 def test_read_on_closed_private_projects_should_succeed
190 Project.find(1).update_attribute :status, Project::STATUS_CLOSED
191 Project.find(1).update_attribute :is_public, false
192 with_credentials "dlopper", "foo" do
193 assert_success "ls", svn_url
194 end
195 end
196
197 def test_commit_on_closed_projects_should_fail
198 Project.find(1).update_attribute :status, Project::STATUS_CLOSED
199 Role.find(2).add_permission! :commit_access
200 with_credentials "dlopper", "foo" do
201 assert_failure "mkdir --message Creating_a_directory", svn_url(random_filename)
202 end
203 end
204
205 def test_commit_on_closed_private_projects_should_fail
206 Project.find(1).update_attribute :status, Project::STATUS_CLOSED
207 Project.find(1).update_attribute :is_public, false
208 Role.find(2).add_permission! :commit_access
209 with_credentials "dlopper", "foo" do
210 assert_failure "mkdir --message Creating_a_directory", svn_url(random_filename)
211 end
212 end
213
214 if ldap_configured?
215 def test_user_with_ldap_auth_source_should_authenticate_with_ldap_credentials
216 ldap_user = User.new(:mail => 'example1@redmine.org', :firstname => 'LDAP', :lastname => 'user', :auth_source_id => 1)
217 ldap_user.login = 'example1'
218 ldap_user.save!
219
220 with_settings :login_required => '1' do
221 with_credentials "example1", "123456" do
222 assert_success "ls", svn_url
223 end
224 end
225
226 with_settings :login_required => '1' do
227 with_credentials "example1", "wrong" do
228 assert_failure "ls", svn_url
229 end
230 end
231 end
232 end
233
234 def test_checkout
235 Dir.mktmpdir do |dir|
236 assert_success "checkout", svn_url, dir
237 end
238 end
239
240 def test_read_commands
241 assert_success "info", svn_url
242 assert_success "ls", svn_url
243 assert_success "log", svn_url
244 end
245
246 def test_write_commands
247 Role.find(2).add_permission! :commit_access
248 filename = random_filename
249
250 Dir.mktmpdir do |dir|
251 assert_success "checkout", svn_url, dir
252 Dir.chdir(dir) do
253 # creates a file in the working copy
254 f = File.new(File.join(dir, filename), "w")
255 f.write "test file content"
256 f.close
257
258 assert_success "add", filename
259 with_credentials "dlopper", "foo" do
260 assert_success "commit --message Committing_a_file"
261 assert_success "copy --message Copying_a_file", svn_url(filename), svn_url("#{filename}_copy")
262 assert_success "delete --message Deleting_a_file", svn_url(filename)
263 assert_success "mkdir --message Creating_a_directory", svn_url("#{filename}_dir")
264 end
265 assert_success "update"
266
267 # checks that the working copy was updated
268 assert File.exists?(File.join(dir, "#{filename}_copy"))
269 assert File.directory?(File.join(dir, "#{filename}_dir"))
270 end
271 end
272 end
273
274 def test_read_invalid_repo_should_fail
275 assert_failure "ls", svn_url("invalid")
276 end
277
278 protected
279
280 def execute(*args)
281 a = [SVN_BIN, "--no-auth-cache --non-interactive"]
282 a << "--username #{username}" if username
283 a << "--password #{password}" if password
284
285 super a, *args
286 end
287
288 def svn_url(path=nil)
289 host = ENV['REDMINE_TEST_DAV_SERVER'] || '127.0.0.1'
290 url = "http://#{host}/svn/ecookbook"
291 url << "/#{path}" if path
292 url
293 end
294 end