@@ -211,3 +211,43 @@ def test_dnsaddress_repr_works():
211211 # ipv6 addresses not treated properly
212212 dnsaddr = DNSAddress ('aaaa' , r ._TYPE_A , r ._CLASS_IN , 60 , '127.0.0.1' )
213213 repr (dnsaddr )
214+
215+
216+ def test_unicast_query ():
217+ # test for queries fron a random source port
218+ generated = r .DNSOutgoing (r ._FLAGS_QR_QUERY )
219+ generated .add_question (r .DNSQuestion ("testname.local." , r ._TYPE_A ,
220+ r ._CLASS_IN ))
221+ zc = r .Zeroconf ()
222+ zc .handle_query (generated ,'127.0.0.1' ,1782 )
223+ zc .handle_query (generated ,'127.0.0.1' ,53 )
224+
225+
226+ def test_handle_read_nonspecialport ():
227+ error = socket .error (socket .EBADF )
228+ error .errno = socket .EBADF
229+
230+ zeroconf = Mock ()
231+ # packet data captured by running python examples/registration.py --debug
232+ zeroconf .socket .recvfrom = lambda x : (
233+ '0\x1a \x01 \x00 \x00 \x01 \x00 \x00 \x00 \x00 \x00 \x00 \x08 testname\x05 local\x00 \x00 \x01 \x00 \x01 ' ,
234+ ('127.0.0.1' , 1234 ))
235+
236+ listener = Listener (zeroconf )
237+ listener .handle_read (zeroconf .socket )
238+
239+
240+ def test_handle_read_dnsport ():
241+ error = socket .error (socket .EBADF )
242+ error .errno = socket .EBADF
243+
244+ zeroconf = Mock ()
245+ zeroconf .socket .recvfrom = lambda x : (
246+ '0\x1a \x01 \x00 \x00 \x01 \x00 \x00 \x00 \x00 \x00 \x00 \x08 testname\x05 local\x00 \x00 \x01 \x00 \x01 ' ,
247+ ('127.0.0.1' , 1234 ))
248+
249+
250+ listener = Listener (zeroconf )
251+ listener .handle_read (zeroconf .socket )
252+
253+
0 commit comments