[email protected] | 1a49a43 | 2013-12-10 20:33:25 | [diff] [blame] | 1 | // 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 Horo | 4f516be | 2022-06-14 11:53:13 | [diff] [blame^] | 13 | namespace net::ct { |
[email protected] | 1a49a43 | 2013-12-10 20:33:25 | [diff] [blame] | 14 | |
| 15 | namespace { |
| 16 | |
| 17 | const char kLogDescription[] = "somelog"; |
| 18 | |
| 19 | class SignedCertificateTimestampTest : public ::testing::Test { |
| 20 | public: |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 21 | void SetUp() override { |
[email protected] | 1a49a43 | 2013-12-10 20:33:25 | [diff] [blame] | 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 | |
| 31 | TEST_F(SignedCertificateTimestampTest, PicklesAndUnpickles) { |
brettw | bd4d711 | 2015-06-03 04:29:25 | [diff] [blame] | 32 | base::Pickle pickle; |
[email protected] | 1a49a43 | 2013-12-10 20:33:25 | [diff] [blame] | 33 | |
| 34 | sample_sct_->Persist(&pickle); |
brettw | bd4d711 | 2015-06-03 04:29:25 | [diff] [blame] | 35 | base::PickleIterator iter(pickle); |
[email protected] | 1a49a43 | 2013-12-10 20:33:25 | [diff] [blame] | 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 | |
eranm | 028c4d6 | 2015-03-15 10:25:55 | [diff] [blame] | 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 | |
[email protected] | 1a49a43 | 2013-12-10 20:33:25 | [diff] [blame] | 59 | } // namespace |
| 60 | |
Tsuyoshi Horo | 4f516be | 2022-06-14 11:53:13 | [diff] [blame^] | 61 | } // namespace net::ct |