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.
4 
5 #include <iostream>
6 
7 #include "base/bind.h"
8 #include "base/build_time.h"
9 #include "base/test/launcher/unit_test_launcher.h"
10 #include "build/build_config.h"
11 #include "crypto/nss_util.h"
12 #include "net/socket/transport_client_socket_pool.h"
13 #include "net/test/net_test_suite.h"
14 #include "url/buildflags.h"
15 
16 namespace {
17 
VerifyBuildIsTimely()18 bool VerifyBuildIsTimely() {
19   // This lines up with various //net security features, like Certificate
20   // Transparency or HPKP, in that they require the build time be less than 70
21   // days old. Moreover, operating on the assumption that tests are run against
22   // recently compiled builds, this also serves as a sanity check for the
23   // system clock, which should be close to the build date.
24   base::TimeDelta kMaxAge = base::TimeDelta::FromDays(70);
25 
26   base::Time build_time = base::GetBuildTime();
27   base::Time now = base::Time::Now();
28 
29   if ((now - build_time).magnitude() <= kMaxAge)
30     return true;
31 
32   std::cerr
33       << "ERROR: This build is more than " << kMaxAge.InDays()
34       << " days out of date.\n"
35          "This could indicate a problem with the device's clock, or the build "
36          "is simply too old.\n"
37          "See crbug.com/666821 for why this is a problem\n"
38       << "    base::Time::Now() --> " << now << " (" << now.ToInternalValue()
39       << ")\n"
40       << "    base::GetBuildTime() --> " << build_time << " ("
41       << build_time.ToInternalValue() << ")\n";
42 
43   return false;
44 }
45 
46 }  // namespace
47 
main(int argc,char ** argv)48 int main(int argc, char** argv) {
49   if (!VerifyBuildIsTimely())
50     return 1;
51 
52   NetTestSuite test_suite(argc, argv);
53   net::TransportClientSocketPool::set_connect_backup_jobs_enabled(false);
54 
55   return base::LaunchUnitTests(
56       argc, argv,
57       base::BindOnce(&NetTestSuite::Run, base::Unretained(&test_suite)));
58 }
59