blob: 0b9a7d96b88370f672ac6c8918ca9560481fdbae [file] [log] [blame]
[email protected]1a49a432013-12-10 20:33:251// Copyright 2013 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 "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
Tsuyoshi Horo4f516be2022-06-14 11:53:1313namespace net::ct {
[email protected]1a49a432013-12-10 20:33:2514
15namespace {
16
17const char kLogDescription[] = "somelog";
18
19class SignedCertificateTimestampTest : public ::testing::Test {
20 public:
dcheng67be2b1f2014-10-27 21:47:2921 void SetUp() override {
[email protected]1a49a432013-12-10 20:33:2522 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
31TEST_F(SignedCertificateTimestampTest, PicklesAndUnpickles) {
brettwbd4d7112015-06-03 04:29:2532 base::Pickle pickle;
[email protected]1a49a432013-12-10 20:33:2533
34 sample_sct_->Persist(&pickle);
brettwbd4d7112015-06-03 04:29:2535 base::PickleIterator iter(pickle);
[email protected]1a49a432013-12-10 20:33:2536
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
eranm028c4d62015-03-15 10:25:5548TEST_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
[email protected]1a49a432013-12-10 20:33:2559} // namespace
60
Tsuyoshi Horo4f516be2022-06-14 11:53:1361} // namespace net::ct