Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(680)

Side by Side Diff: net/dns/dns_response_unittest.cc

Issue 15326002: Fix bug in InitParseWithoutQuestion (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/dns/dns_response.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/dns/dns_response.h" 5 #include "net/dns/dns_response.h"
6 6
7 #include "base/time.h" 7 #include "base/time.h"
8 #include "net/base/address_list.h" 8 #include "net/base/address_list.h"
9 #include "net/base/io_buffer.h" 9 #include "net/base/io_buffer.h"
10 #include "net/base/net_util.h" 10 #include "net/base/net_util.h"
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 EXPECT_FALSE(parser.AtEnd()); 371 EXPECT_FALSE(parser.AtEnd());
372 EXPECT_TRUE(parser.ReadRecord(&record)); 372 EXPECT_TRUE(parser.ReadRecord(&record));
373 EXPECT_EQ("codereview.chromium.org", record.name); 373 EXPECT_EQ("codereview.chromium.org", record.name);
374 EXPECT_EQ(0x35u, record.ttl); 374 EXPECT_EQ(0x35u, record.ttl);
375 EXPECT_EQ(dns_protocol::kTypeA, record.type); 375 EXPECT_EQ(dns_protocol::kTypeA, record.type);
376 376
377 EXPECT_TRUE(parser.AtEnd()); 377 EXPECT_TRUE(parser.AtEnd());
378 EXPECT_FALSE(parser.ReadRecord(&record)); 378 EXPECT_FALSE(parser.ReadRecord(&record));
379 } 379 }
380 380
381 TEST(DnsResponseTest, InitParseWithoutQueryPacketTooShort) {
382 const uint8 response_data[] = {
383 // Header
384 0xca, 0xfe, // ID
385 0x81, 0x80, // Standard query response, RA, no error
386 0x00, 0x00, // No question
387 };
388
389 DnsResponse resp;
390 memcpy(resp.io_buffer()->data(), response_data, sizeof(response_data));
391
392 EXPECT_FALSE(resp.InitParseWithoutQuery(sizeof(response_data)));
393 }
394
381 void VerifyAddressList(const std::vector<const char*>& ip_addresses, 395 void VerifyAddressList(const std::vector<const char*>& ip_addresses,
382 const AddressList& addrlist) { 396 const AddressList& addrlist) {
383 ASSERT_EQ(ip_addresses.size(), addrlist.size()); 397 ASSERT_EQ(ip_addresses.size(), addrlist.size());
384 398
385 for (size_t i = 0; i < addrlist.size(); ++i) { 399 for (size_t i = 0; i < addrlist.size(); ++i) {
386 EXPECT_EQ(ip_addresses[i], addrlist[i].ToStringWithoutPort()); 400 EXPECT_EQ(ip_addresses[i], addrlist[i].ToStringWithoutPort());
387 } 401 }
388 } 402 }
389 403
390 TEST(DnsResponseTest, ParseToAddressList) { 404 TEST(DnsResponseTest, ParseToAddressList) {
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 AddressList addr_list; 572 AddressList addr_list;
559 base::TimeDelta ttl; 573 base::TimeDelta ttl;
560 EXPECT_EQ(t.expected_result, 574 EXPECT_EQ(t.expected_result,
561 response.ParseToAddressList(&addr_list, &ttl)); 575 response.ParseToAddressList(&addr_list, &ttl));
562 } 576 }
563 } 577 }
564 578
565 } // namespace 579 } // namespace
566 580
567 } // namespace net 581 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/dns_response.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698