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