1 // Copyright 2013 The Chromium Authors
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 "net/cert/signed_certificate_timestamp.h"
6
7 #include <string>
8
9 #include "base/pickle.h"
10 #include "net/test/ct_test_util.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace net::ct {
14
15 namespace {
16
17 const char kLogDescription[] = "somelog";
18
19 class SignedCertificateTimestampTest : public ::testing::Test {
20 public:
SetUp()21 void SetUp() override {
22 GetX509CertSCT(&sample_sct_);
23 sample_sct_->origin = SignedCertificateTimestamp::SCT_FROM_OCSP_RESPONSE;
24 sample_sct_->log_description = kLogDescription;
25 }
26
27 protected:
28 scoped_refptr<SignedCertificateTimestamp> sample_sct_;
29 };
30
TEST_F(SignedCertificateTimestampTest,PicklesAndUnpickles)31 TEST_F(SignedCertificateTimestampTest, PicklesAndUnpickles) {
32 base::Pickle pickle;
33
34 sample_sct_->Persist(&pickle);
35 base::PickleIterator iter(pickle);
36
37 scoped_refptr<SignedCertificateTimestamp> unpickled_sct(
38 SignedCertificateTimestamp::CreateFromPickle(&iter));
39
40 SignedCertificateTimestamp::LessThan less_than;
41
42 ASSERT_FALSE(less_than(sample_sct_, unpickled_sct));
43 ASSERT_FALSE(less_than(unpickled_sct, sample_sct_));
44 ASSERT_EQ(sample_sct_->origin, unpickled_sct->origin);
45 ASSERT_EQ(sample_sct_->log_description, unpickled_sct->log_description);
46 }
47
TEST_F(SignedCertificateTimestampTest,SCTsWithDifferentOriginsNotEqual)48 TEST_F(SignedCertificateTimestampTest, SCTsWithDifferentOriginsNotEqual) {
49 scoped_refptr<SignedCertificateTimestamp> another_sct;
50 GetX509CertSCT(&another_sct);
51 another_sct->origin = SignedCertificateTimestamp::SCT_FROM_TLS_EXTENSION;
52
53 SignedCertificateTimestamp::LessThan less_than;
54
55 ASSERT_TRUE(less_than(sample_sct_, another_sct) ||
56 less_than(another_sct, sample_sct_));
57 }
58
59 } // namespace
60
61 } // namespace net::ct
62