Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Unified Diff: net/test/run_all_unittests.cc

Issue 2524613002: Move the sanity check on build time vs current time to the net test (Closed)
Patch Set: update comment Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/cert/ct_policy_enforcer_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/test/run_all_unittests.cc
diff --git a/net/test/run_all_unittests.cc b/net/test/run_all_unittests.cc
index 604888e07f2ee39b6701cd9aed0b72586bbd9668..78307f756b0dcac8aa7df30bd3652a76e1ea5f50 100644
--- a/net/test/run_all_unittests.cc
+++ b/net/test/run_all_unittests.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/build_time.h"
#include "base/metrics/statistics_recorder.h"
#include "base/test/launcher/unit_test_launcher.h"
#include "build/build_config.h"
@@ -23,6 +24,38 @@
using net::internal::ClientSocketPoolBaseHelper;
+namespace {
+
+bool VerifyBuildIsTimely() {
+ // This lines up with various //net security features, like Certificate
+ // Transparency or HPKP, in that they require the build time be less than 70
+ // days old. Moreover, operating on the assumption that tests are run against
+ // recently compiled builds, this also serves as a sanity check for the
+ // system clock, which should be close to the build date.
+ base::TimeDelta kMaxAge = base::TimeDelta::FromDays(70);
+
+ base::Time build_time = base::GetBuildTime();
+ base::Time now = base::Time::Now();
+
+ if ((now - build_time).magnitude() <= kMaxAge)
+ return true;
+
+ std::cerr
+ << "ERROR: This build is more than " << kMaxAge.InDays()
+ << " days out of date.\n"
+ "This could indicate a problem with the device's clock, or the build "
+ "is simply too old.\n"
+ "See crbug.com/666821 for why this is a problem\n"
+ << " base::Time::Now() --> " << now << " (" << now.ToInternalValue()
+ << ")\n"
+ << " base::GetBuildTime() --> " << build_time << " ("
+ << build_time.ToInternalValue() << ")\n";
+
+ return false;
+}
+
+} // namespace
+
int main(int argc, char** argv) {
// Record histograms, so we can get histograms data in tests.
base::StatisticsRecorder::Initialize();
@@ -42,6 +75,9 @@ int main(int argc, char** argv) {
arraysize(kNetTestRegisteredMethods));
#endif
+ if (!VerifyBuildIsTimely())
+ return 1;
+
NetTestSuite test_suite(argc, argv);
ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false);
« no previous file with comments | « net/cert/ct_policy_enforcer_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698