summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/repo_path_spec.rb
blob: 13940713dfc42ebbf0a2ad9f5b4c63041333f820 (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
require 'spec_helper'

describe ::Gitlab::RepoPath do
  describe '.parse' do
    set(:project) { create(:project, :repository) }

    context 'a repository storage path' do
      it 'parses a full repository path' do
        expect(described_class.parse(project.repository.full_path)).to eq([project, false, nil])
      end

      it 'parses a full wiki path' do
        expect(described_class.parse(project.wiki.repository.full_path)).to eq([project, true, nil])
      end
    end

    context 'a relative path' do
      it 'parses a relative repository path' do
        expect(described_class.parse(project.full_path + '.git')).to eq([project, false, nil])
      end

      it 'parses a relative wiki path' do
        expect(described_class.parse(project.full_path + '.wiki.git')).to eq([project, true, nil])
      end

      it 'parses a relative path starting with /' do
        expect(described_class.parse('/' + project.full_path + '.git')).to eq([project, false, nil])
      end

      context 'of a redirected project' do
        let(:redirect) { project.route.create_redirect('foo/bar') }

        it 'parses a relative repository path' do
          expect(described_class.parse(redirect.path + '.git')).to eq([project, false, 'foo/bar'])
        end

        it 'parses a relative wiki path' do
          expect(described_class.parse(redirect.path + '.wiki.git')).to eq([project, true, 'foo/bar.wiki'])
        end

        it 'parses a relative path starting with /' do
          expect(described_class.parse('/' + redirect.path + '.git')).to eq([project, false, 'foo/bar'])
        end
      end
    end
  end

  describe '.find_project' do
    let(:project) { create(:project) }
    let(:redirect) { project.route.create_redirect('foo/bar/baz') }

    context 'when finding a project by its canonical path' do
      context 'when the cases match' do
        it 'returns the project and false' do
          expect(described_class.find_project(project.full_path)).to eq([project, false])
        end
      end

      context 'when the cases do not match' do
        # This is slightly different than web behavior because on the web it is
        # easy and safe to redirect someone to the correctly-cased URL. For git
        # requests, we should accept wrongly-cased URLs because it is a pain to
        # block people's git operations and force them to update remote URLs.
        it 'returns the project and false' do
          expect(described_class.find_project(project.full_path.upcase)).to eq([project, false])
        end
      end
    end

    context 'when finding a project via a redirect' do
      it 'returns the project and true' do
        expect(described_class.find_project(redirect.path)).to eq([project, true])
      end
    end
  end
end