annotate .svn/pristine/c5/c52f7b6c9c463e8a51ddc62dfba2a59799b361b2.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

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