OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.h" | 5 #include "content/common/origin_trials/trial_token.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/strings/string_piece.h" | 9 #include "base/strings/string_piece.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 30 matching lines...) Expand all Loading... | |
41 // 0x07, 0x4d, 0x76, 0x55, 0x56, 0x42, 0x17, 0x2d, 0x8a, 0x9c, 0x47, | 41 // 0x07, 0x4d, 0x76, 0x55, 0x56, 0x42, 0x17, 0x2d, 0x8a, 0x9c, 0x47, |
42 // 0x96, 0x25, 0xda, 0x70, 0xaa, 0xb9, 0xfd, 0x53, 0x5d, 0x51, 0x3e, | 42 // 0x96, 0x25, 0xda, 0x70, 0xaa, 0xb9, 0xfd, 0x53, 0x5d, 0x51, 0x3e, |
43 // 0x16, 0xab, 0xb4, 0x86, 0xea, 0xf3, 0x35, 0xc6, 0xca | 43 // 0x16, 0xab, 0xb4, 0x86, 0xea, 0xf3, 0x35, 0xc6, 0xca |
44 const uint8_t kTestPublicKey2[] = { | 44 const uint8_t kTestPublicKey2[] = { |
45 0x50, 0x07, 0x4d, 0x76, 0x55, 0x56, 0x42, 0x17, 0x2d, 0x8a, 0x9c, | 45 0x50, 0x07, 0x4d, 0x76, 0x55, 0x56, 0x42, 0x17, 0x2d, 0x8a, 0x9c, |
46 0x47, 0x96, 0x25, 0xda, 0x70, 0xaa, 0xb9, 0xfd, 0x53, 0x5d, 0x51, | 46 0x47, 0x96, 0x25, 0xda, 0x70, 0xaa, 0xb9, 0xfd, 0x53, 0x5d, 0x51, |
47 0x3e, 0x16, 0xab, 0xb4, 0x86, 0xea, 0xf3, 0x35, 0xc6, 0xca, | 47 0x3e, 0x16, 0xab, 0xb4, 0x86, 0xea, 0xf3, 0x35, 0xc6, 0xca, |
48 }; | 48 }; |
49 | 49 |
50 // This is a good trial token, signed with the above test private key. | 50 // This is a good trial token, signed with the above test private key. |
51 // Generate this token with the command (in tools/origin_trials): | |
52 // generate_token.py valid.example.com Frobulate --expire-timestamp=1458766277 | |
51 const char* kSampleToken = | 53 const char* kSampleToken = |
52 "1|UsEO0cNxoUtBnHDJdGPWTlXuLENjXcEIPL7Bs7sbvicPCcvAtyqhQuTJ9h/u1R3VZpWigtI+" | 54 "Ap+Q/Qm0ELadZql+dlEGSwnAVsFZKgCEtUZg8idQC3uekkIeSZIY1tftoYdrwhqj" |
53 "SdUwk7Dyk/qbDw==|https://valid.example.com|Frobulate|1458766277"; | 55 "7FO5L22sNvkZZnacLvmfNwsAAABZeyJvcmlnaW4iOiAiaHR0cHM6Ly92YWxpZC5l" |
54 const uint8_t kExpectedVersion = 1; | 56 "eGFtcGxlLmNvbTo0NDMiLCAiZmVhdHVyZSI6ICJGcm9idWxhdGUiLCAiZXhwaXJ5" |
55 const char* kExpectedSignature = | 57 "IjogMTQ1ODc2NjI3N30="; |
56 "UsEO0cNxoUtBnHDJdGPWTlXuLENjXcEIPL7Bs7sbvicPCcvAtyqhQuTJ9h/u1R3VZpWigtI+S" | 58 |
57 "dUwk7Dyk/qbDw=="; | |
58 const char* kExpectedData = "https://valid.example.com|Frobulate|1458766277"; | |
59 const char* kExpectedFeatureName = "Frobulate"; | 59 const char* kExpectedFeatureName = "Frobulate"; |
60 const char* kExpectedOrigin = "https://valid.example.com"; | 60 const char* kExpectedOrigin = "https://valid.example.com"; |
61 const uint64_t kExpectedExpiry = 1458766277; | 61 const uint64_t kExpectedExpiry = 1458766277; |
62 | 62 |
63 // The token should not be valid for this origin, or for this feature. | 63 // The token should not be valid for this origin, or for this feature. |
64 const char* kInvalidOrigin = "https://invalid.example.com"; | 64 const char* kInvalidOrigin = "https://invalid.example.com"; |
65 const char* kInsecureOrigin = "http://valid.example.com"; | 65 const char* kInsecureOrigin = "http://valid.example.com"; |
66 const char* kInvalidFeatureName = "Grokalyze"; | 66 const char* kInvalidFeatureName = "Grokalyze"; |
67 | 67 |
68 // The token should be valid if the current time is kValidTimestamp or earlier. | 68 // The token should be valid if the current time is kValidTimestamp or earlier. |
69 double kValidTimestamp = 1458766276.0; | 69 double kValidTimestamp = 1458766276.0; |
70 | 70 |
71 // The token should be invalid if the current time is kInvalidTimestamp or | 71 // The token should be invalid if the current time is kInvalidTimestamp or |
72 // later. | 72 // later. |
73 double kInvalidTimestamp = 1458766278.0; | 73 double kInvalidTimestamp = 1458766278.0; |
74 | 74 |
75 // Well-formed trial token with an invalid signature. | 75 // Well-formed trial token with an invalid signature. |
76 const char* kInvalidSignatureToken = | 76 const char* kInvalidSignatureToken = |
77 "1|CO8hDne98QeFeOJ0DbRZCBN3uE0nyaPgaLlkYhSWnbRoDfEAg+TXELaYfQPfEvKYFauBg/" | 77 "AYeNXSDktgG9p4ns5B1WKsLq2TytMxfR4whfbi+oyT0rXyzh+qXYfxbDMGmyjU2Z" |
78 "hnxmba765hz0mXMc==|https://valid.example.com|Frobulate|1458766277"; | 78 "lEJ16vQObMXJoOaYUqd8xwkAAABZeyJvcmlnaW4iOiAiaHR0cHM6Ly92YWxpZC5l" |
79 "eGFtcGxlLmNvbTo0NDMiLCAiZmVhdHVyZSI6ICJGcm9idWxhdGUiLCAiZXhwaXJ5" | |
80 "IjogMTQ1ODc2NjI3N30="; | |
81 | |
82 // Trial token truncated in the middle of the length field; too short to | |
83 // possibly be valid. | |
84 const char kTruncatedToken[] = | |
85 "Ap+Q/Qm0ELadZql+dlEGSwnAVsFZKgCEtUZg8idQC3uekkIeSZIY1tftoYdrwhqj" | |
86 "7FO5L22sNvkZZnacLvmfNwsA"; | |
87 | |
88 // Trial token with an incorrectly-declared length, but with a valid signature. | |
89 const char kIncorrectLengthToken[] = | |
90 "Ao06eNl/CZuM88qurWKX4RfoVEpHcVHWxdOTrEXZkaC1GUHyb/8L4sthADiVWdc9" | |
91 "kXFyF1BW5bbraqp6MBVr3wEAAABaeyJvcmlnaW4iOiAiaHR0cHM6Ly92YWxpZC5l" | |
92 "eGFtcGxlLmNvbTo0NDMiLCAiZmVhdHVyZSI6ICJGcm9idWxhdGUiLCAiZXhwaXJ5" | |
93 "IjogMTQ1ODc2NjI3N30="; | |
94 | |
95 // Trial token with a misidentified version (42). | |
96 const char kIncorrectVersionToken[] = | |
97 "KlH8wVLT5o59uDvlJESorMDjzgWnvG1hmIn/GiT9Ng3f45ratVeiXCNTeaJheOaG" | |
98 "A6kX4ir4Amv8aHVC+OJHZQkAAABZeyJvcmlnaW4iOiAiaHR0cHM6Ly92YWxpZC5l" | |
99 "eGFtcGxlLmNvbTo0NDMiLCAiZmVhdHVyZSI6ICJGcm9idWxhdGUiLCAiZXhwaXJ5" | |
100 "IjogMTQ1ODc2NjI3N30="; | |
101 | |
102 const char kSampleTokenJSON[] = | |
103 "{\"origin\": \"https://valid.example.com:443\", \"feature\": " | |
104 "\"Frobulate\", \"expiry\": 1458766277}"; | |
79 | 105 |
80 // Various ill-formed trial tokens. These should all fail to parse. | 106 // Various ill-formed trial tokens. These should all fail to parse. |
81 const char* kInvalidTokens[] = { | 107 const char* kInvalidTokens[] = { |
82 // Invalid - only one part | 108 // Invalid - Not JSON at all |
83 "abcde", | 109 "abcde", |
84 // Not enough parts | 110 // Invalid JSON |
85 "https://valid.example.com|FeatureName|1458766277", | 111 "{", |
86 "Signature|https://valid.example.com|FeatureName|1458766277", | 112 // Not an object |
87 // Non-numeric version | 113 "\"abcde\"", |
88 "a|Signature|https://valid.example.com|FeatureName|1458766277", | 114 "123.4", |
89 "1x|Signature|https://valid.example.com|FeatureName|1458766277", | 115 "[0, 1, 2]", |
90 // Unsupported version (< min, > max, negative, overflow) | 116 // Missing keys |
91 "0|Signature|https://valid.example.com|FeatureName|1458766277", | 117 "{}", |
92 "2|Signature|https://valid.example.com|FeatureName|1458766277", | 118 "{\"something\": 1}", |
93 "-1|Signature|https://valid.example.com|FeatureName|1458766277", | 119 "{\"origin\": \"https://a.a\"}", |
94 "99999|Signature|https://valid.example.com|FeatureName|1458766277", | 120 "{\"origin\": \"https://a.a\", \"feature\": \"a\"}" |
95 // Delimiter in feature name | 121 "{\"origin\": \"https://a.a\", \"expiry\": 1458766277}", |
96 "1|Signature|https://valid.example.com|Feature|Name|1458766277", | 122 "{\"feature\": \"FeatureName\", \"expiry\": 1458766277}", |
97 // Extra string field | 123 // Incorrect types |
98 "1|Signature|https://valid.example.com|FeatureName|1458766277|ExtraField", | 124 "{\"origin\": 1, \"feature\": \"a\", \"expiry\": 1458766277}", |
99 // Extra numeric field | 125 "{\"origin\": \"https://a.a\", \"feature\": 1, \"expiry\": 1458766277}", |
100 "1|Signature|https://valid.example.com|FeatureName|1458766277|1458766277", | 126 "{\"origin\": \"https://a.a\", \"feature\": \"a\", \"expiry\": \"1\"}", |
101 // Non-numeric expiry timestamp | |
102 "1|Signature|https://valid.example.com|FeatureName|abcdefghij", | |
103 "1|Signature|https://valid.example.com|FeatureName|1458766277x", | |
104 // Negative expiry timestamp | 127 // Negative expiry timestamp |
105 "1|Signature|https://valid.example.com|FeatureName|-1458766277", | 128 "{\"origin\": \"https://a.a\", \"feature\": \"a\", \"expiry\": -1}", |
106 // Origin not a proper origin URL | 129 // Origin not a proper origin URL |
107 "1|Signature|abcdef|FeatureName|1458766277", | 130 "{\"origin\": \"abcdef\", \"feature\": \"a\", \"expiry\": 1458766277}", |
108 "1|Signature|data:text/plain,abcdef|FeatureName|1458766277", | 131 "{\"origin\": \"data:text/plain,abcdef\", \"feature\": \"a\", \"expiry\": " |
109 "1|Signature|javascript:alert(1)|FeatureName|1458766277"}; | 132 "1458766277}", |
133 "{\"origin\": \"javascript:alert(1)\", \"feature\": \"a\", \"expiry\": " | |
134 "1458766277}"}; | |
110 const size_t kNumInvalidTokens = arraysize(kInvalidTokens); | 135 const size_t kNumInvalidTokens = arraysize(kInvalidTokens); |
111 | 136 |
112 } // namespace | 137 } // namespace |
113 | 138 |
114 class TrialTokenTest : public testing::Test { | 139 class TrialTokenTest : public testing::Test { |
115 public: | 140 public: |
116 TrialTokenTest() | 141 TrialTokenTest() |
117 : expected_origin_(GURL(kExpectedOrigin)), | 142 : expected_origin_(GURL(kExpectedOrigin)), |
118 invalid_origin_(GURL(kInvalidOrigin)), | 143 invalid_origin_(GURL(kInvalidOrigin)), |
119 insecure_origin_(GURL(kInsecureOrigin)), | 144 insecure_origin_(GURL(kInsecureOrigin)), |
145 expected_expiry_(base::Time::FromDoubleT(kExpectedExpiry)), | |
146 valid_timestamp_(base::Time::FromDoubleT(kValidTimestamp)), | |
147 invalid_timestamp_(base::Time::FromDoubleT(kInvalidTimestamp)), | |
120 correct_public_key_( | 148 correct_public_key_( |
121 base::StringPiece(reinterpret_cast<const char*>(kTestPublicKey), | 149 base::StringPiece(reinterpret_cast<const char*>(kTestPublicKey), |
122 arraysize(kTestPublicKey))), | 150 arraysize(kTestPublicKey))), |
123 incorrect_public_key_( | 151 incorrect_public_key_( |
124 base::StringPiece(reinterpret_cast<const char*>(kTestPublicKey2), | 152 base::StringPiece(reinterpret_cast<const char*>(kTestPublicKey2), |
125 arraysize(kTestPublicKey2))) {} | 153 arraysize(kTestPublicKey2))) {} |
126 | 154 |
127 protected: | 155 protected: |
156 scoped_ptr<std::string> Extract(const std::string& token_text, | |
157 base::StringPiece public_key) { | |
158 return TrialToken::Extract(token_text, public_key); | |
159 } | |
160 scoped_ptr<TrialToken> Parse(const std::string& token_payload) { | |
161 return TrialToken::Parse(token_payload); | |
162 } | |
163 | |
128 bool ValidateOrigin(TrialToken* token, const url::Origin origin) { | 164 bool ValidateOrigin(TrialToken* token, const url::Origin origin) { |
129 return token->ValidateOrigin(origin); | 165 return token->ValidateOrigin(origin); |
130 } | 166 } |
131 | 167 |
132 bool ValidateFeatureName(TrialToken* token, const char* feature_name) { | 168 bool ValidateFeatureName(TrialToken* token, const char* feature_name) { |
133 return token->ValidateFeatureName(feature_name); | 169 return token->ValidateFeatureName(feature_name); |
134 } | 170 } |
135 | 171 |
136 bool ValidateDate(TrialToken* token, const base::Time& now) { | 172 bool ValidateDate(TrialToken* token, const base::Time& now) { |
137 return token->ValidateDate(now); | 173 return token->ValidateDate(now); |
138 } | 174 } |
139 | 175 |
140 bool ValidateSignature(TrialToken* token, | |
141 const base::StringPiece& public_key) { | |
142 return token->ValidateSignature(public_key); | |
143 } | |
144 | |
145 base::StringPiece correct_public_key() { return correct_public_key_; } | 176 base::StringPiece correct_public_key() { return correct_public_key_; } |
146 base::StringPiece incorrect_public_key() { return incorrect_public_key_; } | 177 base::StringPiece incorrect_public_key() { return incorrect_public_key_; } |
147 | 178 |
148 const url::Origin expected_origin_; | 179 const url::Origin expected_origin_; |
149 const url::Origin invalid_origin_; | 180 const url::Origin invalid_origin_; |
150 const url::Origin insecure_origin_; | 181 const url::Origin insecure_origin_; |
151 | 182 |
183 const base::Time expected_expiry_; | |
184 const base::Time valid_timestamp_; | |
185 const base::Time invalid_timestamp_; | |
186 | |
152 private: | 187 private: |
153 base::StringPiece correct_public_key_; | 188 base::StringPiece correct_public_key_; |
154 base::StringPiece incorrect_public_key_; | 189 base::StringPiece incorrect_public_key_; |
155 }; | 190 }; |
156 | 191 |
192 // Test the extraction of the signed payload from token strings. This includes | |
193 // checking the included version identifier, payload length, and cryptographic | |
194 // signature. | |
195 | |
196 /* Test verification of signature and extraction of token JSON from signed token | |
Marijn Kruisselbrink
2016/04/08 21:19:30
// is much more common to use for comments. And th
iclelland
2016/04/11 16:59:37
Done.
| |
197 */ | |
198 TEST_F(TrialTokenTest, ValidateValidSignature) { | |
199 scoped_ptr<std::string> token_payload = | |
200 Extract(kSampleToken, correct_public_key()); | |
201 ASSERT_TRUE(token_payload); | |
202 EXPECT_STREQ(kSampleTokenJSON, token_payload.get()->c_str()); | |
203 } | |
204 | |
205 TEST_F(TrialTokenTest, ValidateInvalidSignature) { | |
206 scoped_ptr<std::string> token_payload = | |
207 Extract(kInvalidSignatureToken, correct_public_key()); | |
208 ASSERT_FALSE(token_payload); | |
209 } | |
210 | |
211 TEST_F(TrialTokenTest, ValidateSignatureWithIncorrectKey) { | |
212 scoped_ptr<std::string> token_payload = | |
213 Extract(kSampleToken, incorrect_public_key()); | |
214 ASSERT_FALSE(token_payload); | |
215 } | |
216 | |
217 TEST_F(TrialTokenTest, ValidateEmptyToken) { | |
218 scoped_ptr<std::string> token_payload = Extract("", correct_public_key()); | |
219 ASSERT_FALSE(token_payload); | |
220 } | |
221 | |
222 TEST_F(TrialTokenTest, ValidateShortToken) { | |
223 scoped_ptr<std::string> token_payload = | |
224 Extract(kTruncatedToken, correct_public_key()); | |
225 ASSERT_FALSE(token_payload); | |
226 } | |
227 | |
228 TEST_F(TrialTokenTest, ValidateUnsupportedVersion) { | |
229 scoped_ptr<std::string> token_payload = | |
230 Extract(kIncorrectVersionToken, correct_public_key()); | |
231 ASSERT_FALSE(token_payload); | |
232 } | |
233 | |
234 TEST_F(TrialTokenTest, ValidateSignatureWithIncorrectLength) { | |
235 scoped_ptr<std::string> token = | |
236 Extract(kIncorrectLengthToken, correct_public_key()); | |
237 ASSERT_FALSE(token); | |
238 } | |
239 | |
240 /* Test parsing of fields from JSON token */ | |
241 | |
157 TEST_F(TrialTokenTest, ParseEmptyString) { | 242 TEST_F(TrialTokenTest, ParseEmptyString) { |
158 scoped_ptr<TrialToken> empty_token = TrialToken::Parse(""); | 243 scoped_ptr<TrialToken> empty_token = Parse(""); |
159 EXPECT_FALSE(empty_token); | 244 EXPECT_FALSE(empty_token); |
160 } | 245 } |
161 | 246 |
162 TEST_F(TrialTokenTest, ParseInvalidStrings) { | 247 TEST_F(TrialTokenTest, ParseInvalidStrings) { |
163 for (size_t i = 0; i < kNumInvalidTokens; ++i) { | 248 for (size_t i = 0; i < kNumInvalidTokens; ++i) { |
164 scoped_ptr<TrialToken> empty_token = TrialToken::Parse(kInvalidTokens[i]); | 249 scoped_ptr<TrialToken> empty_token = Parse(kInvalidTokens[i]); |
Marijn Kruisselbrink
2016/04/08 21:19:30
nit: not really part of this CL, but it would be n
iclelland
2016/04/11 16:59:37
Thanks for that pointer -- done.
| |
165 EXPECT_FALSE(empty_token) << "Invalid trial token should not parse: " | 250 EXPECT_FALSE(empty_token) << "Invalid trial token should not parse: " |
166 << kInvalidTokens[i]; | 251 << kInvalidTokens[i]; |
167 } | 252 } |
168 } | 253 } |
169 | 254 |
170 TEST_F(TrialTokenTest, ParseValidToken) { | 255 TEST_F(TrialTokenTest, ParseValidToken) { |
171 scoped_ptr<TrialToken> token = TrialToken::Parse(kSampleToken); | 256 scoped_ptr<TrialToken> token = Parse(kSampleTokenJSON); |
172 ASSERT_TRUE(token); | 257 ASSERT_TRUE(token); |
173 EXPECT_EQ(kExpectedVersion, token->version()); | |
174 EXPECT_EQ(kExpectedFeatureName, token->feature_name()); | 258 EXPECT_EQ(kExpectedFeatureName, token->feature_name()); |
175 EXPECT_EQ(kExpectedSignature, token->signature()); | |
176 EXPECT_EQ(kExpectedData, token->data()); | |
177 EXPECT_EQ(expected_origin_, token->origin()); | 259 EXPECT_EQ(expected_origin_, token->origin()); |
178 EXPECT_EQ(base::Time::FromDoubleT(kExpectedExpiry), token->expiry_time()); | 260 EXPECT_EQ(expected_expiry_, token->expiry_time()); |
179 } | 261 } |
180 | 262 |
181 TEST_F(TrialTokenTest, ValidateValidToken) { | 263 TEST_F(TrialTokenTest, ValidateValidToken) { |
182 scoped_ptr<TrialToken> token = TrialToken::Parse(kSampleToken); | 264 scoped_ptr<TrialToken> token = Parse(kSampleTokenJSON); |
183 ASSERT_TRUE(token); | 265 ASSERT_TRUE(token); |
184 EXPECT_TRUE(ValidateOrigin(token.get(), expected_origin_)); | 266 EXPECT_TRUE(ValidateOrigin(token.get(), expected_origin_)); |
185 EXPECT_FALSE(ValidateOrigin(token.get(), invalid_origin_)); | 267 EXPECT_FALSE(ValidateOrigin(token.get(), invalid_origin_)); |
186 EXPECT_FALSE(ValidateOrigin(token.get(), insecure_origin_)); | 268 EXPECT_FALSE(ValidateOrigin(token.get(), insecure_origin_)); |
187 EXPECT_TRUE(ValidateFeatureName(token.get(), kExpectedFeatureName)); | 269 EXPECT_TRUE(ValidateFeatureName(token.get(), kExpectedFeatureName)); |
188 EXPECT_FALSE(ValidateFeatureName(token.get(), kInvalidFeatureName)); | 270 EXPECT_FALSE(ValidateFeatureName(token.get(), kInvalidFeatureName)); |
189 EXPECT_FALSE(ValidateFeatureName( | 271 EXPECT_FALSE(ValidateFeatureName( |
190 token.get(), base::ToUpperASCII(kExpectedFeatureName).c_str())); | 272 token.get(), base::ToUpperASCII(kExpectedFeatureName).c_str())); |
191 EXPECT_FALSE(ValidateFeatureName( | 273 EXPECT_FALSE(ValidateFeatureName( |
192 token.get(), base::ToLowerASCII(kExpectedFeatureName).c_str())); | 274 token.get(), base::ToLowerASCII(kExpectedFeatureName).c_str())); |
193 EXPECT_TRUE( | 275 EXPECT_TRUE(ValidateDate(token.get(), valid_timestamp_)); |
194 ValidateDate(token.get(), base::Time::FromDoubleT(kValidTimestamp))); | 276 EXPECT_FALSE(ValidateDate(token.get(), invalid_timestamp_)); |
195 EXPECT_FALSE( | |
196 ValidateDate(token.get(), base::Time::FromDoubleT(kInvalidTimestamp))); | |
197 } | 277 } |
198 | 278 |
199 TEST_F(TrialTokenTest, TokenIsAppropriateForOriginAndFeature) { | 279 TEST_F(TrialTokenTest, TokenIsValidForFeature) { |
200 scoped_ptr<TrialToken> token = TrialToken::Parse(kSampleToken); | 280 scoped_ptr<TrialToken> token = Parse(kSampleTokenJSON); |
201 ASSERT_TRUE(token); | 281 ASSERT_TRUE(token); |
202 EXPECT_TRUE(token->IsAppropriate(expected_origin_, kExpectedFeatureName)); | 282 EXPECT_TRUE(token->IsValidForFeature(expected_origin_, kExpectedFeatureName, |
203 EXPECT_FALSE(token->IsAppropriate(expected_origin_, | 283 valid_timestamp_)); |
204 base::ToUpperASCII(kExpectedFeatureName))); | 284 EXPECT_FALSE(token->IsValidForFeature( |
205 EXPECT_FALSE(token->IsAppropriate(expected_origin_, | 285 expected_origin_, base::ToUpperASCII(kExpectedFeatureName), |
206 base::ToLowerASCII(kExpectedFeatureName))); | 286 valid_timestamp_)); |
207 EXPECT_FALSE(token->IsAppropriate(invalid_origin_, kExpectedFeatureName)); | 287 EXPECT_FALSE(token->IsValidForFeature( |
208 EXPECT_FALSE(token->IsAppropriate(insecure_origin_, kExpectedFeatureName)); | 288 expected_origin_, base::ToLowerASCII(kExpectedFeatureName), |
209 EXPECT_FALSE(token->IsAppropriate(expected_origin_, kInvalidFeatureName)); | 289 valid_timestamp_)); |
290 EXPECT_FALSE(token->IsValidForFeature(invalid_origin_, kExpectedFeatureName, | |
291 valid_timestamp_)); | |
292 EXPECT_FALSE(token->IsValidForFeature(insecure_origin_, kExpectedFeatureName, | |
293 valid_timestamp_)); | |
294 EXPECT_FALSE(token->IsValidForFeature(expected_origin_, kInvalidFeatureName, | |
295 valid_timestamp_)); | |
296 EXPECT_FALSE(token->IsValidForFeature(expected_origin_, kExpectedFeatureName, | |
297 invalid_timestamp_)); | |
210 } | 298 } |
211 | 299 |
212 TEST_F(TrialTokenTest, ValidateValidSignature) { | |
213 scoped_ptr<TrialToken> token = TrialToken::Parse(kSampleToken); | |
214 ASSERT_TRUE(token); | |
215 EXPECT_TRUE(ValidateSignature(token.get(), correct_public_key())); | |
216 } | |
217 | |
218 TEST_F(TrialTokenTest, ValidateInvalidSignature) { | |
219 scoped_ptr<TrialToken> token = TrialToken::Parse(kInvalidSignatureToken); | |
220 ASSERT_TRUE(token); | |
221 EXPECT_FALSE(ValidateSignature(token.get(), correct_public_key())); | |
222 } | |
223 | |
224 TEST_F(TrialTokenTest, ValidateTokenWithCorrectKey) { | |
225 scoped_ptr<TrialToken> token = TrialToken::Parse(kSampleToken); | |
226 ASSERT_TRUE(token); | |
227 EXPECT_TRUE(token->IsValid(base::Time::FromDoubleT(kValidTimestamp), | |
228 correct_public_key())); | |
229 } | |
230 | |
231 TEST_F(TrialTokenTest, ValidateSignatureWithIncorrectKey) { | |
232 scoped_ptr<TrialToken> token = TrialToken::Parse(kSampleToken); | |
233 ASSERT_TRUE(token); | |
234 EXPECT_FALSE(token->IsValid(base::Time::FromDoubleT(kValidTimestamp), | |
235 incorrect_public_key())); | |
236 } | |
237 | |
238 TEST_F(TrialTokenTest, ValidateWhenNotExpired) { | |
239 scoped_ptr<TrialToken> token = TrialToken::Parse(kSampleToken); | |
240 ASSERT_TRUE(token); | |
241 } | |
242 | 300 |
243 } // namespace content | 301 } // namespace content |
OLD | NEW |