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

Unified Diff: content/common/origin_trials/trial_token_validator_unittest.cc

Issue 2559973003: Assert that the system clock is between 1e9 and 2e9 for Origin Trial token validation tests (Closed)
Patch Set: Created 4 years 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/common/origin_trials/trial_token_validator_unittest.cc
diff --git a/content/common/origin_trials/trial_token_validator_unittest.cc b/content/common/origin_trials/trial_token_validator_unittest.cc
index 19b5d44c57e6f5b46d8c425c3049c970ef8acdeb..877216a8c5bc2398e62b5b266011c0527e225471 100644
--- a/content/common/origin_trials/trial_token_validator_unittest.cc
+++ b/content/common/origin_trials/trial_token_validator_unittest.cc
@@ -98,6 +98,12 @@ const char kInsecureOriginToken[] =
"YW1wbGUuY29tOjgwIiwgImZlYXR1cmUiOiAiRnJvYnVsYXRlIiwgImV4cGlyeSI6"
"IDIwMDAwMDAwMDB9";
+// These timestamps should be in the past and future, respectively. Sanity
+// checks within the tests assert that that is true, to guard against poorly-set
+// system clocks. (And against the inevitable march of time past the year 2033)
+double kPastTimestamp = 1000000000;
+double kFutureTimestamp = 2000000000;
Marc Treib 2016/12/08 16:40:45 Should probably make these const
+
class TestOriginTrialPolicy : public OriginTrialPolicy {
public:
base::StringPiece GetPublicKey() const override {
@@ -152,6 +158,15 @@ class TrialTokenValidatorTest : public testing::Test {
~TrialTokenValidatorTest() override { SetContentClient(nullptr); }
+ void SetUp() override {
+ // Ensure that the system clock is set to a date that the matches the test
+ // expectations. If this fails, either the clock on the test device is
+ // incorrect, or the actual date is after 2033-05-18, and the tokens need to
+ // be regenerated.
+ ASSERT_GT(base::Time::Now(), base::Time::FromDoubleT(kPastTimestamp));
+ ASSERT_LT(base::Time::Now(), base::Time::FromDoubleT(kFutureTimestamp));
+ }
+
void SetPublicKey(const uint8_t* key) {
test_content_client_.SetOriginTrialPublicKey(key);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698