Ejemplo n.º 1
0
    def test_interface_checkip_bad_services(self):
        prog = client.Program()

        with self.assertRaises(ExitException):
            prog.run("checkip -t https --services curlmyip".split(), log=False)

        self.assertTrue(self.arg_error_mock.called)
Ejemplo n.º 2
0
 def test_interface_checkip(self):
     response_mock = mock.mock_open(read_data="127.0.0.1\n")
     self.urlopen_mock.side_effect = response_mock
     prog = client.Program()
     prog.run("checkip".split(), log=False)
     ret_value = self.stdout_mock.getvalue()
     self.assertIn('127.0.0.1', ret_value)
Ejemplo n.º 3
0
 def test_interface_update_query_by_ip(self):
     self.urlopen_mock.side_effect = mock.mock_open(read_data="127.0.0.7\n")
     prog = client.Program()
     prog.run("update -k keyname.key -s 8.8.8.8 other.zone.com".split(),
              log=False)
     args, kwargs = self.query_mock.call_args
     server = args[1]
     self.assertEqual(server, "8.8.8.8")
Ejemplo n.º 4
0
    def test_interface_checkip_bad_fetch(self):
        self.urlopen_mock.side_effect = client.URLError("timeout")
        prog = client.Program()

        with self.assertRaises(ExitException):
            prog.run("checkip".split(), log=False)

        self.arg_exit_mock.assert_called_with(69, mock.ANY)
Ejemplo n.º 5
0
    def test_interface_update2(self):
        self.urlopen_mock.side_effect = mock.mock_open(read_data="127.0.0.7\n")
        prog = client.Program()
        prog.run("update -k keyname.key other.zone.com".split(), log=False)

        args, kwargs = self.query_mock.call_args
        updater = args[0]
        msg_text = updater.to_text()
        self.assertIn("other", msg_text)
        self.assertIn("127.0.0.7", msg_text)
        self.assertNotIn("name", msg_text)
Ejemplo n.º 6
0
    def test_interface_update_timeout(self):
        self.urlopen_mock.side_effect = mock.mock_open(read_data="127.0.0.7\n")
        self.resolver_mock.return_value.query \
            .side_effect = dns.exception.Timeout
        prog = client.Program()
        with self.assertRaises(ExitException):
            prog.run("update -k keyname.key test.zone.com".split(), log=False)

        self.zone_for_name_mock.side_effect = dns.exception.Timeout

        with self.assertRaises(ExitException):
            prog.run("update -k keyname.key test.zone.com".split(), log=False)
Ejemplo n.º 7
0
    def test_interface_update_bad_key(self):
        self.urlopen_mock.side_effect = mock.mock_open(read_data="127.0.0.7\n")
        prog = client.Program()
        with self.assertRaises(ExitException):
            prog.run("update -k badkey.key other.zone.com".split(), log=False)

        with self.assertRaises(ExitException):
            prog.run(
                "update -k keyname.key --keyname bad other.zone.com".split(),
                log=False)

        with self.assertRaises(ExitException):
            prog.run("update -k empty.key other.zone.com".split(), log=False)
Ejemplo n.º 8
0
    def test_interface_checkip_bad_num(self):
        self.urlopen_mock.side_effect = mock.mock_open(read_data="127.0.0.1\n")
        prog = client.Program()
        with self.assertRaises(ExitException):
            prog.run("checkip -n -2".split(), log=False)

        with self.assertRaises(ExitException):
            prog.run("checkip -n 0".split(), log=False)

        with self.assertRaises(ExitException):
            prog.run("checkip --timeout -1".split(), log=False)

        with self.assertRaises(ExitException):
            prog.run("checkip --timeout -0.1".split(), log=False)
Ejemplo n.º 9
0
    def test_interface_set_verbosity(self, logger_mock, checkip_mock):
        logger_mock.configure_mock(handlers=[])
        prog = client.Program()
        prog.run("-vvv checkip".split(), log=True)

        logger_mock.setLevel.assert_called_with(logging.DEBUG)
        logger_mock.addHandler.assert_called_with(mock.ANY)

        prog.run("-vv checkip".split(), log=True)
        logger_mock.setLevel.assert_called_with(logging.INFO)

        prog.run("-v checkip".split(), log=True)
        logger_mock.setLevel.assert_called_with(logging.WARNING)

        prog.run("-vvvvv checkip".split(), log=True)
        logger_mock.setLevel.assert_called_with(logging.DEBUG)
Ejemplo n.º 10
0
    def test_interface_update(self):
        response_mock = mock.mock_open(read_data="127.0.0.6\n")
        self.urlopen_mock.side_effect = response_mock
        prog = client.Program()
        prog.run("update -k keyname.key name.zone.com".split(), log=False)
        self.query_mock.assert_called_with(mock.ANY,
                                           "master.server",
                                           timeout=mock.ANY,
                                           port=53)
        args, kwargs = self.query_mock.call_args
        updater = args[0]
        self.assertEqual(updater.origin.to_text(), "zone.com.")
        # look to KEY_TEXT
        self.assertEqual(updater.keyname.to_text(), "test.")
        self.assertEqual(updater.keyalgorithm, "hmac-sha256")
        msg_text = updater.to_text()

        self.assertIn("127.0.0.6", msg_text)
        self.assertIn("name", msg_text)
Ejemplo n.º 11
0
 def test_interface_update_bad_fetch(self):
     self.urlopen_mock.side_effect = client.URLError("timeout")
     prog = client.Program()
     with self.assertRaises(ExitException):
         prog.run("update -k keyname.key test.zone.com".split(), log=False)