summaryrefslogtreecommitdiffstats
path: root/test/integration/git_http_cloning_test.rb
blob: 09e54882a60f9fa93772ca325ecb77497b9495b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# encoding: utf-8
#--
#   Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
#
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU Affero General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU Affero General Public License for more details.
#
#   You should have received a copy of the GNU Affero General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
#++
require File.join(File.dirname(__FILE__), "..", "test_helper")

class GitHttpCloningTest < ActionController::IntegrationTest
  context 'Request with git clone' do
    setup do
      @repository = repositories(:johans)
      @request_uri = '/johans-project/johansprojectrepos.git/HEAD'
    end

    should 'set X-Sendfile headers for subdomains allowing HTTP cloning' do
      ['git.gitorious.org','git.gitorious.local','git.foo.com'].each do |host|
        assert_incremented_by(@repository.cloners, :count, 1) do
          get @request_uri, {}, :host => host, :remote_addr => '192.71.1.2'
          last_cloner = @repository.cloners.last
          assert_equal('192.71.1.2', last_cloner.ip)
          assert_equal('http', last_cloner.protocol)
        end
        assert_response :success
        assert_not_nil(headers['X-Sendfile'])
        assert_equal(File.join(GitoriousConfig['repository_base_path'], @repository.real_gitdir, "HEAD"), headers['X-Sendfile'])
      end
    end

    context "disabling of http cloning" do
      setup { GitoriousConfig['hide_http_clone_urls'] = true }
      teardown { GitoriousConfig['hide_http_clone_urls'] = false }

      should "not allow http cloning if denied by configuration" do
        ['git.gitorious.org','git.gitorious.local','git.foo.com'].each do |host|
          get @request_uri, {}, :host => host
          assert_response :not_found
          assert_nil headers['X-Sendfile']
        end
      end
    end
    
    should 'not set X-Sendfile for hosts that do not allow HTTP cloning' do
      ['gitorious.local','foo.local'].each do |host|
        get @request_uri, {}, :host => host
        assert_response :not_found
        assert_nil(headers['X-Sendfile'])
      end
    end
  end

  context "robots.txt generation" do
    should "generate a robots.txt entry disallowing indexing" do
      get "/robots.txt", {}, :host => "git.gitorious.local"
      assert_response :success
      assert_equal "text/plain", headers["Content-Type"]
      assert_equal "User-Agent: *\nDisallow: /\n", @response.body
    end

    should "not generate a robots.txt entry for non git subdomain" do
      get "/robots.txt", {}, :host => "gitorious.local"
      assert_response :not_found
    end
  end
end