@@ -67,4 +67,52 @@ public function testFallsBackIfNoIpv6Matches()
6767
6868 $ ret = $ this ->executor ->query ('8.8.8.8 ' , new Query ('google.com ' , Message::TYPE_AAAA , Message::CLASS_IN , 0 ));
6969 }
70+
71+ public function testDoesReturnReverseIpv4Lookup ()
72+ {
73+ $ this ->hosts ->expects ($ this ->once ())->method ('getHostsForIp ' )->with ('127.0.0.1 ' )->willReturn (array ('localhost ' ));
74+ $ this ->fallback ->expects ($ this ->never ())->method ('query ' );
75+
76+ $ this ->executor ->query ('8.8.8.8 ' , new Query ('1.0.0.127.in-addr.arpa ' , Message::TYPE_PTR , Message::CLASS_IN , 0 ));
77+ }
78+
79+ public function testFallsBackIfNoReverseIpv4Matches ()
80+ {
81+ $ this ->hosts ->expects ($ this ->once ())->method ('getHostsForIp ' )->with ('127.0.0.1 ' )->willReturn (array ());
82+ $ this ->fallback ->expects ($ this ->once ())->method ('query ' );
83+
84+ $ this ->executor ->query ('8.8.8.8 ' , new Query ('1.0.0.127.in-addr.arpa ' , Message::TYPE_PTR , Message::CLASS_IN , 0 ));
85+ }
86+
87+ public function testDoesReturnReverseIpv6Lookup ()
88+ {
89+ $ this ->hosts ->expects ($ this ->once ())->method ('getHostsForIp ' )->with ('2a02:2e0:3fe:100::6 ' )->willReturn (array ('ip6-localhost ' ));
90+ $ this ->fallback ->expects ($ this ->never ())->method ('query ' );
91+
92+ $ this ->executor ->query ('8.8.8.8 ' , new Query ('6.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.0.e.f.3.0.0.e.2.0.2.0.a.2.ip6.arpa ' , Message::TYPE_PTR , Message::CLASS_IN , 0 ));
93+ }
94+
95+ public function testFallsBackForInvalidAddress ()
96+ {
97+ $ this ->hosts ->expects ($ this ->never ())->method ('getHostsForIp ' );
98+ $ this ->fallback ->expects ($ this ->once ())->method ('query ' );
99+
100+ $ this ->executor ->query ('8.8.8.8 ' , new Query ('example.com ' , Message::TYPE_PTR , Message::CLASS_IN , 0 ));
101+ }
102+
103+ public function testReverseFallsBackForInvalidIpv4Address ()
104+ {
105+ $ this ->hosts ->expects ($ this ->never ())->method ('getHostsForIp ' );
106+ $ this ->fallback ->expects ($ this ->once ())->method ('query ' );
107+
108+ $ this ->executor ->query ('8.8.8.8 ' , new Query ('::1.in-addr.arpa ' , Message::TYPE_PTR , Message::CLASS_IN , 0 ));
109+ }
110+
111+ public function testReverseFallsBackForInvalidIpv6Address ()
112+ {
113+ $ this ->hosts ->expects ($ this ->never ())->method ('getHostsForIp ' );
114+ $ this ->fallback ->expects ($ this ->once ())->method ('query ' );
115+
116+ $ this ->executor ->query ('8.8.8.8 ' , new Query ('abcd.ip6.arpa ' , Message::TYPE_PTR , Message::CLASS_IN , 0 ));
117+ }
70118}
0 commit comments