You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

repository_git_test.rb 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2014 Jean-Philippe Lang
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. require File.expand_path('../test_case', __FILE__)
  18. require 'tmpdir'
  19. class RedminePmTest::RepositoryGitTest < RedminePmTest::TestCase
  20. fixtures :projects, :users, :members, :roles, :member_roles
  21. GIT_BIN = Redmine::Configuration['scm_git_command'] || "git"
  22. def test_anonymous_read_on_public_repo_with_permission_should_succeed
  23. assert_success "ls-remote", git_url
  24. end
  25. def test_anonymous_read_on_public_repo_without_permission_should_fail
  26. Role.anonymous.remove_permission! :browse_repository
  27. assert_failure "ls-remote", git_url
  28. end
  29. def test_invalid_credentials_should_fail
  30. Project.find(1).update_attribute :is_public, false
  31. with_credentials "dlopper", "foo" do
  32. assert_success "ls-remote", git_url
  33. end
  34. with_credentials "dlopper", "wrong" do
  35. assert_failure "ls-remote", git_url
  36. end
  37. end
  38. def test_clone
  39. Dir.mktmpdir do |dir|
  40. Dir.chdir(dir) do
  41. assert_success "clone", git_url
  42. end
  43. end
  44. end
  45. def test_write_commands
  46. Role.find(2).add_permission! :commit_access
  47. filename = random_filename
  48. Dir.mktmpdir do |dir|
  49. assert_success "clone", git_url, dir
  50. Dir.chdir(dir) do
  51. f = File.new(File.join(dir, filename), "w")
  52. f.write "test file content"
  53. f.close
  54. with_credentials "dlopper", "foo" do
  55. assert_success "add", filename
  56. assert_success "commit -a --message Committing_a_file"
  57. assert_success "push", git_url, "--all"
  58. end
  59. end
  60. end
  61. Dir.mktmpdir do |dir|
  62. assert_success "clone", git_url, dir
  63. Dir.chdir(dir) do
  64. assert File.exists?(File.join(dir, "#{filename}"))
  65. end
  66. end
  67. end
  68. protected
  69. def execute(*args)
  70. a = [GIT_BIN]
  71. super a, *args
  72. end
  73. def git_url(path=nil)
  74. host = ENV['REDMINE_TEST_DAV_SERVER'] || '127.0.0.1'
  75. credentials = nil
  76. if username && password
  77. credentials = "#{username}:#{password}"
  78. end
  79. url = "http://#{credentials}@#{host}/git/ecookbook"
  80. url << "/#{path}" if path
  81. url
  82. end
  83. end