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