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

Side by Side Diff: content/common/experiments/api_key_unittest.cc

Issue 1563903002: Add public key and signature verification to browser-side API keys Base URL: https://chromium.googlesource.com/chromium/src.git@keys
Patch Set: Created 4 years, 11 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
« no previous file with comments | « content/common/experiments/api_key.cc ('k') | content/content_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/experiments/api_key.h" 5 #include "content/common/experiments/api_key.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"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 namespace content { 14 namespace content {
15 15
16 namespace { 16 namespace {
17 17
18 // This is a good key, signed with the test private key.
18 const char* kSampleAPIKey = 19 const char* kSampleAPIKey =
19 "Signature|https://valid.example.com|Frobulate|1458766277"; 20 "fsnbBl0XwKysvzH3d4TtIomsD9teP0PFfqxIYIAksfipEjB+cXAwI0tUzkYES4H0zZUZ2S982"
20 21 "cZVEmrv0uX2LYKmsfXUhgZCwm46Xx6ZzX3BIg/U1noIlr50O+eB0iHAxe98Ph1NM1gPIlyaev"
21 const char* kExpectedAPIKeySignature = "Signature"; 22 "Lw75PPmXT5kUh15lJy+UPkKB8q52p3TKa2024Q3D2kGUWZ8DBD2zR5G+oHRtnKqfAh5fcTQyL"
23 "Oa37NL66h0kTZ8WfvzATfTuAaAYuw+H5sYYeYTLrrVxhDuYqu/+kRzlQ42jlpNA0xkKEqRiIz"
24 "X0erG2umU/l8SQpvdXBC87JtOIseHS9dSUoKKRO1XWnmgXX9dA==|https://valid.exampl"
25 "e.com|Frobulate|1458766277";
26 const char* kExpectedAPIKeySignature =
27 "fsnbBl0XwKysvzH3d4TtIomsD9teP0PFfqxIYIAksfipEjB+cXAwI0tUzkYES4H0zZUZ2S982"
28 "cZVEmrv0uX2LYKmsfXUhgZCwm46Xx6ZzX3BIg/U1noIlr50O+eB0iHAxe98Ph1NM1gPIlyaev"
29 "Lw75PPmXT5kUh15lJy+UPkKB8q52p3TKa2024Q3D2kGUWZ8DBD2zR5G+oHRtnKqfAh5fcTQyL"
30 "Oa37NL66h0kTZ8WfvzATfTuAaAYuw+H5sYYeYTLrrVxhDuYqu/+kRzlQ42jlpNA0xkKEqRiIz"
31 "X0erG2umU/l8SQpvdXBC87JtOIseHS9dSUoKKRO1XWnmgXX9dA==";
22 const char* kExpectedAPIKeyData = 32 const char* kExpectedAPIKeyData =
23 "https://valid.example.com|Frobulate|1458766277"; 33 "https://valid.example.com|Frobulate|1458766277";
24 const char* kExpectedAPIName = "Frobulate"; 34 const char* kExpectedAPIName = "Frobulate";
25 const char* kExpectedOrigin = "https://valid.example.com"; 35 const char* kExpectedOrigin = "https://valid.example.com";
26 const uint64_t kExpectedExpiry = 1458766277; 36 const uint64_t kExpectedExpiry = 1458766277;
27 37
28 // The key should not be valid for this origin, or for this API. 38 // The key should not be valid for this origin, or for this API.
29 const char* kInvalidOrigin = "https://invalid.example.com"; 39 const char* kInvalidOrigin = "https://invalid.example.com";
30 const char* kInsecureOrigin = "http://valid.example.com"; 40 const char* kInsecureOrigin = "http://valid.example.com";
31 const char* kInvalidAPIName = "Grokalyze"; 41 const char* kInvalidAPIName = "Grokalyze";
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 EXPECT_TRUE(key->IsAppropriate(kExpectedOrigin, kExpectedAPIName)); 134 EXPECT_TRUE(key->IsAppropriate(kExpectedOrigin, kExpectedAPIName));
125 EXPECT_TRUE(key->IsAppropriate(kExpectedOrigin, 135 EXPECT_TRUE(key->IsAppropriate(kExpectedOrigin,
126 base::ToUpperASCII(kExpectedAPIName))); 136 base::ToUpperASCII(kExpectedAPIName)));
127 EXPECT_TRUE(key->IsAppropriate(kExpectedOrigin, 137 EXPECT_TRUE(key->IsAppropriate(kExpectedOrigin,
128 base::ToLowerASCII(kExpectedAPIName))); 138 base::ToLowerASCII(kExpectedAPIName)));
129 EXPECT_FALSE(key->IsAppropriate(kInvalidOrigin, kExpectedAPIName)); 139 EXPECT_FALSE(key->IsAppropriate(kInvalidOrigin, kExpectedAPIName));
130 EXPECT_FALSE(key->IsAppropriate(kInsecureOrigin, kExpectedAPIName)); 140 EXPECT_FALSE(key->IsAppropriate(kInsecureOrigin, kExpectedAPIName));
131 EXPECT_FALSE(key->IsAppropriate(kExpectedOrigin, kInvalidAPIName)); 141 EXPECT_FALSE(key->IsAppropriate(kExpectedOrigin, kInvalidAPIName));
132 } 142 }
133 143
144 TEST_F(ApiKeyTest, ValidateWhenNotExpired) {
145 scoped_ptr<ApiKey> key = ApiKey::Parse(kSampleAPIKey);
146 ASSERT_TRUE(key);
147 }
148
134 } // namespace content 149 } // namespace content
OLDNEW
« no previous file with comments | « content/common/experiments/api_key.cc ('k') | content/content_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698