~ubuntu-branches/debian/sid/aptdaemon/sid

« back to all changes in this revision

Viewing changes to tests/test_worker.py

  • Committer: Package Import Robot
  • Author(s): Michael Vogt
  • Date: 2012-04-02 20:57:57 UTC
  • mfrom: (1.3.24)
  • Revision ID: package-import@ubuntu.com-20120402205757-1krcphk1524dq0kl
Tags: 0.43+bzr790-1
* New upstream snapshot
* fixes CVE-2012-0944

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
import glob
26
26
import os
27
27
import shutil
 
28
import stat
28
29
import sys
29
30
import unittest
30
31
 
409
410
        self.assertEqual(license_key, open(verify_path).read(),
410
411
                         "Content of license key doesn't match")
411
412
 
 
413
    def test_use_apt_auth_conf(self):
 
414
        """Test if credentials of repositories are store securely in a
 
415
        separate file.
 
416
        """
 
417
        from mock import Mock
 
418
 
 
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",
 
423
                                   source_file_name)
 
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,
 
427
                                        source_file_name)
 
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)
 
440
 
412
441
 
413
442
if __name__ == "__main__":
414
443
    unittest.main()