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

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: Bump version number 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 29 matching lines...) Expand all
40 // 0x16, 0xab, 0xb4, 0x86, 0xea, 0xf3, 0x35, 0xc6, 0xca 40 // 0x16, 0xab, 0xb4, 0x86, 0xea, 0xf3, 0x35, 0xc6, 0xca
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 // Generate this token with the command (in tools/origin_trials):
51 // generate_token.py valid.example.com Frobulate --expire-timestamp=2000000000
50 const char kSampleToken[] = 52 const char kSampleToken[] =
51 "1|w694328Rl8l2vd96nkbAumpwvOOnvhWTj9/pfBRkvcWMDAsmiMEhZGEPzdBRy5Yao6il5qC" 53 "AuR/1mg+/w5ROLN54Ok20rApK3opgR7Tq9ZfzhATQmnCa+BtPA1RRw4Nigf336r+"
52 "OyS6Ah7uuHf7JAQ==|https://valid.example.com|Frobulate|2000000000"; 54 "O4fM3Sa+MEd+5JcIgSZafw8AAABZeyJvcmlnaW4iOiAiaHR0cHM6Ly92YWxpZC5l"
55 "eGFtcGxlLmNvbTo0NDMiLCAiZmVhdHVyZSI6ICJGcm9idWxhdGUiLCAiZXhwaXJ5"
56 "IjogMjAwMDAwMDAwMH0=";
53 57
54 // The token should be valid for this origin and for this feature. 58 // The token should be valid for this origin and for this feature.
55 const char kAppropriateOrigin[] = "https://valid.example.com"; 59 const char kAppropriateOrigin[] = "https://valid.example.com";
56 const char kAppropriateFeatureName[] = "Frobulate"; 60 const char kAppropriateFeatureName[] = "Frobulate";
57 61
58 const char kInappropriateFeatureName[] = "Grokalyze"; 62 const char kInappropriateFeatureName[] = "Grokalyze";
59 const char kInappropriateOrigin[] = "https://invalid.example.com"; 63 const char kInappropriateOrigin[] = "https://invalid.example.com";
60 const char kInsecureOrigin[] = "http://valid.example.com"; 64 const char kInsecureOrigin[] = "http://valid.example.com";
61 65
62 // Well-formed trial token with an invalid signature. 66 // Well-formed trial token with an invalid signature.
67 // This token is a corruption of the above valid token.
63 const char kInvalidSignatureToken[] = 68 const char kInvalidSignatureToken[] =
64 "1|CO8hDne98QeFeOJ0DbRZCBN3uE0nyaPgaLlkYhSWnbRoDfEAg+TXELaYfQPfEvKYFauBg/h" 69 "AuR/1mg+/w5ROLN54Ok20rApK3opgR7Tq9ZfzhATQmnCa+BtPA1RRw4Nigf336r+"
65 "nxmba765hz0mXMc==|https://valid.example.com|Frobulate|2000000000"; 70 "RrOtlAwa0gPqqn+A8GTD3AQAAABZeyJvcmlnaW4iOiAiaHR0cHM6Ly92YWxpZC5l"
71 "eGFtcGxlLmNvbTo0NDMiLCAiZmVhdHVyZSI6ICJGcm9idWxhdGUiLCAiZXhwaXJ5"
72 "IjogMjAwMDAwMDAwMH0=";
66 73
67 // Well-formed, but expired, trial token. (Expired in 2001) 74 // Well-formed, but expired, trial token. (Expired in 2001)
75 // Generate this token with the command (in tools/origin_trials):
76 // generate_token.py valid.example.com Frobulate --expire-timestamp=1000000000
68 const char kExpiredToken[] = 77 const char kExpiredToken[] =
69 "1|Vtzq/H0qMxsMXPThIgGEvI13d3Fd8K3W11/0E+FrJJXqBpx6n/dFkeFkEUsPaP3KeT8PCPF" 78 "AmHPUIXMaXe9jWW8kJeDFXolVjT93p4XMnK4+jMYd2pjqtFcYB1bUmdD8PunQKM+"
70 "1zpZ7kVgWYRLpAA==|https://valid.example.com|Frobulate|1000000000"; 79 "RrOtlAwa0gPqqn+A8GTD3AQAAABZeyJvcmlnaW4iOiAiaHR0cHM6Ly92YWxpZC5l"
80 "eGFtcGxlLmNvbTo0NDMiLCAiZmVhdHVyZSI6ICJGcm9idWxhdGUiLCAiZXhwaXJ5"
81 "IjogMTAwMDAwMDAwMH0=";
71 82
72 const char kUnparsableToken[] = "abcde"; 83 const char kUnparsableToken[] = "abcde";
73 84
74 class TestContentClient : public ContentClient { 85 class TestContentClient : public ContentClient {
75 public: 86 public:
76 base::StringPiece GetOriginTrialPublicKey() override { 87 base::StringPiece GetOriginTrialPublicKey() override {
77 return base::StringPiece(reinterpret_cast<const char*>(key_), 88 return base::StringPiece(reinterpret_cast<const char*>(key_),
78 arraysize(kTestPublicKey)); 89 arraysize(kTestPublicKey));
79 } 90 }
80 void SetOriginTrialPublicKey(const uint8_t* key) { key_ = key; } 91 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)); 150 kExpiredToken, appropriate_origin_, kAppropriateFeatureName));
140 } 151 }
141 152
142 TEST_F(TrialTokenValidatorTest, ValidateValidTokenWithIncorrectKey) { 153 TEST_F(TrialTokenValidatorTest, ValidateValidTokenWithIncorrectKey) {
143 SetPublicKey(kTestPublicKey2); 154 SetPublicKey(kTestPublicKey2);
144 EXPECT_FALSE(TrialTokenValidator::ValidateToken( 155 EXPECT_FALSE(TrialTokenValidator::ValidateToken(
145 kSampleToken, appropriate_origin_, kAppropriateFeatureName)); 156 kSampleToken, appropriate_origin_, kAppropriateFeatureName));
146 } 157 }
147 158
148 } // namespace content 159 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698