Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(RK-243) Refuse to generate rugged credentials more than 50 times. #596

Merged
merged 1 commit into from
May 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/r10k/git/rugged/credentials.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,18 @@ class R10K::Git::Rugged::Credentials
# @param repository [R10K::Git::Rugged::BaseRepository]
def initialize(repository)
@repository = repository
@called = 0
end

def call(url, username_from_url, allowed_types)
@called += 1

# Break out of infinite HTTP auth retry loop introduced in libgit2/rugged 0.24.0, libssh
# auth seems to already abort after ~50 attempts.
if @called > 50
raise R10K::Git::GitError.new("Authentication failed for Git remote #{url.inspect}.")
end

if allowed_types.include?(:ssh_key)
get_ssh_key_credentials(url, username_from_url)
elsif allowed_types.include?(:plaintext)
Expand Down
6 changes: 6 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,11 @@
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 more than 50 times" do
(1..50).each { subject.call("https://tessier-ashpool.freeside/repo.git", nil, [:plaintext]) }

expect { subject.call("https://tessier-ashpool.freeside/repo.git", nil, [:plaintext]) }.to raise_error(R10K::Git::GitError, /authentication failed/i)
end
end
end