Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/safe_browsing_db/v4_get_hash_protocol_manager.h" | 5 #include "components/safe_browsing_db/v4_get_hash_protocol_manager.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 463 invalid->mutable_threat()->set_hash(full_hash); | 463 invalid->mutable_threat()->set_hash(full_hash); |
| 464 ThreatEntryMetadata::MetadataEntry* invalid_meta = | 464 ThreatEntryMetadata::MetadataEntry* invalid_meta = |
| 465 invalid->mutable_threat_entry_metadata()->add_entries(); | 465 invalid->mutable_threat_entry_metadata()->add_entries(); |
| 466 invalid_meta->set_key("pha_pattern_type"); | 466 invalid_meta->set_key("pha_pattern_type"); |
| 467 invalid_meta->set_value("INVALIDE_VALUE"); | 467 invalid_meta->set_value("INVALIDE_VALUE"); |
| 468 | 468 |
| 469 std::string invalid_data; | 469 std::string invalid_data; |
| 470 invalid_res.SerializeToString(&invalid_data); | 470 invalid_res.SerializeToString(&invalid_data); |
| 471 std::vector<FullHashInfo> full_hash_infos; | 471 std::vector<FullHashInfo> full_hash_infos; |
| 472 base::Time cache_expire; | 472 base::Time cache_expire; |
| 473 EXPECT_FALSE( | 473 EXPECT_TRUE( |
| 474 pm->ParseHashResponse(invalid_data, &full_hash_infos, &cache_expire)); | 474 pm->ParseHashResponse(invalid_data, &full_hash_infos, &cache_expire)); |
| 475 EXPECT_EQ(0ul, full_hash_infos.size()); | 475 |
| 476 ASSERT_EQ(1ul, full_hash_infos.size()); | |
|
Nathan Parker
2016/10/27 22:06:49
nit: Add a comment: The PHA threat still remains s
vakh (use Gerrit instead)
2016/10/27 22:40:05
Done.
| |
| 477 const auto& fhi = full_hash_infos[0]; | |
| 478 EXPECT_EQ(full_hash, fhi.full_hash); | |
| 479 EXPECT_EQ( | |
| 480 ListIdentifier(CHROME_PLATFORM, URL, POTENTIALLY_HARMFUL_APPLICATION), | |
| 481 fhi.list_id); | |
| 482 EXPECT_EQ(ThreatPatternType::NONE, fhi.metadata.threat_pattern_type); | |
| 476 } | 483 } |
| 477 } | 484 } |
| 478 | 485 |
| 479 // Adds metadata with a key value that is not "permission". | 486 // Adds metadata with a key value that is not "permission". |
| 480 TEST_F(V4GetHashProtocolManagerTest, | 487 TEST_F(V4GetHashProtocolManagerTest, |
| 481 TestParseHashResponseNonPermissionMetadata) { | 488 TestParseHashResponseNonPermissionMetadata) { |
| 482 std::unique_ptr<V4GetHashProtocolManager> pm(CreateProtocolManager()); | 489 std::unique_ptr<V4GetHashProtocolManager> pm(CreateProtocolManager()); |
| 483 | 490 |
| 484 base::Time now = base::Time::UnixEpoch(); | 491 base::Time now = base::Time::UnixEpoch(); |
| 485 SetTestClock(now, pm.get()); | 492 SetTestClock(now, pm.get()); |
| 486 | 493 |
| 494 FullHash full_hash("Not to fret."); | |
| 487 FindFullHashesResponse res; | 495 FindFullHashesResponse res; |
| 488 res.mutable_negative_cache_duration()->set_seconds(600); | 496 res.mutable_negative_cache_duration()->set_seconds(600); |
| 489 ThreatMatch* m = res.add_matches(); | 497 ThreatMatch* m = res.add_matches(); |
| 490 m->set_threat_type(API_ABUSE); | 498 m->set_threat_type(API_ABUSE); |
| 491 m->set_platform_type(CHROME_PLATFORM); | 499 m->set_platform_type(CHROME_PLATFORM); |
| 492 m->set_threat_entry_type(URL); | 500 m->set_threat_entry_type(URL); |
| 493 m->mutable_threat()->set_hash(FullHash("Not to fret.")); | 501 m->mutable_threat()->set_hash(full_hash); |
| 494 ThreatEntryMetadata::MetadataEntry* e = | 502 ThreatEntryMetadata::MetadataEntry* e = |
| 495 m->mutable_threat_entry_metadata()->add_entries(); | 503 m->mutable_threat_entry_metadata()->add_entries(); |
| 496 e->set_key("notpermission"); | 504 e->set_key("notpermission"); |
| 497 e->set_value("NOTGEOLOCATION"); | 505 e->set_value("NOTGEOLOCATION"); |
| 498 | 506 |
| 499 // Serialize. | 507 // Serialize. |
| 500 std::string res_data; | 508 std::string res_data; |
| 501 res.SerializeToString(&res_data); | 509 res.SerializeToString(&res_data); |
| 502 | 510 |
| 503 std::vector<FullHashInfo> full_hash_infos; | 511 std::vector<FullHashInfo> full_hash_infos; |
| 504 base::Time cache_expire; | 512 base::Time cache_expire; |
| 505 EXPECT_FALSE( | 513 EXPECT_TRUE(pm->ParseHashResponse(res_data, &full_hash_infos, &cache_expire)); |
| 506 pm->ParseHashResponse(res_data, &full_hash_infos, &cache_expire)); | |
| 507 | 514 |
| 508 EXPECT_EQ(now + base::TimeDelta::FromSeconds(600), cache_expire); | 515 EXPECT_EQ(now + base::TimeDelta::FromSeconds(600), cache_expire); |
| 509 EXPECT_EQ(0ul, full_hash_infos.size()); | 516 ASSERT_EQ(1ul, full_hash_infos.size()); |
| 517 const auto& fhi = full_hash_infos[0]; | |
| 518 EXPECT_EQ(full_hash, fhi.full_hash); | |
| 519 EXPECT_EQ(GetChromeUrlApiId(), fhi.list_id); | |
| 520 EXPECT_TRUE(fhi.metadata.api_permissions.empty()); | |
| 510 } | 521 } |
| 511 | 522 |
| 512 TEST_F(V4GetHashProtocolManagerTest, | 523 TEST_F(V4GetHashProtocolManagerTest, |
| 513 TestParseHashResponseInconsistentThreatTypes) { | 524 TestParseHashResponseInconsistentThreatTypes) { |
| 514 std::unique_ptr<V4GetHashProtocolManager> pm(CreateProtocolManager()); | 525 std::unique_ptr<V4GetHashProtocolManager> pm(CreateProtocolManager()); |
| 515 | 526 |
| 516 FindFullHashesResponse res; | 527 FindFullHashesResponse res; |
| 517 res.mutable_negative_cache_duration()->set_seconds(600); | 528 res.mutable_negative_cache_duration()->set_seconds(600); |
| 518 ThreatMatch* m1 = res.add_matches(); | 529 ThreatMatch* m1 = res.add_matches(); |
| 519 m1->set_threat_type(API_ABUSE); | 530 m1->set_threat_type(API_ABUSE); |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 726 full_hash = FullHash("Everything's shiny, Cap'n."); | 737 full_hash = FullHash("Everything's shiny, Cap'n."); |
| 727 info = ResponseInfo(full_hash, GetChromeUrlApiId()); | 738 info = ResponseInfo(full_hash, GetChromeUrlApiId()); |
| 728 info.key_values.emplace_back("permission", "GEOLOCATION"); | 739 info.key_values.emplace_back("permission", "GEOLOCATION"); |
| 729 infos.push_back(info); | 740 infos.push_back(info); |
| 730 SetupFetcherToReturnOKResponse(factory, infos); | 741 SetupFetcherToReturnOKResponse(factory, infos); |
| 731 | 742 |
| 732 EXPECT_TRUE(callback_called()); | 743 EXPECT_TRUE(callback_called()); |
| 733 } | 744 } |
| 734 | 745 |
| 735 } // namespace safe_browsing | 746 } // namespace safe_browsing |
| OLD | NEW |