409
410
self.assertEqual(license_key, open(verify_path).read(),
410
411
"Content of license key doesn't match")
413
def test_use_apt_auth_conf(self):
414
"""Test if credentials of repositories are store securely in a
417
from mock import Mock
419
source_file_name = "private_source.list"
420
self.worker.add_repository(Mock(), "deb",
421
"https://user:pass@host.example.com/path",
422
"natty", ["main"], "comment",
424
# check if password was stripped (source file)
425
source_parts = apt_pkg.config.find_dir("Dir::Etc::sourceparts")
426
source_file_path = os.path.join(source_parts,
428
with open(source_file_path) as source_file:
429
source_file_content = source_file.read()
430
self.assertFalse("user:pass" in source_file_content)
431
# check if password was stored correctly (auth.conf)
432
auth_file_path = apt_pkg.config.find_file("Dir::Etc::netrc")
433
with open(auth_file_path) as auth_file:
434
auth_file_content = auth_file.read()
435
self.assertTrue("login user" in auth_file_content)
436
self.assertTrue("password pass" in auth_file_content)
437
self.assertTrue("machine host.example.com/path" in auth_file_content)
438
buf = os.stat(auth_file_path)
439
self.assertEqual(stat.S_IMODE(buf.st_mode), 0640)
413
442
if __name__ == "__main__":