Handle user-only http auth in git module

This commit is contained in:
Tarjei Husøy 2015-08-19 09:24:17 -07:00
parent bcca1b4c5a
commit 09fc934acc
2 changed files with 48 additions and 2 deletions

View file

@ -123,8 +123,11 @@ def _add_http_basic_auth(repository, https_user=None, https_pass=None):
else:
urltuple = _urlparse(repository)
if urltuple.scheme == 'https':
netloc = "{0}:{1}@{2}".format(https_user, https_pass,
urltuple.netloc)
if https_pass:
auth_string = "{0}:{1}".format(https_user, https_pass)
else:
auth_string = https_user
netloc = "{0}@{1}".format(auth_string, urltuple.netloc)
urltuple = urltuple._replace(netloc=netloc)
return _urlunparse(urltuple)
else:

View file

@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
'''
:codeauthor: :email:`Tarjei Husøy <git@thusoy.com>`
'''
# Import Salt Testing Libs
from salttesting import TestCase
from salttesting.helpers import ensure_in_syspath
ensure_in_syspath('../../')
# Import Salt Libs
from salt.modules import git
class GitTestCase(TestCase):
'''
TestCase for salt.modules.git module
'''
def test_http_basic_authentication(self):
'''
Test that HTTP Basic auth works as intended.
'''
# ((user, pass), expected) tuples
test_inputs = [
((None, None), 'https://example.com'),
(('user', None), 'https://user@example.com'),
(('user', 'pass'), 'https://user:pass@example.com'),
]
for (user, password), expected in test_inputs:
kwargs = {
'https_user': user,
'https_pass': password,
'repository': 'https://example.com',
}
result = git._add_http_basic_auth(**kwargs)
self.assertEqual(result, expected)
if __name__ == '__main__':
from integration import run_tests
run_tests(GitTestCase, needs_daemon=False)