annotate .svn/pristine/af/af84f3f5537a5370b6f58104816b1886cf576cfc.svn-base @ 1519:afce8026aaeb redmine-2.4-integration

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