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