annotate .svn/pristine/eb/eb6cb0f6889f62dec8dd9c85a7fb5ed905af22c8.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-2013 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::RepositoryGitTest < RedminePmTest::TestCase
Chris@1295 22 fixtures :projects, :users, :members, :roles, :member_roles
Chris@1295 23
Chris@1295 24 GIT_BIN = Redmine::Configuration['scm_git_command'] || "git"
Chris@1295 25
Chris@1295 26 def test_anonymous_read_on_public_repo_with_permission_should_succeed
Chris@1295 27 assert_success "ls-remote", git_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-remote", git_url
Chris@1295 33 end
Chris@1295 34
Chris@1295 35 def test_invalid_credentials_should_fail
Chris@1295 36 Project.find(1).update_attribute :is_public, false
Chris@1295 37 with_credentials "dlopper", "foo" do
Chris@1295 38 assert_success "ls-remote", git_url
Chris@1295 39 end
Chris@1295 40 with_credentials "dlopper", "wrong" do
Chris@1295 41 assert_failure "ls-remote", git_url
Chris@1295 42 end
Chris@1295 43 end
Chris@1295 44
Chris@1295 45 def test_clone
Chris@1295 46 Dir.mktmpdir do |dir|
Chris@1295 47 Dir.chdir(dir) do
Chris@1295 48 assert_success "clone", git_url
Chris@1295 49 end
Chris@1295 50 end
Chris@1295 51 end
Chris@1295 52
Chris@1295 53 def test_write_commands
Chris@1295 54 Role.find(2).add_permission! :commit_access
Chris@1295 55 filename = random_filename
Chris@1295 56
Chris@1295 57 Dir.mktmpdir do |dir|
Chris@1295 58 assert_success "clone", git_url, dir
Chris@1295 59 Dir.chdir(dir) do
Chris@1295 60 f = File.new(File.join(dir, filename), "w")
Chris@1295 61 f.write "test file content"
Chris@1295 62 f.close
Chris@1295 63
Chris@1295 64 with_credentials "dlopper", "foo" do
Chris@1295 65 assert_success "add", filename
Chris@1295 66 assert_success "commit -a --message Committing_a_file"
Chris@1295 67 assert_success "push", git_url, "--all"
Chris@1295 68 end
Chris@1295 69 end
Chris@1295 70 end
Chris@1295 71
Chris@1295 72 Dir.mktmpdir do |dir|
Chris@1295 73 assert_success "clone", git_url, dir
Chris@1295 74 Dir.chdir(dir) do
Chris@1295 75 assert File.exists?(File.join(dir, "#{filename}"))
Chris@1295 76 end
Chris@1295 77 end
Chris@1295 78 end
Chris@1295 79
Chris@1295 80 protected
Chris@1295 81
Chris@1295 82 def execute(*args)
Chris@1295 83 a = [GIT_BIN]
Chris@1295 84 super a, *args
Chris@1295 85 end
Chris@1295 86
Chris@1295 87 def git_url(path=nil)
Chris@1295 88 host = ENV['REDMINE_TEST_DAV_SERVER'] || '127.0.0.1'
Chris@1295 89 credentials = nil
Chris@1295 90 if username && password
Chris@1295 91 credentials = "#{username}:#{password}"
Chris@1295 92 end
Chris@1295 93 url = "http://#{credentials}@#{host}/git/ecookbook"
Chris@1295 94 url << "/#{path}" if path
Chris@1295 95 url
Chris@1295 96 end
Chris@1295 97 end