| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/safe_browsing/incident_reporting/binary_integrity_incid
ent.h" |
| 6 |
| 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "chrome/common/safe_browsing/csd.pb.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 |
| 11 namespace safe_browsing { |
| 12 |
| 13 namespace { |
| 14 |
| 15 scoped_ptr<Incident> MakeIncident(const char* file_basename) { |
| 16 scoped_ptr<ClientIncidentReport_IncidentData_BinaryIntegrityIncident> |
| 17 incident(new ClientIncidentReport_IncidentData_BinaryIntegrityIncident); |
| 18 |
| 19 incident->set_file_basename(file_basename); |
| 20 |
| 21 // Set the signature. |
| 22 incident->mutable_signature()->set_trusted(true); |
| 23 ClientDownloadRequest_CertificateChain* certificate_chain = |
| 24 incident->mutable_signature()->add_certificate_chain(); |
| 25 |
| 26 // Fill the certificate chain with 2 elements. |
| 27 const unsigned char certificates[][5] = { |
| 28 {42, 255, 100, 53, 2}, |
| 29 {64, 33, 51, 91, 210}, |
| 30 }; |
| 31 for (size_t i = 0; i < arraysize(certificates); ++i) { |
| 32 ClientDownloadRequest_CertificateChain_Element* element = |
| 33 certificate_chain->add_element(); |
| 34 element->set_certificate(certificates[i], arraysize(certificates[i])); |
| 35 } |
| 36 |
| 37 return make_scoped_ptr(new BinaryIntegrityIncident(incident.Pass())); |
| 38 } |
| 39 |
| 40 } // namespace |
| 41 |
| 42 TEST(BinaryIntegrityIncident, GetType) { |
| 43 ASSERT_EQ(IncidentType::BINARY_INTEGRITY, MakeIncident("foo")->GetType()); |
| 44 } |
| 45 |
| 46 TEST(BinaryIntegrityIncident, GetKeyIsFile) { |
| 47 ASSERT_EQ(std::string("foo"), MakeIncident("foo")->GetKey()); |
| 48 } |
| 49 |
| 50 TEST(BinaryIntegrityIncident, SameIncidentSameDigest) { |
| 51 ASSERT_EQ(MakeIncident("foo")->ComputeDigest(), |
| 52 MakeIncident("foo")->ComputeDigest()); |
| 53 } |
| 54 |
| 55 TEST(BinaryIntegrityIncident, DifferentIncidentDifferentDigest) { |
| 56 ASSERT_NE(MakeIncident("foo")->ComputeDigest(), |
| 57 MakeIncident("bar")->ComputeDigest()); |
| 58 } |
| 59 |
| 60 } // namespace safe_browsing |
| OLD | NEW |