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

Side by Side Diff: extensions/browser/verified_contents_unittest.cc

Issue 585583003: Fix case-sensitivity problems in extension content verification (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove old code Created 6 years, 2 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 | « extensions/browser/verified_contents.cc ('k') | extensions/test/data/content_verifier/README » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/base64.h" 8 #include "base/base64.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "extensions/browser/verified_contents.h" 13 #include "extensions/browser/verified_contents.h"
14 #include "extensions/common/extension.h" 14 #include "extensions/common/extension.h"
15 #include "extensions/common/extension_paths.h" 15 #include "extensions/common/extension_paths.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 17
18 namespace extensions { 18 namespace extensions {
19 19
20 namespace { 20 namespace {
21 21
22 bool Base64UrlStringEquals(std::string input, const std::string* bytes) { 22 std::string DecodeBase64Url(const std::string& encoded) {
23 if (!bytes) 23 std::string fixed_up_base64 = encoded;
24 return false; 24 if (!VerifiedContents::FixupBase64Encoding(&fixed_up_base64))
25 if (!VerifiedContents::FixupBase64Encoding(&input)) 25 return std::string();
26 return false;
27 std::string decoded; 26 std::string decoded;
28 if (!base::Base64Decode(input, &decoded)) 27 if (!base::Base64Decode(fixed_up_base64, &decoded))
29 return false; 28 return std::string();
30 if (decoded.size() != bytes->size()) 29 return decoded;
31 return false;
32
33 if (bytes->empty())
34 return true;
35
36 return decoded == *bytes;
37 } 30 }
38 31
39 bool GetPublicKey(const base::FilePath& path, std::string* public_key) { 32 bool GetPublicKey(const base::FilePath& path, std::string* public_key) {
40 std::string public_key_pem; 33 std::string public_key_pem;
41 if (!base::ReadFileToString(path, &public_key_pem)) 34 if (!base::ReadFileToString(path, &public_key_pem))
42 return false; 35 return false;
43 if (!Extension::ParsePEMKeyBytes(public_key_pem, public_key)) 36 if (!Extension::ParsePEMKeyBytes(public_key_pem, public_key))
44 return false; 37 return false;
45 return true; 38 return true;
46 } 39 }
(...skipping 14 matching lines...) Expand all
61 base::FilePath verified_contents_path = 54 base::FilePath verified_contents_path =
62 path.AppendASCII("verified_contents.json"); 55 path.AppendASCII("verified_contents.json");
63 56
64 ASSERT_TRUE(contents.InitFrom(verified_contents_path, false)); 57 ASSERT_TRUE(contents.InitFrom(verified_contents_path, false));
65 58
66 // Make sure we get expected values. 59 // Make sure we get expected values.
67 EXPECT_EQ(contents.block_size(), 4096); 60 EXPECT_EQ(contents.block_size(), 4096);
68 EXPECT_EQ(contents.extension_id(), "abcdefghijklmnopabcdefghijklmnop"); 61 EXPECT_EQ(contents.extension_id(), "abcdefghijklmnopabcdefghijklmnop");
69 EXPECT_EQ("1.2.3", contents.version().GetString()); 62 EXPECT_EQ("1.2.3", contents.version().GetString());
70 63
71 EXPECT_TRUE(Base64UrlStringEquals( 64 EXPECT_TRUE(contents.TreeHashRootEquals(
72 "-vyyIIn7iSCzg7X3ICUI5wZa3tG7w7vyiCckxZdJGfs", 65 base::FilePath::FromUTF8Unsafe("manifest.json"),
73 contents.GetTreeHashRoot( 66 DecodeBase64Url("-vyyIIn7iSCzg7X3ICUI5wZa3tG7w7vyiCckxZdJGfs")));
74 base::FilePath::FromUTF8Unsafe("manifest.json")))); 67
75 EXPECT_TRUE(Base64UrlStringEquals( 68 EXPECT_TRUE(contents.TreeHashRootEquals(
76 "txHiG5KQvNoPOSH5FbQo9Zb5gJ23j3oFB0Ru9DOnziw", 69 base::FilePath::FromUTF8Unsafe("background.js"),
77 contents.GetTreeHashRoot( 70 DecodeBase64Url("txHiG5KQvNoPOSH5FbQo9Zb5gJ23j3oFB0Ru9DOnziw")));
78 base::FilePath::FromUTF8Unsafe("background.js"))));
79 71
80 base::FilePath foo_bar_html = 72 base::FilePath foo_bar_html =
81 base::FilePath(FILE_PATH_LITERAL("foo")).AppendASCII("bar.html"); 73 base::FilePath(FILE_PATH_LITERAL("foo")).AppendASCII("bar.html");
82 EXPECT_FALSE(foo_bar_html.IsAbsolute()); 74 EXPECT_FALSE(foo_bar_html.IsAbsolute());
83 EXPECT_TRUE( 75 EXPECT_TRUE(contents.TreeHashRootEquals(
84 Base64UrlStringEquals("L37LFbT_hmtxRL7AfGZN9YTpW6yoz_ZiQ1opLJn1NZU", 76 foo_bar_html,
85 contents.GetTreeHashRoot(foo_bar_html))); 77 DecodeBase64Url("L37LFbT_hmtxRL7AfGZN9YTpW6yoz_ZiQ1opLJn1NZU")));
86 78
87 base::FilePath nonexistent = base::FilePath::FromUTF8Unsafe("nonexistent"); 79 base::FilePath nonexistent = base::FilePath::FromUTF8Unsafe("nonexistent");
88 EXPECT_TRUE(contents.GetTreeHashRoot(nonexistent) == NULL); 80 EXPECT_FALSE(contents.HasTreeHashRoot(nonexistent));
81
82 EXPECT_TRUE(contents.TreeHashRootEquals(
83 base::FilePath::FromUTF8Unsafe("lowercase.html"),
84 DecodeBase64Url("HpLotLGCmmOdKYvGQmD3OkXMKGs458dbanY4WcfAZI0")));
85 EXPECT_TRUE(contents.TreeHashRootEquals(
86 base::FilePath::FromUTF8Unsafe("Lowercase.Html"),
87 DecodeBase64Url("HpLotLGCmmOdKYvGQmD3OkXMKGs458dbanY4WcfAZI0")));
88 EXPECT_TRUE(contents.TreeHashRootEquals(
89 base::FilePath::FromUTF8Unsafe("LOWERCASE.HTML"),
90 DecodeBase64Url("HpLotLGCmmOdKYvGQmD3OkXMKGs458dbanY4WcfAZI0")));
91
92 EXPECT_TRUE(contents.TreeHashRootEquals(
93 base::FilePath::FromUTF8Unsafe("ALLCAPS.HTML"),
94 DecodeBase64Url("bl-eV8ENowvtw6P14D4X1EP0mlcMoG-_aOx5o9C1364")));
95 EXPECT_TRUE(contents.TreeHashRootEquals(
96 base::FilePath::FromUTF8Unsafe("AllCaps.Html"),
97 DecodeBase64Url("bl-eV8ENowvtw6P14D4X1EP0mlcMoG-_aOx5o9C1364")));
98 EXPECT_TRUE(contents.TreeHashRootEquals(
99 base::FilePath::FromUTF8Unsafe("allcaps.html"),
100 DecodeBase64Url("bl-eV8ENowvtw6P14D4X1EP0mlcMoG-_aOx5o9C1364")));
101
102 EXPECT_TRUE(contents.TreeHashRootEquals(
103 base::FilePath::FromUTF8Unsafe("MixedCase.Html"),
104 DecodeBase64Url("zEAO9FwciigMNy3NtU2XNb-dS5TQMmVNx0T9h7WvXbQ")));
105 EXPECT_TRUE(contents.TreeHashRootEquals(
106 base::FilePath::FromUTF8Unsafe("MIXEDCASE.HTML"),
107 DecodeBase64Url("zEAO9FwciigMNy3NtU2XNb-dS5TQMmVNx0T9h7WvXbQ")));
108 EXPECT_TRUE(contents.TreeHashRootEquals(
109 base::FilePath::FromUTF8Unsafe("mixedcase.html"),
110 DecodeBase64Url("zEAO9FwciigMNy3NtU2XNb-dS5TQMmVNx0T9h7WvXbQ")));
111 EXPECT_TRUE(contents.TreeHashRootEquals(
112 base::FilePath::FromUTF8Unsafe("mIxedcAse.Html"),
113 DecodeBase64Url("zEAO9FwciigMNy3NtU2XNb-dS5TQMmVNx0T9h7WvXbQ")));
114
115 EXPECT_TRUE(contents.TreeHashRootEquals(
116 base::FilePath::FromUTF8Unsafe("mIxedcAse.Html"),
117 DecodeBase64Url("nKRqUcJg1_QZWAeCb4uFd5ouC0McuGavKp8TFDRqBgg")));
118 EXPECT_TRUE(contents.TreeHashRootEquals(
119 base::FilePath::FromUTF8Unsafe("MIXEDCASE.HTML"),
120 DecodeBase64Url("nKRqUcJg1_QZWAeCb4uFd5ouC0McuGavKp8TFDRqBgg")));
121 EXPECT_TRUE(contents.TreeHashRootEquals(
122 base::FilePath::FromUTF8Unsafe("mixedcase.html"),
123 DecodeBase64Url("nKRqUcJg1_QZWAeCb4uFd5ouC0McuGavKp8TFDRqBgg")));
124 EXPECT_TRUE(contents.TreeHashRootEquals(
125 base::FilePath::FromUTF8Unsafe("MixedCase.Html"),
126 DecodeBase64Url("nKRqUcJg1_QZWAeCb4uFd5ouC0McuGavKp8TFDRqBgg")));
89 } 127 }
90 128
91 } // namespace extensions 129 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/verified_contents.cc ('k') | extensions/test/data/content_verifier/README » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698