@ -1570,7 +1570,7 @@ TEST_P(MockUDPChannelTest, DNSCookieSingle) {
reply . set_response ( ) . set_aa ( )
. add_question ( new DNSQuestion ( " www.google.com " , T_A ) )
. add_answer ( new DNSARR ( " www.google.com " , 0x0100 , { 0x01 , 0x02 , 0x03 , 0x04 } ) )
. add_additional ( new DNSOptRR ( 0 , 0 , 0 , 1280 , { } , server_cookie ) ) ;
. add_additional ( new DNSOptRR ( 0 , 0 , 0 , 1280 , { } , server_cookie , false ) ) ;
EXPECT_CALL ( server_ , OnRequest ( " www.google.com " , T_A ) )
. WillOnce ( SetReply ( & server_ , & reply ) ) ;
@ -1587,26 +1587,33 @@ TEST_P(MockUDPChannelTest, DNSCookieSingle) {
}
TEST_P ( MockUDPChannelTest , DNSCookieMissingAfterGood ) {
DNSPacket reply ;
std : : vector < byte > server_cookie = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 } ;
DNSPacket reply ;
reply . set_response ( ) . set_aa ( )
. add_question ( new DNSQuestion ( " www.google.com " , T_A ) )
. add_answer ( new DNSARR ( " www.google.com " , 0x0100 , { 0x01 , 0x02 , 0x03 , 0x04 } ) )
. add_additional ( new DNSOptRR ( 0 , 0 , 0 , 1280 , { } , server_cookie ) ) ;
. add_additional ( new DNSOptRR ( 0 , 0 , 0 , 1280 , { } , server_cookie , false ) ) ;
DNSPacket reply_nocookie ;
reply_nocookie . set_response ( ) . set_aa ( )
. add_question ( new DNSQuestion ( " www.google.com " , T_A ) )
. add_answer ( new DNSARR ( " www.google.com " , 0x0100 , { 0x01 , 0x02 , 0x03 , 0x04 } ) )
. add_additional ( new DNSOptRR ( 0 , 0 , 0 , 1280 , { } , { } ) ) ;
. add_additional ( new DNSOptRR ( 0 , 0 , 0 , 1280 , { } , { } , false ) ) ;
DNSPacket reply_ensurecookie ;
reply_ensurecookie . set_response ( ) . set_aa ( )
. add_question ( new DNSQuestion ( " www.google.com " , T_A ) )
. add_answer ( new DNSARR ( " www.google.com " , 0x0100 , { 0x01 , 0x02 , 0x03 , 0x04 } ) )
. add_additional ( new DNSOptRR ( 0 , 0 , 0 , 1280 , { } , server_cookie , true ) ) ;
EXPECT_CALL ( server_ , OnRequest ( " www.google.com " , T_A ) )
. WillOnce ( SetReply ( & server_ , & reply ) )
. WillOnce ( SetReply ( & server_ , & reply_nocookie ) )
. WillOnce ( SetReply ( & server_ , & reply ) ) ;
. WillOnce ( SetReply ( & server_ , & reply_ensurecookie ) ) ;
/* This test will establish the server supports cookies, then the next reply
* will be missing the server cookie and therefore be rejected and timeout , then
* an internal retry will occur and the cookie will be present again . */
* an internal retry will occur and the cookie will be present again and it
* will be verified a server cookie was actually present that matches the
* server cookie . */
QueryResult result1 ;
ares_query_dnsrec ( channel_ , " www.google.com " , ARES_CLASS_IN , ARES_REC_TYPE_A , QueryCallback , & result1 , NULL ) ;
Process ( ) ;
@ -1637,12 +1644,12 @@ TEST_P(MockUDPChannelTest, DNSCookieBadLen) {
reply . set_response ( ) . set_aa ( )
. add_question ( new DNSQuestion ( " www.google.com " , T_A ) )
. add_answer ( new DNSARR ( " www.google.com " , 0x0100 , { 0x01 , 0x02 , 0x03 , 0x04 } ) )
. add_additional ( new DNSOptRR ( 0 , 0 , 0 , 1280 , { } , server_cookie ) ) ;
. add_additional ( new DNSOptRR ( 0 , 0 , 0 , 1280 , { } , server_cookie , false ) ) ;
DNSPacket reply_badcookielen ;
reply_badcookielen . set_response ( ) . set_aa ( )
. add_question ( new DNSQuestion ( " www.google.com " , T_A ) )
. add_answer ( new DNSARR ( " www.google.com " , 0x0100 , { 0x01 , 0x02 , 0x03 , 0x04 } ) )
. add_additional ( new DNSOptRR ( 0 , 0 , 0 , 1280 , { } , server_cookie_bad ) ) ;
. add_additional ( new DNSOptRR ( 0 , 0 , 0 , 1280 , { } , server_cookie_bad , false ) ) ;
EXPECT_CALL ( server_ , OnRequest ( " www.google.com " , T_A ) )
. WillOnce ( SetReply ( & server_ , & reply_badcookielen ) )
@ -1665,17 +1672,17 @@ TEST_P(MockUDPChannelTest, DNSCookieServerRotate) {
reply_cookie1 . set_response ( ) . set_aa ( )
. add_question ( new DNSQuestion ( " www.google.com " , T_A ) )
. add_answer ( new DNSARR ( " www.google.com " , 0x0100 , { 0x01 , 0x02 , 0x03 , 0x04 } ) )
. add_additional ( new DNSOptRR ( 0 , 0 , 0 , 1280 , { } , server_cookie ) ) ;
. add_additional ( new DNSOptRR ( 0 , 0 , 0 , 1280 , { } , server_cookie , false ) ) ;
DNSPacket reply_cookie2_badcookie ;
reply_cookie2_badcookie . set_response ( ) . set_aa ( ) . set_rcode ( ARES_RCODE_BADCOOKIE & 0xF )
. add_question ( new DNSQuestion ( " www.google.com " , T_A ) )
. add_answer ( new DNSARR ( " www.google.com " , 0x0100 , { 0x01 , 0x02 , 0x03 , 0x04 } ) )
. add_additional ( new DNSOptRR ( ( ARES_RCODE_BADCOOKIE > > 4 ) & 0xFF , 0 , 0 , 1280 , { } , server_cookie_rotate ) ) ;
. add_additional ( new DNSOptRR ( ( ARES_RCODE_BADCOOKIE > > 4 ) & 0xFF , 0 , 0 , 1280 , { } , server_cookie_rotate , false ) ) ;
DNSPacket reply_cookie2 ;
reply_cookie2 . set_response ( ) . set_aa ( )
. add_question ( new DNSQuestion ( " www.google.com " , T_A ) )
. add_answer ( new DNSARR ( " www.google.com " , 0x0100 , { 0x01 , 0x02 , 0x03 , 0x04 } ) )
. add_additional ( new DNSOptRR ( 0 , 0 , 0 , 1280 , { } , server_cookie_rotate ) ) ;
. add_additional ( new DNSOptRR ( 0 , 0 , 0 , 1280 , { } , server_cookie_rotate , true ) ) ;
EXPECT_CALL ( server_ , OnRequest ( " www.google.com " , T_A ) )
. WillOnce ( SetReply ( & server_ , & reply_cookie1 ) )
@ -1717,12 +1724,12 @@ TEST_P(MockUDPChannelTest, DNSCookieSpoof) {
reply_spoof . set_response ( ) . set_aa ( )
. add_question ( new DNSQuestion ( " www.google.com " , T_A ) )
. add_answer ( new DNSARR ( " www.google.com " , 0x0100 , { 0x01 , 0x02 , 0x03 , 0x04 } ) )
. add_additional ( new DNSOptRR ( 0 , 0 , 0 , 1280 , client_cookie , server_cookie ) ) ;
. add_additional ( new DNSOptRR ( 0 , 0 , 0 , 1280 , client_cookie , server_cookie , false ) ) ;
DNSPacket reply ;
reply . set_response ( ) . set_aa ( )
. add_question ( new DNSQuestion ( " www.google.com " , T_A ) )
. add_answer ( new DNSARR ( " www.google.com " , 0x0100 , { 0x01 , 0x02 , 0x03 , 0x04 } ) )
. add_additional ( new DNSOptRR ( 0 , 0 , 0 , 1280 , { } , server_cookie ) ) ;
. add_additional ( new DNSOptRR ( 0 , 0 , 0 , 1280 , { } , server_cookie , false ) ) ;
EXPECT_CALL ( server_ , OnRequest ( " www.google.com " , T_A ) )
. WillOnce ( SetReply ( & server_ , & reply_spoof ) )
@ -1745,12 +1752,12 @@ TEST_P(MockUDPChannelTest, DNSCookieTCPUpgrade) {
reply_badcookie . set_response ( ) . set_aa ( ) . set_rcode ( ARES_RCODE_BADCOOKIE & 0xF )
. add_question ( new DNSQuestion ( " www.google.com " , T_A ) )
. add_answer ( new DNSARR ( " www.google.com " , 0x0100 , { 0x01 , 0x02 , 0x03 , 0x04 } ) )
. add_additional ( new DNSOptRR ( ( ARES_RCODE_BADCOOKIE > > 4 ) & 0xFF , 0 , 0 , 1280 , { } , server_cookie ) ) ;
. add_additional ( new DNSOptRR ( ( ARES_RCODE_BADCOOKIE > > 4 ) & 0xFF , 0 , 0 , 1280 , { } , server_cookie , false ) ) ;
DNSPacket reply ;
reply . set_response ( ) . set_aa ( )
. add_question ( new DNSQuestion ( " www.google.com " , T_A ) )
. add_answer ( new DNSARR ( " www.google.com " , 0x0100 , { 0x01 , 0x02 , 0x03 , 0x04 } ) )
. add_additional ( new DNSOptRR ( 0 , 0 , 0 , 1280 , { } , { } ) ) ;
. add_additional ( new DNSOptRR ( 0 , 0 , 0 , 1280 , { } , { } , false ) ) ;
EXPECT_CALL ( server_ , OnRequest ( " www.google.com " , T_A ) )
. WillOnce ( SetReply ( & server_ , & reply_badcookie ) )