##// END OF EJS Templates
Additional tests for Redmine.pm....
Jean-Philippe Lang -
r9645:9eef74f09aa7
parent child
Show More
@@ -1,216 +1,251
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
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
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.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../test_case', __FILE__)
18 require File.expand_path('../test_case', __FILE__)
19 require 'tmpdir'
19 require 'tmpdir'
20
20
21 class RedminePmTest::RepositorySubversionTest < RedminePmTest::TestCase
21 class RedminePmTest::RepositorySubversionTest < RedminePmTest::TestCase
22 fixtures :projects, :users, :members, :roles, :member_roles
22 fixtures :projects, :users, :members, :roles, :member_roles, :auth_sources
23
23
24 SVN_BIN = Redmine::Configuration['scm_subversion_command'] || "svn"
24 SVN_BIN = Redmine::Configuration['scm_subversion_command'] || "svn"
25
25
26 def test_anonymous_read_on_public_repo_with_permission_should_succeed
26 def test_anonymous_read_on_public_repo_with_permission_should_succeed
27 assert_success "ls", svn_url
27 assert_success "ls", svn_url
28 end
28 end
29
29
30 def test_anonymous_read_on_public_repo_without_permission_should_fail
30 def test_anonymous_read_on_public_repo_without_permission_should_fail
31 Role.anonymous.remove_permission! :browse_repository
31 Role.anonymous.remove_permission! :browse_repository
32 assert_failure "ls", svn_url
32 assert_failure "ls", svn_url
33 end
33 end
34
34
35 def test_anonymous_read_on_private_repo_should_fail
35 def test_anonymous_read_on_private_repo_should_fail
36 Project.find(1).update_attribute :is_public, false
36 Project.find(1).update_attribute :is_public, false
37 assert_failure "ls", svn_url
37 assert_failure "ls", svn_url
38 end
38 end
39
39
40 def test_anonymous_commit_on_public_repo_should_fail
40 def test_anonymous_commit_on_public_repo_should_fail
41 Role.anonymous.add_permission! :commit_access
41 Role.anonymous.add_permission! :commit_access
42 assert_failure "mkdir --message Creating_a_directory", svn_url(random_filename)
42 assert_failure "mkdir --message Creating_a_directory", svn_url(random_filename)
43 end
43 end
44
44
45 def test_anonymous_commit_on_private_repo_should_fail
45 def test_anonymous_commit_on_private_repo_should_fail
46 Role.anonymous.add_permission! :commit_access
46 Role.anonymous.add_permission! :commit_access
47 Project.find(1).update_attribute :is_public, false
47 Project.find(1).update_attribute :is_public, false
48 assert_failure "mkdir --message Creating_a_directory", svn_url(random_filename)
48 assert_failure "mkdir --message Creating_a_directory", svn_url(random_filename)
49 end
49 end
50
50
51 def test_non_member_read_on_public_repo_with_permission_should_succeed
51 def test_non_member_read_on_public_repo_with_permission_should_succeed
52 Role.anonymous.remove_permission! :browse_repository
52 Role.anonymous.remove_permission! :browse_repository
53 with_credentials "miscuser8", "foo" do
53 with_credentials "miscuser8", "foo" do
54 assert_success "ls", svn_url
54 assert_success "ls", svn_url
55 end
55 end
56 end
56 end
57
57
58 def test_non_member_read_on_public_repo_without_permission_should_fail
58 def test_non_member_read_on_public_repo_without_permission_should_fail
59 Role.anonymous.remove_permission! :browse_repository
59 Role.anonymous.remove_permission! :browse_repository
60 Role.non_member.remove_permission! :browse_repository
60 Role.non_member.remove_permission! :browse_repository
61 with_credentials "miscuser8", "foo" do
61 with_credentials "miscuser8", "foo" do
62 assert_failure "ls", svn_url
62 assert_failure "ls", svn_url
63 end
63 end
64 end
64 end
65
65
66 def test_non_member_read_on_private_repo_should_fail
66 def test_non_member_read_on_private_repo_should_fail
67 Project.find(1).update_attribute :is_public, false
67 Project.find(1).update_attribute :is_public, false
68 with_credentials "miscuser8", "foo" do
68 with_credentials "miscuser8", "foo" do
69 assert_failure "ls", svn_url
69 assert_failure "ls", svn_url
70 end
70 end
71 end
71 end
72
72
73 def test_non_member_commit_on_public_repo_should_fail
73 def test_non_member_commit_on_public_repo_should_fail
74 Role.non_member.add_permission! :commit_access
74 Role.non_member.add_permission! :commit_access
75 assert_failure "mkdir --message Creating_a_directory", svn_url(random_filename)
75 assert_failure "mkdir --message Creating_a_directory", svn_url(random_filename)
76 end
76 end
77
77
78 def test_non_member_commit_on_private_repo_should_fail
78 def test_non_member_commit_on_private_repo_should_fail
79 Role.non_member.add_permission! :commit_access
79 Role.non_member.add_permission! :commit_access
80 Project.find(1).update_attribute :is_public, false
80 Project.find(1).update_attribute :is_public, false
81 assert_failure "mkdir --message Creating_a_directory", svn_url(random_filename)
81 assert_failure "mkdir --message Creating_a_directory", svn_url(random_filename)
82 end
82 end
83
83
84 def test_member_read_on_public_repo_with_permission_should_succeed
84 def test_member_read_on_public_repo_with_permission_should_succeed
85 Role.anonymous.remove_permission! :browse_repository
85 Role.anonymous.remove_permission! :browse_repository
86 Role.non_member.remove_permission! :browse_repository
86 Role.non_member.remove_permission! :browse_repository
87 with_credentials "dlopper", "foo" do
87 with_credentials "dlopper", "foo" do
88 assert_success "ls", svn_url
88 assert_success "ls", svn_url
89 end
89 end
90 end
90 end
91
91
92 def test_member_read_on_public_repo_without_permission_should_fail
92 def test_member_read_on_public_repo_without_permission_should_fail
93 Role.anonymous.remove_permission! :browse_repository
93 Role.anonymous.remove_permission! :browse_repository
94 Role.non_member.remove_permission! :browse_repository
94 Role.non_member.remove_permission! :browse_repository
95 Role.find(2).remove_permission! :browse_repository
95 Role.find(2).remove_permission! :browse_repository
96 with_credentials "dlopper", "foo" do
96 with_credentials "dlopper", "foo" do
97 assert_failure "ls", svn_url
97 assert_failure "ls", svn_url
98 end
98 end
99 end
99 end
100
100
101 def test_member_read_on_private_repo_with_permission_should_succeed
101 def test_member_read_on_private_repo_with_permission_should_succeed
102 Project.find(1).update_attribute :is_public, false
102 Project.find(1).update_attribute :is_public, false
103 with_credentials "dlopper", "foo" do
103 with_credentials "dlopper", "foo" do
104 assert_success "ls", svn_url
104 assert_success "ls", svn_url
105 end
105 end
106 end
106 end
107
107
108 def test_member_read_on_private_repo_without_permission_should_fail
108 def test_member_read_on_private_repo_without_permission_should_fail
109 Role.find(2).remove_permission! :browse_repository
109 Role.find(2).remove_permission! :browse_repository
110 Project.find(1).update_attribute :is_public, false
110 Project.find(1).update_attribute :is_public, false
111 with_credentials "dlopper", "foo" do
111 with_credentials "dlopper", "foo" do
112 assert_failure "ls", svn_url
112 assert_failure "ls", svn_url
113 end
113 end
114 end
114 end
115
115
116 def test_member_commit_on_public_repo_with_permission_should_succeed
116 def test_member_commit_on_public_repo_with_permission_should_succeed
117 Role.find(2).add_permission! :commit_access
117 Role.find(2).add_permission! :commit_access
118 with_credentials "dlopper", "foo" do
118 with_credentials "dlopper", "foo" do
119 assert_success "mkdir --message Creating_a_directory", svn_url(random_filename)
119 assert_success "mkdir --message Creating_a_directory", svn_url(random_filename)
120 end
120 end
121 end
121 end
122
122
123 def test_member_commit_on_public_repo_without_permission_should_fail
123 def test_member_commit_on_public_repo_without_permission_should_fail
124 Role.find(2).remove_permission! :commit_access
124 Role.find(2).remove_permission! :commit_access
125 with_credentials "dlopper", "foo" do
125 with_credentials "dlopper", "foo" do
126 assert_failure "mkdir --message Creating_a_directory", svn_url(random_filename)
126 assert_failure "mkdir --message Creating_a_directory", svn_url(random_filename)
127 end
127 end
128 end
128 end
129
129
130 def test_member_commit_on_private_repo_with_permission_should_succeed
130 def test_member_commit_on_private_repo_with_permission_should_succeed
131 Role.find(2).add_permission! :commit_access
131 Role.find(2).add_permission! :commit_access
132 Project.find(1).update_attribute :is_public, false
132 Project.find(1).update_attribute :is_public, false
133 with_credentials "dlopper", "foo" do
133 with_credentials "dlopper", "foo" do
134 assert_success "mkdir --message Creating_a_directory", svn_url(random_filename)
134 assert_success "mkdir --message Creating_a_directory", svn_url(random_filename)
135 end
135 end
136 end
136 end
137
137
138 def test_member_commit_on_private_repo_without_permission_should_fail
138 def test_member_commit_on_private_repo_without_permission_should_fail
139 Role.find(2).remove_permission! :commit_access
139 Role.find(2).remove_permission! :commit_access
140 Project.find(1).update_attribute :is_public, false
140 Project.find(1).update_attribute :is_public, false
141 with_credentials "dlopper", "foo" do
141 with_credentials "dlopper", "foo" do
142 assert_failure "mkdir --message Creating_a_directory", svn_url(random_filename)
142 assert_failure "mkdir --message Creating_a_directory", svn_url(random_filename)
143 end
143 end
144 end
144 end
145
145
146 def test_invalid_credentials_should_fail
146 def test_invalid_credentials_should_fail
147 Project.find(1).update_attribute :is_public, false
147 Project.find(1).update_attribute :is_public, false
148 with_credentials "dlopper", "foo" do
148 with_credentials "dlopper", "foo" do
149 assert_success "ls", svn_url
149 assert_success "ls", svn_url
150 end
150 end
151 with_credentials "dlopper", "wrong" do
151 with_credentials "dlopper", "wrong" do
152 assert_failure "ls", svn_url
152 assert_failure "ls", svn_url
153 end
153 end
154 end
154 end
155
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 if ldap_configured?
172 def test_user_with_ldap_auth_source_should_authenticate_with_ldap_credentials
173 ldap_user = User.new(:mail => 'example1@redmine.org', :firstname => 'LDAP', :lastname => 'user', :auth_source_id => 1)
174 ldap_user.login = 'example1'
175 ldap_user.save!
176
177 with_settings :login_required => '1' do
178 with_credentials "example1", "123456" do
179 assert_success "ls", svn_url
180 end
181 end
182
183 with_settings :login_required => '1' do
184 with_credentials "example1", "wrong" do
185 assert_failure "ls", svn_url
186 end
187 end
188 end
189 end
190
156 def test_checkout
191 def test_checkout
157 Dir.mktmpdir do |dir|
192 Dir.mktmpdir do |dir|
158 assert_success "checkout", svn_url, dir
193 assert_success "checkout", svn_url, dir
159 end
194 end
160 end
195 end
161
196
162 def test_read_commands
197 def test_read_commands
163 assert_success "info", svn_url
198 assert_success "info", svn_url
164 assert_success "ls", svn_url
199 assert_success "ls", svn_url
165 assert_success "log", svn_url
200 assert_success "log", svn_url
166 end
201 end
167
202
168 def test_write_commands
203 def test_write_commands
169 Role.find(2).add_permission! :commit_access
204 Role.find(2).add_permission! :commit_access
170 filename = random_filename
205 filename = random_filename
171
206
172 Dir.mktmpdir do |dir|
207 Dir.mktmpdir do |dir|
173 assert_success "checkout", svn_url, dir
208 assert_success "checkout", svn_url, dir
174 Dir.chdir(dir) do
209 Dir.chdir(dir) do
175 # creates a file in the working copy
210 # creates a file in the working copy
176 f = File.new(File.join(dir, filename), "w")
211 f = File.new(File.join(dir, filename), "w")
177 f.write "test file content"
212 f.write "test file content"
178 f.close
213 f.close
179
214
180 assert_success "add", filename
215 assert_success "add", filename
181 with_credentials "dlopper", "foo" do
216 with_credentials "dlopper", "foo" do
182 assert_success "commit --message Committing_a_file"
217 assert_success "commit --message Committing_a_file"
183 assert_success "copy --message Copying_a_file", svn_url(filename), svn_url("#{filename}_copy")
218 assert_success "copy --message Copying_a_file", svn_url(filename), svn_url("#{filename}_copy")
184 assert_success "delete --message Deleting_a_file", svn_url(filename)
219 assert_success "delete --message Deleting_a_file", svn_url(filename)
185 assert_success "mkdir --message Creating_a_directory", svn_url("#{filename}_dir")
220 assert_success "mkdir --message Creating_a_directory", svn_url("#{filename}_dir")
186 end
221 end
187 assert_success "update"
222 assert_success "update"
188
223
189 # checks that the working copy was updated
224 # checks that the working copy was updated
190 assert File.exists?(File.join(dir, "#{filename}_copy"))
225 assert File.exists?(File.join(dir, "#{filename}_copy"))
191 assert File.directory?(File.join(dir, "#{filename}_dir"))
226 assert File.directory?(File.join(dir, "#{filename}_dir"))
192 end
227 end
193 end
228 end
194 end
229 end
195
230
196 def test_read_invalid_repo_should_fail
231 def test_read_invalid_repo_should_fail
197 assert_failure "ls", svn_url("invalid")
232 assert_failure "ls", svn_url("invalid")
198 end
233 end
199
234
200 protected
235 protected
201
236
202 def execute(*args)
237 def execute(*args)
203 a = [SVN_BIN, "--no-auth-cache --non-interactive"]
238 a = [SVN_BIN, "--no-auth-cache --non-interactive"]
204 a << "--username #{username}" if username
239 a << "--username #{username}" if username
205 a << "--password #{password}" if password
240 a << "--password #{password}" if password
206
241
207 super a, *args
242 super a, *args
208 end
243 end
209
244
210 def svn_url(path=nil)
245 def svn_url(path=nil)
211 host = ENV['REDMINE_TEST_DAV_SERVER'] || '127.0.0.1'
246 host = ENV['REDMINE_TEST_DAV_SERVER'] || '127.0.0.1'
212 url = "http://#{host}/svn/ecookbook"
247 url = "http://#{host}/svn/ecookbook"
213 url << "/#{path}" if path
248 url << "/#{path}" if path
214 url
249 url
215 end
250 end
216 end
251 end
General Comments 0
You need to be logged in to leave comments. Login now