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