annotate .svn/pristine/c5/c52f7b6c9c463e8a51ddc62dfba2a59799b361b2.svn-base @ 1327:287f201c2802 redmine-2.2-integration

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