annotate test/extra/redmine_pm/repository_subversion_test.rb @ 1628:9c5f8e24dadc live tip

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