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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/common/origin_trials/trial_token_validator.h" 5 #include "content/common/origin_trials/trial_token_validator.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 10
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 // Well-formed token, for an insecure origin. 91 // Well-formed token, for an insecure origin.
92 // Generate this token with the command (in tools/origin_trials): 92 // Generate this token with the command (in tools/origin_trials):
93 // generate_token.py http://valid.example.com Frobulate 93 // generate_token.py http://valid.example.com Frobulate
94 // --expire-timestamp=2000000000 94 // --expire-timestamp=2000000000
95 const char kInsecureOriginToken[] = 95 const char kInsecureOriginToken[] =
96 "AjfC47H1q8/Ho5ALFkjkwf9CBK6oUUeRTlFc50Dj+eZEyGGKFIY2WTxMBfy8cLc3" 96 "AjfC47H1q8/Ho5ALFkjkwf9CBK6oUUeRTlFc50Dj+eZEyGGKFIY2WTxMBfy8cLc3"
97 "E0nmFroDA3OmABmO5jMCFgkAAABXeyJvcmlnaW4iOiAiaHR0cDovL3ZhbGlkLmV4" 97 "E0nmFroDA3OmABmO5jMCFgkAAABXeyJvcmlnaW4iOiAiaHR0cDovL3ZhbGlkLmV4"
98 "YW1wbGUuY29tOjgwIiwgImZlYXR1cmUiOiAiRnJvYnVsYXRlIiwgImV4cGlyeSI6" 98 "YW1wbGUuY29tOjgwIiwgImZlYXR1cmUiOiAiRnJvYnVsYXRlIiwgImV4cGlyeSI6"
99 "IDIwMDAwMDAwMDB9"; 99 "IDIwMDAwMDAwMDB9";
100 100
101 // These timestamps should be in the past and future, respectively. Sanity
102 // checks within the tests assert that that is true, to guard against poorly-set
103 // system clocks. (And against the inevitable march of time past the year 2033)
104 double kPastTimestamp = 1000000000;
105 double kFutureTimestamp = 2000000000;
Marc Treib 2016/12/08 16:40:45 Should probably make these const
106
101 class TestOriginTrialPolicy : public OriginTrialPolicy { 107 class TestOriginTrialPolicy : public OriginTrialPolicy {
102 public: 108 public:
103 base::StringPiece GetPublicKey() const override { 109 base::StringPiece GetPublicKey() const override {
104 return base::StringPiece(reinterpret_cast<const char*>(key_), 110 return base::StringPiece(reinterpret_cast<const char*>(key_),
105 arraysize(kTestPublicKey)); 111 arraysize(kTestPublicKey));
106 } 112 }
107 bool IsFeatureDisabled(base::StringPiece feature) const override { 113 bool IsFeatureDisabled(base::StringPiece feature) const override {
108 return disabled_features_.count(feature.as_string()) > 0; 114 return disabled_features_.count(feature.as_string()) > 0;
109 } 115 }
110 116
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 : appropriate_origin_(GURL(kAppropriateOrigin)), 151 : appropriate_origin_(GURL(kAppropriateOrigin)),
146 inappropriate_origin_(GURL(kInappropriateOrigin)), 152 inappropriate_origin_(GURL(kInappropriateOrigin)),
147 insecure_origin_(GURL(kInsecureOrigin)), 153 insecure_origin_(GURL(kInsecureOrigin)),
148 response_headers_(new net::HttpResponseHeaders("")) { 154 response_headers_(new net::HttpResponseHeaders("")) {
149 SetPublicKey(kTestPublicKey); 155 SetPublicKey(kTestPublicKey);
150 SetContentClient(&test_content_client_); 156 SetContentClient(&test_content_client_);
151 } 157 }
152 158
153 ~TrialTokenValidatorTest() override { SetContentClient(nullptr); } 159 ~TrialTokenValidatorTest() override { SetContentClient(nullptr); }
154 160
161 void SetUp() override {
162 // Ensure that the system clock is set to a date that the matches the test
163 // expectations. If this fails, either the clock on the test device is
164 // incorrect, or the actual date is after 2033-05-18, and the tokens need to
165 // be regenerated.
166 ASSERT_GT(base::Time::Now(), base::Time::FromDoubleT(kPastTimestamp));
167 ASSERT_LT(base::Time::Now(), base::Time::FromDoubleT(kFutureTimestamp));
168 }
169
155 void SetPublicKey(const uint8_t* key) { 170 void SetPublicKey(const uint8_t* key) {
156 test_content_client_.SetOriginTrialPublicKey(key); 171 test_content_client_.SetOriginTrialPublicKey(key);
157 } 172 }
158 173
159 void DisableFeature(const std::string& feature) { 174 void DisableFeature(const std::string& feature) {
160 test_content_client_.DisableFeature(feature); 175 test_content_client_.DisableFeature(feature);
161 } 176 }
162 177
163 const url::Origin appropriate_origin_; 178 const url::Origin appropriate_origin_;
164 const url::Origin inappropriate_origin_; 179 const url::Origin inappropriate_origin_;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 kAppropriateFeatureName)); 289 kAppropriateFeatureName));
275 EXPECT_FALSE(TrialTokenValidator::RequestEnablesFeature( 290 EXPECT_FALSE(TrialTokenValidator::RequestEnablesFeature(
276 GURL(kAppropriateOrigin), response_headers_.get(), 291 GURL(kAppropriateOrigin), response_headers_.get(),
277 kInappropriateFeatureName)); 292 kInappropriateFeatureName));
278 EXPECT_FALSE(TrialTokenValidator::RequestEnablesFeature( 293 EXPECT_FALSE(TrialTokenValidator::RequestEnablesFeature(
279 GURL(kInappropriateOrigin), response_headers_.get(), 294 GURL(kInappropriateOrigin), response_headers_.get(),
280 kAppropriateFeatureName)); 295 kAppropriateFeatureName));
281 } 296 }
282 297
283 } // namespace content 298 } // namespace content
OLDNEW
« 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