Skip to content

Commit

Permalink
(RK-243) Refuse to generate rugged credentials more than once.
Browse files Browse the repository at this point in the history
The new behavior as of libgit2/rugged 0.24.0 is to continue to call the
credentials callback until either it raises an error or the server gives
up. Since neither was happening, invalid credentials were leading to an
infinite retry loop.
  • Loading branch information
scotje committed May 16, 2016
1 parent b945b88 commit 5d67cd2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/r10k/git/rugged/credentials.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,17 @@ class R10K::Git::Rugged::Credentials
# @param repository [R10K::Git::Rugged::BaseRepository]
def initialize(repository)
@repository = repository
@called = false
end

def call(url, username_from_url, allowed_types)
# Break out of infinite auth retry loop introduced in libgit2/rugged 0.24.0.
if @called
raise R10K::Git::GitError.new("Authentication failed for Git remote #{url.inspect}.")
else
@called = true
end

if allowed_types.include?(:ssh_key)
get_ssh_key_credentials(url, username_from_url)
elsif allowed_types.include?(:plaintext)
Expand Down
5 changes: 5 additions & 0 deletions spec/unit/git/rugged/credentials_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,10 @@
it "creates default credentials when no other types are allowed" do
expect(subject.call("https://tessier-ashpool.freeside/repo.git", nil, [])).to be_a_kind_of(Rugged::Credentials::Default)
end

it "refuses to generate credentials a second time" do
expect(subject.call("https://tessier-ashpool.freeside/repo.git", nil, [:plaintext])).to be_a_kind_of(Rugged::Credentials::UserPassword)
expect { subject.call("https://tessier-ashpool.freeside/repo.git", nil, [:plaintext]) }.to raise_error(R10K::Git::GitError, /authentication failed/i)
end
end
end

0 comments on commit 5d67cd2

Please sign in to comment.