Beispiel #1
0
 async def test_scpd_get(self):
     sent = []
     replies = {self.get_request: self.response}
     with mock_tcp_and_udp(self.loop,
                           tcp_replies=replies,
                           sent_tcp_packets=sent):
         result, raw, err = await scpd_get(self.path, self.lan_address,
                                           self.port, self.loop)
         self.assertEqual(None, err)
         self.assertDictEqual(self.expected_parsed, result)
Beispiel #2
0
 def test_get_external_ip(self):
     actual_output = StringIO()
     with contextlib.redirect_stdout(actual_output):
         with mock_tcp_and_udp(self.loop,
                               '10.0.0.1',
                               tcp_replies=self.scpd_replies,
                               udp_replies=self.udp_replies):
             main((None, '--timeout=1', '--gateway_address=10.0.0.1',
                   '--lan_address=10.0.0.2', 'get-external-ip'), self.loop)
     self.assertEqual("11.22.33.44\n", actual_output.getvalue())
Beispiel #3
0
 async def test_scpd_get_timeout(self):
     sent = []
     replies = {}
     with mock_tcp_and_udp(self.loop,
                           tcp_replies=replies,
                           sent_tcp_packets=sent):
         result, raw, err = await scpd_get(self.path, self.lan_address,
                                           self.port, self.loop)
         self.assertTrue(isinstance(err, UPnPError))
         self.assertDictEqual({}, result)
         self.assertEqual(b'', raw)
Beispiel #4
0
 async def test_scpd_get_overrun_content_length(self):
     sent = []
     replies = {self.get_request: self.bad_response + b'\r\n'}
     with mock_tcp_and_udp(self.loop,
                           tcp_replies=replies,
                           sent_tcp_packets=sent):
         result, raw, err = await scpd_get(self.path, self.lan_address,
                                           self.port, self.loop)
         self.assertDictEqual({}, result)
         self.assertEqual(self.bad_response + b'\r\n', raw)
         self.assertTrue(isinstance(err, UPnPError))
         self.assertTrue(str(err).startswith('too many bytes written'))
Beispiel #5
0
 async def test_scpd_get_bad_xml(self):
     sent = []
     replies = {self.get_request: self.bad_response}
     with mock_tcp_and_udp(self.loop,
                           tcp_replies=replies,
                           sent_tcp_packets=sent):
         result, raw, err = await scpd_get(self.path, self.lan_address,
                                           self.port, self.loop)
         self.assertDictEqual({}, result)
         self.assertEqual(self.bad_xml, raw)
         self.assertTrue(isinstance(err, UPnPError))
         self.assertTrue(str(err).startswith('no element found'))
Beispiel #6
0
    def test_m_search(self):
        actual_output = StringIO()
        timeout_msg = "aioupnp encountered an error: M-SEARCH for 10.0.0.1:1900 timed out\n"
        with contextlib.redirect_stdout(actual_output):
            with mock_tcp_and_udp(self.loop,
                                  '10.0.0.1',
                                  tcp_replies=self.scpd_replies,
                                  udp_replies=self.udp_replies):
                main((None, '--timeout=1', '--gateway_address=10.0.0.1',
                      '--lan_address=10.0.0.2', 'm-search'), self.loop)
        self.assertEqual(timeout_msg, actual_output.getvalue())

        actual_output = StringIO()
        with contextlib.redirect_stdout(actual_output):
            with mock_tcp_and_udp(self.loop,
                                  '10.0.0.1',
                                  tcp_replies=self.scpd_replies,
                                  udp_replies=self.udp_replies):
                main((None, '--timeout=1', '--gateway_address=10.0.0.1',
                      '--lan_address=10.0.0.2', '--unicast', 'm-search'),
                     self.loop)
        self.assertEqual(m_search_cli_result, actual_output.getvalue())
Beispiel #7
0
 async def test_scpd_post_overrun_response(self):
     sent = []
     replies = {self.post_bytes: self.post_response + b'\r\n'}
     with mock_tcp_and_udp(self.loop,
                           tcp_replies=replies,
                           sent_tcp_packets=sent):
         result, raw, err = await scpd_post(self.path, self.gateway_address,
                                            self.port, self.method,
                                            self.param_names, self.st,
                                            self.loop)
         self.assertTrue(isinstance(err, UPnPError))
         self.assertTrue(str(err).startswith('too many bytes written'))
         self.assertEqual(self.post_response + b'\r\n', raw)
         self.assertDictEqual({}, result)
Beispiel #8
0
 async def test_scpd_post_bad_xml_response(self):
     sent = []
     replies = {self.post_bytes: self.bad_envelope_response}
     with mock_tcp_and_udp(self.loop,
                           tcp_replies=replies,
                           sent_tcp_packets=sent):
         result, raw, err = await scpd_post(self.path, self.gateway_address,
                                            self.port, self.method,
                                            self.param_names, self.st,
                                            self.loop)
         self.assertTrue(isinstance(err, UPnPError))
         self.assertTrue(str(err).startswith('no element found'))
         self.assertEqual(self.bad_envelope, raw)
         self.assertDictEqual({}, result)
Beispiel #9
0
 async def test_scpd_post_timeout(self):
     sent = []
     replies = {}
     with mock_tcp_and_udp(self.loop,
                           tcp_replies=replies,
                           sent_tcp_packets=sent):
         result, raw, err = await scpd_post(self.path, self.gateway_address,
                                            self.port, self.method,
                                            self.param_names, self.st,
                                            self.loop)
         self.assertTrue(isinstance(err, UPnPError))
         self.assertTrue(str(err).startswith('Timeout'))
         self.assertEqual(b'', raw)
         self.assertDictEqual({}, result)
Beispiel #10
0
 async def test_scpd_post(self):
     sent = []
     replies = {self.post_bytes: self.post_response}
     with mock_tcp_and_udp(self.loop,
                           tcp_replies=replies,
                           sent_tcp_packets=sent):
         result, raw, err = await scpd_post(self.path, self.gateway_address,
                                            self.port, self.method,
                                            self.param_names, self.st,
                                            self.loop)
         self.assertEqual(None, err)
         self.assertEqual(self.envelope, raw)
         self.assertDictEqual({'NewExternalIPAddress': '11.22.33.44'},
                              result)