Exemplo n.º 1
0
 def test_pkg_audit_not_authorised_inside_jail(self):
     check = checkpkgaudit.CheckPkgAudit()
     err_message = "pkg: jail_attach(masterdns): Operation not permitted"
     with mock.patch("checkpkgaudit.checkpkgaudit._popen") as _popen:
         _popen.return_value = '', err_message
         with self.assertRaises(CheckError):
             check.pkg_audit(jail='masterdns')  # NOQA
Exemplo n.º 2
0
 def test_pkg_audit_not_installed_in_jail(self):
     check = checkpkgaudit.CheckPkgAudit()
     err_message = ("pkg: vulnxml file /var/db/pkg/vuln.xml does not exist."
                    " Try running 'pkg audit -F' first")
     with mock.patch("checkpkgaudit.checkpkgaudit._popen") as _popen:
         _popen.return_value = '', err_message
         with self.assertRaises(CheckError):
             check.pkg_audit(jail='supervision')  # NOQA
Exemplo n.º 3
0
    def test_pkg_audit_with_problems_inside_jail(self):
        check = checkpkgaudit.CheckPkgAudit()
        pb = ("bind910-9.10.1P1_1 is vulnerable:\n",
              "bind -- denial of service vulnerability\n",
              "CVE: CVE-2015-1349\n",
              "WWW: http://vuxml.FreeBSD.org/freebsd/58033a95",
              "-bba8-11e4-88ae-d050992ecde8.html\n", "\n",
              "1 problem(s) in the installed packages found.\n")

        with mock.patch("checkpkgaudit.checkpkgaudit._popen") as _popen:
            _popen.return_value = ''.join(pb), ''
            self.assertEqual(check.pkg_audit(), 1)
Exemplo n.º 4
0
    def test_probe_host_with_jails(self):
        check = checkpkgaudit.CheckPkgAudit()
        check.hostname = 'hostname.domain.tld'
        mocked = "checkpkgaudit.checkpkgaudit._get_jails"
        with mock.patch(mocked) as _get_jails:
            _get_jails.return_value = [{'hostname': 'masterdns', 'jid': '50'}]

            mocked = "checkpkgaudit.checkpkgaudit.CheckPkgAudit.pkg_audit"
            with mock.patch(mocked) as pkg_audit:
                pkg_audit.return_value = 0
                probe = check.probe()
                host = next(probe)
                self.assertIsNotNone(host)
                jail = next(probe)
                self.assertIsNotNone(jail)
Exemplo n.º 5
0
    def test_probe_host(self):
        check = checkpkgaudit.CheckPkgAudit()
        check.hostname = 'hostname.domain.tld'
        mocked = "checkpkgaudit.checkpkgaudit._get_jails"
        with mock.patch(mocked) as _get_jails:
            _get_jails.return_value = []

            mocked = "checkpkgaudit.checkpkgaudit.CheckPkgAudit.pkg_audit"
            with mock.patch(mocked) as pkg_audit:
                pkg_audit.return_value = 0

                probe = check.probe()
                host = next(probe)
                self.assertEqual(type(host), Metric)
                self.assertEqual(host.name, 'hostname.domain.tld')
                self.assertEqual(host.value, 0)
Exemplo n.º 6
0
 def test_pkg_audit_no_problems_inside_jail(self):
     check = checkpkgaudit.CheckPkgAudit()
     ok_message = "0 problem(s) in the installed packages found."
     with mock.patch("checkpkgaudit.checkpkgaudit._popen") as _popen:
         _popen.return_value = ok_message, ''
         self.assertEqual(check.pkg_audit('masterdns'), 0)