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_pm.rb 2.8KB

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