2015-08-19 16:24:17 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
|
|
|
:codeauthor: :email:`Tarjei Husøy <git@thusoy.com>`
|
|
|
|
'''
|
2015-08-20 22:20:16 +00:00
|
|
|
from __future__ import absolute_import
|
2015-08-19 16:24:17 +00:00
|
|
|
|
|
|
|
# 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 = {
|
2015-08-20 22:21:49 +00:00
|
|
|
'url': 'https://example.com',
|
2015-08-19 16:24:17 +00:00
|
|
|
'https_user': user,
|
|
|
|
'https_pass': password,
|
|
|
|
}
|
|
|
|
result = git._add_http_basic_auth(**kwargs)
|
|
|
|
self.assertEqual(result, expected)
|
|
|
|
|
2015-08-19 18:41:10 +00:00
|
|
|
def test_https_user_and_pw_is_confidential(self):
|
|
|
|
sensitive_outputs = (
|
|
|
|
'https://deadbeaf@example.com',
|
|
|
|
'https://user:pw@example.com',
|
|
|
|
)
|
|
|
|
sanitized = 'https://<redacted>@example.com'
|
|
|
|
for sensitive_output in sensitive_outputs:
|
|
|
|
result = git._remove_sensitive_data(sensitive_output)
|
|
|
|
self.assertEqual(result, sanitized)
|
|
|
|
|
|
|
|
def test_git_ssh_user_is_not_treated_as_sensitive(self):
|
|
|
|
not_sensitive_outputs = (
|
|
|
|
'ssh://user@example.com',
|
|
|
|
)
|
|
|
|
for not_sensitive_output in not_sensitive_outputs:
|
|
|
|
result = git._remove_sensitive_data(not_sensitive_output)
|
|
|
|
self.assertEqual(result, not_sensitive_output)
|
|
|
|
|
2015-08-19 16:24:17 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
from integration import run_tests
|
|
|
|
run_tests(GitTestCase, needs_daemon=False)
|