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

Side by Side Diff: content/common/origin_trials/trial_token_validator_unittest.cc

Issue 1858763003: Change origin trial token format (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update parser unit tests, improve error detection Created 4 years, 8 months 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
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 "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_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/test/simple_test_clock.h" 10 #include "base/test/simple_test_clock.h"
(...skipping 30 matching lines...) Expand all
41 const uint8_t kTestPublicKey2[] = { 41 const uint8_t kTestPublicKey2[] = {
42 0x50, 0x07, 0x4d, 0x76, 0x55, 0x56, 0x42, 0x17, 0x2d, 0x8a, 0x9c, 42 0x50, 0x07, 0x4d, 0x76, 0x55, 0x56, 0x42, 0x17, 0x2d, 0x8a, 0x9c,
43 0x47, 0x96, 0x25, 0xda, 0x70, 0xaa, 0xb9, 0xfd, 0x53, 0x5d, 0x51, 43 0x47, 0x96, 0x25, 0xda, 0x70, 0xaa, 0xb9, 0xfd, 0x53, 0x5d, 0x51,
44 0x3e, 0x16, 0xab, 0xb4, 0x86, 0xea, 0xf3, 0x35, 0xc6, 0xca, 44 0x3e, 0x16, 0xab, 0xb4, 0x86, 0xea, 0xf3, 0x35, 0xc6, 0xca,
45 }; 45 };
46 46
47 // This is a good trial token, signed with the above test private key. 47 // This is a good trial token, signed with the above test private key.
48 // TODO(iclelland): This token expires in 2033. Update it or find a way 48 // TODO(iclelland): This token expires in 2033. Update it or find a way
49 // to autogenerate it before then. 49 // to autogenerate it before then.
50 const char kSampleToken[] = 50 const char kSampleToken[] =
51 "1|w694328Rl8l2vd96nkbAumpwvOOnvhWTj9/pfBRkvcWMDAsmiMEhZGEPzdBRy5Yao6il5qC" 51 "AQ6Xx5NT42b46tmZ7Mfd/U/qcM8l/+9gIOSXj1EUbUQ1uMmHQxJOKwU57f3kXdds"
52 "OyS6Ah7uuHf7JAQ==|https://valid.example.com|Frobulate|2000000000"; 52 "PtLMMOsKMHG8OPtF4HrEqQsAAABZeyJvcmlnaW4iOiAiaHR0cHM6Ly92YWxpZC5l"
53 "eGFtcGxlLmNvbTo0NDMiLCAiZmVhdHVyZSI6ICJGcm9idWxhdGUiLCAiZXhwaXJ5"
54 "IjogMjAwMDAwMDAwMH0=";
53 55
54 // The token should be valid for this origin and for this feature. 56 // The token should be valid for this origin and for this feature.
55 const char kAppropriateOrigin[] = "https://valid.example.com"; 57 const char kAppropriateOrigin[] = "https://valid.example.com";
56 const char kAppropriateFeatureName[] = "Frobulate"; 58 const char kAppropriateFeatureName[] = "Frobulate";
57 59
58 const char kInappropriateFeatureName[] = "Grokalyze"; 60 const char kInappropriateFeatureName[] = "Grokalyze";
59 const char kInappropriateOrigin[] = "https://invalid.example.com"; 61 const char kInappropriateOrigin[] = "https://invalid.example.com";
60 const char kInsecureOrigin[] = "http://valid.example.com"; 62 const char kInsecureOrigin[] = "http://valid.example.com";
61 63
62 // Well-formed trial token with an invalid signature. 64 // Well-formed trial token with an invalid signature.
63 const char kInvalidSignatureToken[] = 65 const char kInvalidSignatureToken[] =
64 "1|CO8hDne98QeFeOJ0DbRZCBN3uE0nyaPgaLlkYhSWnbRoDfEAg+TXELaYfQPfEvKYFauBg/h" 66 "AQ6Xx5NT42b46tmZ7Mfd/U/qcM8l/+9gIOSXj1EUbUQ1uMmHQxJOKwU57f3kXdds"
65 "nxmba765hz0mXMc==|https://valid.example.com|Frobulate|2000000000"; 67 "JgVz4lvNSyEw+r5/UlpGHQQAAABZeyJvcmlnaW4iOiAiaHR0cHM6Ly92YWxpZC5l"
68 "eGFtcGxlLmNvbTo0NDMiLCAiZmVhdHVyZSI6ICJGcm9idWxhdGUiLCAiZXhwaXJ5"
69 "IjogMTAwMDAwMDAwMH0=";
66 70
67 // Well-formed, but expired, trial token. (Expired in 2001) 71 // Well-formed, but expired, trial token. (Expired in 2001)
68 const char kExpiredToken[] = 72 const char kExpiredToken[] =
69 "1|Vtzq/H0qMxsMXPThIgGEvI13d3Fd8K3W11/0E+FrJJXqBpx6n/dFkeFkEUsPaP3KeT8PCPF" 73 "AVChEbwX8yTgZZ1ut0oWd8g/3Y8YBZp7R8SmqXv4HNGsl5b5rSON4Kizc9LdiJi0"
70 "1zpZ7kVgWYRLpAA==|https://valid.example.com|Frobulate|1000000000"; 74 "JgVz4lvNSyEw+r5/UlpGHQQAAABZeyJvcmlnaW4iOiAiaHR0cHM6Ly92YWxpZC5l"
75 "eGFtcGxlLmNvbTo0NDMiLCAiZmVhdHVyZSI6ICJGcm9idWxhdGUiLCAiZXhwaXJ5"
76 "IjogMTAwMDAwMDAwMH0=";
71 77
72 const char kUnparsableToken[] = "abcde"; 78 const char kUnparsableToken[] = "abcde";
73 79
74 class TestContentClient : public ContentClient { 80 class TestContentClient : public ContentClient {
75 public: 81 public:
76 base::StringPiece GetOriginTrialPublicKey() override { 82 base::StringPiece GetOriginTrialPublicKey() override {
77 return base::StringPiece(reinterpret_cast<const char*>(key_), 83 return base::StringPiece(reinterpret_cast<const char*>(key_),
78 arraysize(kTestPublicKey)); 84 arraysize(kTestPublicKey));
79 } 85 }
80 void SetOriginTrialPublicKey(const uint8_t* key) { key_ = key; } 86 void SetOriginTrialPublicKey(const uint8_t* key) { key_ = key; }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 kExpiredToken, appropriate_origin_, kAppropriateFeatureName)); 145 kExpiredToken, appropriate_origin_, kAppropriateFeatureName));
140 } 146 }
141 147
142 TEST_F(TrialTokenValidatorTest, ValidateValidTokenWithIncorrectKey) { 148 TEST_F(TrialTokenValidatorTest, ValidateValidTokenWithIncorrectKey) {
143 SetPublicKey(kTestPublicKey2); 149 SetPublicKey(kTestPublicKey2);
144 EXPECT_FALSE(TrialTokenValidator::ValidateToken( 150 EXPECT_FALSE(TrialTokenValidator::ValidateToken(
145 kSampleToken, appropriate_origin_, kAppropriateFeatureName)); 151 kSampleToken, appropriate_origin_, kAppropriateFeatureName));
146 } 152 }
147 153
148 } // namespace content 154 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698