Skip to content

Commit

Permalink
Until now SUSEConnect was only supporting the format of .curlrc that …
Browse files Browse the repository at this point in the history
…Yast writes: '--proxy-user "meuser1$:mepassord2%"'

In https://www.suse.com/support/kb/doc/?id=000017441, SUSE asks customers to use a different format: proxy-user = "meuser1$:mepassord2%"

With this patch, SUSEConnect can read both formats from .curlrc
  • Loading branch information
digitaltom committed Sep 28, 2020
1 parent 3f4c5a2 commit c520743
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
9 changes: 7 additions & 2 deletions lib/suse/toolkit/curlrc_dotfile.rb
Expand Up @@ -3,6 +3,11 @@
class SUSE::Toolkit::CurlrcDotfile
CURLRC_LOCATION = '.curlrc'

# Yast is setting up the credentials in .curlrc in '--proxy-user "user:pwd"' style,
# but https://www.suse.com/support/kb/doc/?id=000017441 uses 'proxy-user = "john:n0v3ll"'.
# We should support both formats in SUSEConnect
CURLRC_CREDENTIALS_REGEXP = /-*proxy-user[ =]*"(.+):(.+)"/

def initialize
@file_location = File.join(Etc.getpwuid.dir, CURLRC_LOCATION)
end
Expand All @@ -12,11 +17,11 @@ def exist?
end

def username
line_with_credentials.match(/--proxy-user\s?"(.*):/)[1] rescue nil
line_with_credentials.match(CURLRC_CREDENTIALS_REGEXP)[1] rescue nil
end

def password
line_with_credentials.match(/--proxy-user\s?".*:(.*)"/)[1] rescue nil
line_with_credentials.match(CURLRC_CREDENTIALS_REGEXP)[2] rescue nil
end

private
Expand Down
29 changes: 14 additions & 15 deletions spec/toolkit/curlrc_dotfile_spec.rb
Expand Up @@ -4,9 +4,10 @@
describe SUSE::Toolkit::CurlrcDotfile do
let(:curlrc_location) { File.join(Etc.getpwuid.dir, described_class::CURLRC_LOCATION) }
let(:fixture_curlrc) { File.readlines('spec/fixtures/curlrc_example.dotfile') }
let(:proper_line_with_credentials) do
%(--proxy-user "meuser:mepassord"
)
let(:proper_lines_with_credentials) do
['--proxy-user "meuser1$:mepassord2%"',
'proxy-user = "meuser1$:mepassord2%"',
'proxy-user="meuser1$:mepassord2%"']
end
let(:garbled_line_with_credentials) do
%(--proxy-user meusermepassord"
Expand Down Expand Up @@ -35,12 +36,11 @@

describe '#password' do
context 'string with credentials is matching' do
before do
allow(subject).to receive(:line_with_credentials).and_return(proper_line_with_credentials)
end

it 'extracts proper username' do
expect(subject.password).to eq 'mepassord'
it 'extracts proper password' do
proper_lines_with_credentials.each do |proper_line_with_credentials|
allow(subject).to receive(:line_with_credentials).and_return(proper_line_with_credentials)
expect(subject.password).to eq 'mepassord2%'
end
end
end

Expand All @@ -57,12 +57,11 @@

describe '#username' do
context 'string with credentials is matching' do
before do
allow(subject).to receive(:line_with_credentials).and_return(proper_line_with_credentials)
end

it 'extracts proper username' do
expect(subject.username).to eq 'meuser'
proper_lines_with_credentials.each do |proper_line_with_credentials|
allow(subject).to receive(:line_with_credentials).and_return(proper_line_with_credentials)
expect(subject.username).to eq 'meuser1$'
end
end
end

Expand All @@ -85,7 +84,7 @@
end

it 'returns line matching pattern' do
expect(subject.send(:line_with_credentials)).to eq proper_line_with_credentials
expect(subject.send(:line_with_credentials)).to eq "--proxy-user \"meuser:mepassord\"\n"
end

it 'returns nil if no matchin line found' do
Expand Down

0 comments on commit c520743

Please sign in to comment.