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.
5 #include "chrome/browser/safe_browsing/incident_reporting/binary_integrity_incident.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "chrome/common/safe_browsing/csd.pb.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 namespace safe_browsing
{
15 scoped_ptr
<Incident
> MakeIncident(const char* file_basename
) {
16 scoped_ptr
<ClientIncidentReport_IncidentData_BinaryIntegrityIncident
>
17 incident(new ClientIncidentReport_IncidentData_BinaryIntegrityIncident
);
19 incident
->set_file_basename(file_basename
);
22 incident
->mutable_signature()->set_trusted(true);
23 ClientDownloadRequest_CertificateChain
* certificate_chain
=
24 incident
->mutable_signature()->add_certificate_chain();
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},
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
]));
37 return make_scoped_ptr(new BinaryIntegrityIncident(incident
.Pass()));
42 TEST(BinaryIntegrityIncident
, GetType
) {
43 ASSERT_EQ(IncidentType::BINARY_INTEGRITY
, MakeIncident("foo")->GetType());
46 TEST(BinaryIntegrityIncident
, GetKeyIsFile
) {
47 ASSERT_EQ(std::string("foo"), MakeIncident("foo")->GetKey());
50 TEST(BinaryIntegrityIncident
, SameIncidentSameDigest
) {
51 ASSERT_EQ(MakeIncident("foo")->ComputeDigest(),
52 MakeIncident("foo")->ComputeDigest());
55 TEST(BinaryIntegrityIncident
, DifferentIncidentDifferentDigest
) {
56 ASSERT_NE(MakeIncident("foo")->ComputeDigest(),
57 MakeIncident("bar")->ComputeDigest());
60 } // namespace safe_browsing