Chris@1115: # Redmine - project management software Chris@1295: # Copyright (C) 2006-2013 Jean-Philippe Lang Chris@1115: # Chris@1115: # This program is free software; you can redistribute it and/or Chris@1115: # modify it under the terms of the GNU General Public License Chris@1115: # as published by the Free Software Foundation; either version 2 Chris@1115: # of the License, or (at your option) any later version. Chris@1115: # Chris@1115: # This program is distributed in the hope that it will be useful, Chris@1115: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@1115: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@1115: # GNU General Public License for more details. Chris@1115: # Chris@1115: # You should have received a copy of the GNU General Public License Chris@1115: # along with this program; if not, write to the Free Software Chris@1115: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@1115: Chris@1115: require File.expand_path('../test_case', __FILE__) Chris@1115: require 'tmpdir' Chris@1115: Chris@1115: class RedminePmTest::RepositoryGitTest < RedminePmTest::TestCase Chris@1115: fixtures :projects, :users, :members, :roles, :member_roles Chris@1115: Chris@1115: GIT_BIN = Redmine::Configuration['scm_git_command'] || "git" Chris@1115: Chris@1115: def test_anonymous_read_on_public_repo_with_permission_should_succeed Chris@1115: assert_success "ls-remote", git_url Chris@1115: end Chris@1115: Chris@1115: def test_anonymous_read_on_public_repo_without_permission_should_fail Chris@1115: Role.anonymous.remove_permission! :browse_repository Chris@1115: assert_failure "ls-remote", git_url Chris@1115: end Chris@1115: Chris@1115: def test_invalid_credentials_should_fail Chris@1115: Project.find(1).update_attribute :is_public, false Chris@1115: with_credentials "dlopper", "foo" do Chris@1115: assert_success "ls-remote", git_url Chris@1115: end Chris@1115: with_credentials "dlopper", "wrong" do Chris@1115: assert_failure "ls-remote", git_url Chris@1115: end Chris@1115: end Chris@1115: Chris@1115: def test_clone Chris@1115: Dir.mktmpdir do |dir| Chris@1115: Dir.chdir(dir) do Chris@1115: assert_success "clone", git_url Chris@1115: end Chris@1115: end Chris@1115: end Chris@1115: Chris@1115: def test_write_commands Chris@1115: Role.find(2).add_permission! :commit_access Chris@1115: filename = random_filename Chris@1115: Chris@1115: Dir.mktmpdir do |dir| Chris@1115: assert_success "clone", git_url, dir Chris@1115: Dir.chdir(dir) do Chris@1115: f = File.new(File.join(dir, filename), "w") Chris@1115: f.write "test file content" Chris@1115: f.close Chris@1115: Chris@1115: with_credentials "dlopper", "foo" do Chris@1115: assert_success "add", filename Chris@1115: assert_success "commit -a --message Committing_a_file" Chris@1115: assert_success "push", git_url, "--all" Chris@1115: end Chris@1115: end Chris@1115: end Chris@1115: Chris@1115: Dir.mktmpdir do |dir| Chris@1115: assert_success "clone", git_url, dir Chris@1115: Dir.chdir(dir) do Chris@1115: assert File.exists?(File.join(dir, "#{filename}")) Chris@1115: end Chris@1115: end Chris@1115: end Chris@1115: Chris@1115: protected Chris@1115: Chris@1115: def execute(*args) Chris@1115: a = [GIT_BIN] Chris@1115: super a, *args Chris@1115: end Chris@1115: Chris@1115: def git_url(path=nil) Chris@1115: host = ENV['REDMINE_TEST_DAV_SERVER'] || '127.0.0.1' Chris@1115: credentials = nil Chris@1115: if username && password Chris@1115: credentials = "#{username}:#{password}" Chris@1115: end Chris@1115: url = "http://#{credentials}@#{host}/git/ecookbook" Chris@1115: url << "/#{path}" if path Chris@1115: url Chris@1115: end Chris@1115: end