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

Side by Side Diff: components/update_client/utils_unittest.cc

Issue 1876573002: Component updater must enforce that the brand length is 4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@apchange
Patch Set: 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
« no previous file with comments | « components/update_client/utils.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/files/file_path.h" 5 #include "base/files/file_path.h"
6 #include "base/path_service.h" 6 #include "base/path_service.h"
7 #include "components/update_client/utils.h" 7 #include "components/update_client/utils.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "url/gurl.h" 9 #include "url/gurl.h"
10 10
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 EXPECT_FALSE(VerifyFileHash256( 50 EXPECT_FALSE(VerifyFileHash256(
51 MakeTestFilePath("jebgalgnebhfojomionfpkfelancnnkf.crx"), 51 MakeTestFilePath("jebgalgnebhfojomionfpkfelancnnkf.crx"),
52 std::string("abcd"))); 52 std::string("abcd")));
53 53
54 EXPECT_FALSE(VerifyFileHash256( 54 EXPECT_FALSE(VerifyFileHash256(
55 MakeTestFilePath("jebgalgnebhfojomionfpkfelancnnkf.crx"), 55 MakeTestFilePath("jebgalgnebhfojomionfpkfelancnnkf.crx"),
56 std::string( 56 std::string(
57 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))); 57 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")));
58 } 58 }
59 59
60 // Tests that the brand matches ^([a-zA-Z]{4})?$ 60 // Tests that the brand matches ^[a-zA-Z]{4}?$
61 TEST(UpdateClientUtils, IsValidBrand) { 61 TEST(UpdateClientUtils, IsValidBrand) {
62 // The valid brand code must be empty or exactly 4 chars long.
62 EXPECT_TRUE(IsValidBrand(std::string(""))); 63 EXPECT_TRUE(IsValidBrand(std::string("")));
63 EXPECT_TRUE(IsValidBrand(std::string("T")));
64 EXPECT_TRUE(IsValidBrand(std::string("TE")));
65 EXPECT_TRUE(IsValidBrand(std::string("TES")));
66 EXPECT_TRUE(IsValidBrand(std::string("TEST"))); 64 EXPECT_TRUE(IsValidBrand(std::string("TEST")));
67 EXPECT_TRUE(IsValidBrand(std::string("")));
68 EXPECT_TRUE(IsValidBrand(std::string("t")));
69 EXPECT_TRUE(IsValidBrand(std::string("te")));
70 EXPECT_TRUE(IsValidBrand(std::string("tes")));
71 EXPECT_TRUE(IsValidBrand(std::string("test"))); 65 EXPECT_TRUE(IsValidBrand(std::string("test")));
72 EXPECT_TRUE(IsValidBrand(std::string("TEst"))); 66 EXPECT_TRUE(IsValidBrand(std::string("TEst")));
73 67
68 EXPECT_FALSE(IsValidBrand(std::string("T"))); // Too short.
69 EXPECT_FALSE(IsValidBrand(std::string("TE"))); //
70 EXPECT_FALSE(IsValidBrand(std::string("TES"))); //
74 EXPECT_FALSE(IsValidBrand(std::string("TESTS"))); // Too long. 71 EXPECT_FALSE(IsValidBrand(std::string("TESTS"))); // Too long.
75 EXPECT_FALSE(IsValidBrand(std::string("TES1"))); // Has digit. 72 EXPECT_FALSE(IsValidBrand(std::string("TES1"))); // Has digit.
76 EXPECT_FALSE(IsValidBrand(std::string(" TES"))); // Begins with white space. 73 EXPECT_FALSE(IsValidBrand(std::string(" TES"))); // Begins with white space.
77 EXPECT_FALSE(IsValidBrand(std::string("TES "))); // Ends with white space. 74 EXPECT_FALSE(IsValidBrand(std::string("TES "))); // Ends with white space.
78 EXPECT_FALSE(IsValidBrand(std::string("T ES"))); // Contains white space. 75 EXPECT_FALSE(IsValidBrand(std::string("T ES"))); // Contains white space.
79 EXPECT_FALSE(IsValidBrand(std::string("<TE"))); // Has <. 76 EXPECT_FALSE(IsValidBrand(std::string("<TE"))); // Has <.
80 EXPECT_FALSE(IsValidBrand(std::string("TE>"))); // Has >. 77 EXPECT_FALSE(IsValidBrand(std::string("TE>"))); // Has >.
78 EXPECT_FALSE(IsValidAp(std::string("\""))); // Has "
79 EXPECT_FALSE(IsValidAp(std::string("\\"))); // Has backslash.
81 EXPECT_FALSE(IsValidBrand(std::string("\xaa"))); // Has non-ASCII char. 80 EXPECT_FALSE(IsValidBrand(std::string("\xaa"))); // Has non-ASCII char.
82 } 81 }
83 82
84 // Tests that the ap matches ^([-+_=a-zA-Z0-9]{0,256})$ 83 // Tests that the ap matches ^[-+_=a-zA-Z0-9]{0,256}$
85 TEST(UpdateClientUtils, IsValidAp) { 84 TEST(UpdateClientUtils, IsValidAp) {
86 EXPECT_TRUE(IsValidAp(std::string("a=1"))); 85 EXPECT_TRUE(IsValidAp(std::string("a=1")));
87 EXPECT_TRUE(IsValidAp(std::string(""))); 86 EXPECT_TRUE(IsValidAp(std::string("")));
88 EXPECT_TRUE(IsValidAp(std::string("A"))); 87 EXPECT_TRUE(IsValidAp(std::string("A")));
89 EXPECT_TRUE(IsValidAp(std::string("Z"))); 88 EXPECT_TRUE(IsValidAp(std::string("Z")));
90 EXPECT_TRUE(IsValidAp(std::string("a"))); 89 EXPECT_TRUE(IsValidAp(std::string("a")));
91 EXPECT_TRUE(IsValidAp(std::string("z"))); 90 EXPECT_TRUE(IsValidAp(std::string("z")));
92 EXPECT_TRUE(IsValidAp(std::string("0"))); 91 EXPECT_TRUE(IsValidAp(std::string("0")));
93 EXPECT_TRUE(IsValidAp(std::string("9"))); 92 EXPECT_TRUE(IsValidAp(std::string("9")));
94 EXPECT_TRUE(IsValidAp(std::string(256, 'a'))); 93 EXPECT_TRUE(IsValidAp(std::string(256, 'a')));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 RemoveUnsecureUrls(&urls); 129 RemoveUnsecureUrls(&urls);
131 EXPECT_EQ(0u, urls.size()); 130 EXPECT_EQ(0u, urls.size());
132 131
133 const GURL test5[] = {GURL("http://foo"), GURL("http://bar")}; 132 const GURL test5[] = {GURL("http://foo"), GURL("http://bar")};
134 urls.assign(std::begin(test5), std::end(test5)); 133 urls.assign(std::begin(test5), std::end(test5));
135 RemoveUnsecureUrls(&urls); 134 RemoveUnsecureUrls(&urls);
136 EXPECT_EQ(0u, urls.size()); 135 EXPECT_EQ(0u, urls.size());
137 } 136 }
138 137
139 } // namespace update_client 138 } // namespace update_client
OLDNEW
« no previous file with comments | « components/update_client/utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698