Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / net / cert / x509_util_openssl_unittest.cc
blob9eebff8a32ea39cb57be1ba5fd454447bd2b1486
1 // Copyright (c) 2012 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 "base/memory/scoped_ptr.h"
6 #include "crypto/ec_private_key.h"
7 #include "crypto/openssl_util.h"
8 #include "crypto/scoped_openssl_types.h"
9 #include "net/cert/x509_util.h"
10 #include "net/cert/x509_util_openssl.h"
11 #include "net/ssl/scoped_openssl_types.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 namespace net {
16 TEST(X509UtilOpenSSLTest, IsSupportedValidityRange) {
17 base::Time now = base::Time::Now();
18 EXPECT_TRUE(x509_util::IsSupportedValidityRange(now, now));
19 EXPECT_FALSE(x509_util::IsSupportedValidityRange(
20 now, now - base::TimeDelta::FromSeconds(1)));
22 // See x509_util_openssl.cc to see how these were computed.
23 const int64_t kDaysFromYear0001ToUnixEpoch = 719162;
24 const int64_t kDaysFromUnixEpochToYear10000 = 2932896 + 1;
26 // When computing too_old / too_late, add one day to account for
27 // possible leap seconds.
28 base::Time too_old = base::Time::UnixEpoch() -
29 base::TimeDelta::FromDays(kDaysFromYear0001ToUnixEpoch + 1);
31 base::Time too_late = base::Time::UnixEpoch() +
32 base::TimeDelta::FromDays(kDaysFromUnixEpochToYear10000 + 1);
34 EXPECT_FALSE(x509_util::IsSupportedValidityRange(too_old, too_old));
35 EXPECT_FALSE(x509_util::IsSupportedValidityRange(too_old, now));
37 EXPECT_FALSE(x509_util::IsSupportedValidityRange(now, too_late));
38 EXPECT_FALSE(x509_util::IsSupportedValidityRange(too_late, too_late));
41 } // namespace net