File: fetch_test.rb

package info (click to toggle)
ruby-rugged 1.9.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,752 kB
  • sloc: ansic: 8,722; ruby: 7,473; sh: 99; makefile: 5
file content (121 lines) | stat: -rw-r--r-- 3,389 bytes parent folder | download | duplicates (2)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
require 'test_helper'

class OnlineFetchTest < Rugged::OnlineTestCase
  def setup
    @repo = FixtureRepo.empty
  end

  def test_fetch_over_git
    skip "this test requires network access"
    skip unless git_creds?
    @repo.remotes.create("origin", ENV['GITTEST_REMOTE_GIT_URL'])

    @repo.fetch("origin")
  end

  def test_fetch_over_https
    skip "this test requires network access"
    skip unless Rugged.features.include?(:https)

    @repo.remotes.create("origin", "https://github.com/libgit2/TestGitRepository.git")

    @repo.fetch("origin")

    assert_equal [
      "refs/remotes/origin/first-merge",
      "refs/remotes/origin/master",
      "refs/remotes/origin/no-parent",
      "refs/tags/annotated_tag",
      "refs/tags/blob",
      "refs/tags/commit_tree"
    ], @repo.refs.map(&:name).sort
  end

  def test_fetch_over_https_with_certificate_callback
    skip "this test requires network access"
    skip unless Rugged.features.include?(:https)

    @repo.remotes.create("origin", "https://github.com/libgit2/TestGitRepository.git")

    args = {}
    @repo.fetch(
      "origin",
      certificate_check: lambda { |valid, host|
        args[:valid] = valid
        args[:host] = host
        true
      }
    )

    assert_equal({ valid: true, host: "github.com" }, args)
  end

  def test_fetch_over_https_with_certificate_callback_fail
    skip "this test requires network access"
    skip unless Rugged.features.include?(:https)

    @repo.remotes.create("origin", "https://github.com/libgit2/TestGitRepository.git")

    exception = assert_raises Rugged::HTTPError do
      @repo.fetch(
        "origin",
        certificate_check: lambda { |valid, host| false }
      )
    end

    assert_equal "user rejected certificate for github.com", exception.message
  end

  def test_fetch_over_https_with_certificate_callback_exception
    skip "this test requires network access"
    skip unless Rugged.features.include?(:https)

    @repo.remotes.create("origin", "https://github.com/libgit2/TestGitRepository.git")

    exception = assert_raises RuntimeError do
      @repo.fetch(
        "origin",
        certificate_check: lambda { |valid, host|
          raise "Exception from callback"
        }
      )
    end

    assert_equal "Exception from callback", exception.message
  end

  def test_fetch_over_ssh_with_credentials
    skip "this test requires network access"
    skip unless Rugged.features.include?(:ssh) && ssh_creds?

    @repo.remotes.create("origin", ENV['GITTEST_REMOTE_SSH_URL'])

    @repo.fetch("origin", **{
                  credentials: ssh_key_credential
                })
  end

  def test_fetch_over_ssh_with_credentials_from_agent
    skip "this test requires network access"
    skip unless Rugged.features.include?(:ssh) && ssh_creds?

    @repo.remotes.create("origin", ENV['GITTEST_REMOTE_SSH_URL'])

    @repo.fetch("origin", **{
                  credentials: ssh_key_credential_from_agent
                })
  end

  def test_fetch_over_ssh_with_credentials_callback
    skip "this test requires network access"
    skip unless Rugged.features.include?(:ssh) && ssh_creds?

    @repo.remotes.create("origin", ENV['GITTEST_REMOTE_SSH_URL'])

    @repo.fetch("origin",
                credentials: lambda { |url, username, allowed_types|
                  return ssh_key_credential
                }
               )
  end
end