mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #26483 from thusoy/git-user-only-auth
Handle user-only http auth in git module
This commit is contained in:
commit
a9b28e9577
2 changed files with 48 additions and 2 deletions
|
@ -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:
|
||||
|
|
43
tests/unit/modules/git_test.py
Normal file
43
tests/unit/modules/git_test.py
Normal 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)
|
Loading…
Add table
Reference in a new issue