| OLD | NEW |
| 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 make_pair(std::string(0, 'a'), std::string("value")))); | 87 make_pair(std::string(0, 'a'), std::string("value")))); |
| 88 EXPECT_TRUE(IsValidInstallerAttribute( | 88 EXPECT_TRUE(IsValidInstallerAttribute( |
| 89 make_pair(std::string(1, 'a'), std::string("value")))); | 89 make_pair(std::string(1, 'a'), std::string("value")))); |
| 90 EXPECT_TRUE(IsValidInstallerAttribute( | 90 EXPECT_TRUE(IsValidInstallerAttribute( |
| 91 make_pair(std::string(256, 'a'), std::string("value")))); | 91 make_pair(std::string(256, 'a'), std::string("value")))); |
| 92 EXPECT_FALSE(IsValidInstallerAttribute( | 92 EXPECT_FALSE(IsValidInstallerAttribute( |
| 93 make_pair(std::string(257, 'a'), std::string("value")))); | 93 make_pair(std::string(257, 'a'), std::string("value")))); |
| 94 | 94 |
| 95 const char* const valid_names[] = {"A", "Z", "a", "a-b", "A_B", | 95 const char* const valid_names[] = {"A", "Z", "a", "a-b", "A_B", |
| 96 "z", "0", "9", "-_"}; | 96 "z", "0", "9", "-_"}; |
| 97 for (const auto& name : valid_names) | 97 for (auto* name : valid_names) |
| 98 EXPECT_TRUE(IsValidInstallerAttribute( | 98 EXPECT_TRUE(IsValidInstallerAttribute( |
| 99 make_pair(std::string(name), std::string("value")))); | 99 make_pair(std::string(name), std::string("value")))); |
| 100 | 100 |
| 101 const char* const invalid_names[] = { | 101 const char* const invalid_names[] = { |
| 102 "", "a=1", " name", "name ", "na me", "<name", "name>", | 102 "", "a=1", " name", "name ", "na me", "<name", "name>", |
| 103 "\"", "\\", "\xaa", ".", ",", ";", "+"}; | 103 "\"", "\\", "\xaa", ".", ",", ";", "+"}; |
| 104 for (const auto& name : invalid_names) | 104 for (auto* name : invalid_names) |
| 105 EXPECT_FALSE(IsValidInstallerAttribute( | 105 EXPECT_FALSE(IsValidInstallerAttribute( |
| 106 make_pair(std::string(name), std::string("value")))); | 106 make_pair(std::string(name), std::string("value")))); |
| 107 } | 107 } |
| 108 | 108 |
| 109 // Tests that the value of an InstallerAttribute matches | 109 // Tests that the value of an InstallerAttribute matches |
| 110 // ^[-.,;+_=a-zA-Z0-9]{0,256}$ | 110 // ^[-.,;+_=a-zA-Z0-9]{0,256}$ |
| 111 TEST(UpdateClientUtils, IsValidInstallerAttributeValue) { | 111 TEST(UpdateClientUtils, IsValidInstallerAttributeValue) { |
| 112 // Test the length boundaries. | 112 // Test the length boundaries. |
| 113 EXPECT_TRUE(IsValidInstallerAttribute( | 113 EXPECT_TRUE(IsValidInstallerAttribute( |
| 114 make_pair(std::string("name"), std::string(0, 'a')))); | 114 make_pair(std::string("name"), std::string(0, 'a')))); |
| 115 EXPECT_TRUE(IsValidInstallerAttribute( | 115 EXPECT_TRUE(IsValidInstallerAttribute( |
| 116 make_pair(std::string("name"), std::string(256, 'a')))); | 116 make_pair(std::string("name"), std::string(256, 'a')))); |
| 117 EXPECT_FALSE(IsValidInstallerAttribute( | 117 EXPECT_FALSE(IsValidInstallerAttribute( |
| 118 make_pair(std::string("name"), std::string(257, 'a')))); | 118 make_pair(std::string("name"), std::string(257, 'a')))); |
| 119 | 119 |
| 120 const char* const valid_values[] = {"", "a=1", "A", "Z", "a", | 120 const char* const valid_values[] = {"", "a=1", "A", "Z", "a", |
| 121 "z", "0", "9", "-.,;+_="}; | 121 "z", "0", "9", "-.,;+_="}; |
| 122 for (const auto& value : valid_values) | 122 for (auto* value : valid_values) |
| 123 EXPECT_TRUE(IsValidInstallerAttribute( | 123 EXPECT_TRUE(IsValidInstallerAttribute( |
| 124 make_pair(std::string("name"), std::string(value)))); | 124 make_pair(std::string("name"), std::string(value)))); |
| 125 | 125 |
| 126 const char* const invalid_values[] = {" ap", "ap ", "a p", "<ap", | 126 const char* const invalid_values[] = {" ap", "ap ", "a p", "<ap", |
| 127 "ap>", "\"", "\\", "\xaa"}; | 127 "ap>", "\"", "\\", "\xaa"}; |
| 128 for (const auto& value : invalid_values) | 128 for (auto* value : invalid_values) |
| 129 EXPECT_FALSE(IsValidInstallerAttribute( | 129 EXPECT_FALSE(IsValidInstallerAttribute( |
| 130 make_pair(std::string("name"), std::string(value)))); | 130 make_pair(std::string("name"), std::string(value)))); |
| 131 } | 131 } |
| 132 | 132 |
| 133 TEST(UpdateClientUtils, RemoveUnsecureUrls) { | 133 TEST(UpdateClientUtils, RemoveUnsecureUrls) { |
| 134 const GURL test1[] = {GURL("http://foo"), GURL("https://foo")}; | 134 const GURL test1[] = {GURL("http://foo"), GURL("https://foo")}; |
| 135 std::vector<GURL> urls(std::begin(test1), std::end(test1)); | 135 std::vector<GURL> urls(std::begin(test1), std::end(test1)); |
| 136 RemoveUnsecureUrls(&urls); | 136 RemoveUnsecureUrls(&urls); |
| 137 EXPECT_EQ(1u, urls.size()); | 137 EXPECT_EQ(1u, urls.size()); |
| 138 EXPECT_EQ(urls[0], GURL("https://foo")); | 138 EXPECT_EQ(urls[0], GURL("https://foo")); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 155 RemoveUnsecureUrls(&urls); | 155 RemoveUnsecureUrls(&urls); |
| 156 EXPECT_EQ(0u, urls.size()); | 156 EXPECT_EQ(0u, urls.size()); |
| 157 | 157 |
| 158 const GURL test5[] = {GURL("http://foo"), GURL("http://bar")}; | 158 const GURL test5[] = {GURL("http://foo"), GURL("http://bar")}; |
| 159 urls.assign(std::begin(test5), std::end(test5)); | 159 urls.assign(std::begin(test5), std::end(test5)); |
| 160 RemoveUnsecureUrls(&urls); | 160 RemoveUnsecureUrls(&urls); |
| 161 EXPECT_EQ(0u, urls.size()); | 161 EXPECT_EQ(0u, urls.size()); |
| 162 } | 162 } |
| 163 | 163 |
| 164 } // namespace update_client | 164 } // namespace update_client |
| OLD | NEW |