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

Side by Side Diff: chrome/browser/policy/policy_path_parser_unittest.cc

Issue 6966032: Sanitize enclosing quotes around paths in policies. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed the unit tests. Created 9 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/file_path.h> 5 #include <base/file_path.h>
6 #include <chrome/browser/policy/policy_path_parser.h> 6 #include <chrome/browser/policy/policy_path_parser.h>
7 7
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace policy { 10 namespace policy {
(...skipping 15 matching lines...) Expand all
26 FilePath::StringType no_vars_result = 26 FilePath::StringType no_vars_result =
27 path_parser::ExpandPathVariables(no_vars); 27 path_parser::ExpandPathVariables(no_vars);
28 ASSERT_EQ(no_vars_result, no_vars); 28 ASSERT_EQ(no_vars_result, no_vars);
29 29
30 // This is unknown variable and shouldn't be substituted. 30 // This is unknown variable and shouldn't be substituted.
31 FilePath::StringType unknown_vars(FILE_PATH_LITERAL("//$C/${buggy}")); 31 FilePath::StringType unknown_vars(FILE_PATH_LITERAL("//$C/${buggy}"));
32 FilePath::StringType unknown_vars_result = 32 FilePath::StringType unknown_vars_result =
33 path_parser::ExpandPathVariables(unknown_vars); 33 path_parser::ExpandPathVariables(unknown_vars);
34 ASSERT_EQ(unknown_vars_result, unknown_vars); 34 ASSERT_EQ(unknown_vars_result, unknown_vars);
35 35
36 // Trim quotes around, but not inside paths. Test against bug 80211.
37 FilePath::StringType no_quotes(FILE_PATH_LITERAL("//$C/\"a\"/$path"));
38 FilePath::StringType single_quotes(FILE_PATH_LITERAL("'//$C/\"a\"/$path'"));
39 FilePath::StringType double_quotes(FILE_PATH_LITERAL("\"//$C/\"a\"/$path\""));
40 FilePath::StringType quotes_result =
41 path_parser::ExpandPathVariables(single_quotes);
42 ASSERT_EQ(quotes_result, no_quotes);
43 quotes_result = path_parser::ExpandPathVariables(double_quotes);
44 ASSERT_EQ(quotes_result, no_quotes);
45
36 // Both should have been substituted. 46 // Both should have been substituted.
37 FilePath::StringType vars(FILE_PATH_LITERAL("${user_name}${machine_name}")); 47 FilePath::StringType vars(FILE_PATH_LITERAL("${user_name}${machine_name}"));
38 FilePath::StringType vars_result = path_parser::ExpandPathVariables(vars); 48 FilePath::StringType vars_result = path_parser::ExpandPathVariables(vars);
39 ASSERT_EQ(vars_result.find(FILE_PATH_LITERAL("${user_name}")), 49 ASSERT_EQ(vars_result.find(FILE_PATH_LITERAL("${user_name}")),
40 FilePath::StringType::npos); 50 FilePath::StringType::npos);
41 ASSERT_EQ(vars_result.find(FILE_PATH_LITERAL("${machine_name}")), 51 ASSERT_EQ(vars_result.find(FILE_PATH_LITERAL("${machine_name}")),
42 FilePath::StringType::npos); 52 FilePath::StringType::npos);
43 53
44 // Should substitute only one instance. 54 // Should substitute only one instance.
45 vars = FILE_PATH_LITERAL("${machine_name}${machine_name}"); 55 vars = FILE_PATH_LITERAL("${machine_name}${machine_name}");
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 FILE_PATH_LITERAL("${global_app_data}")); 96 FILE_PATH_LITERAL("${global_app_data}"));
87 CheckForSubstitution(FILE_PATH_LITERAL("//$C/${program_files}"), 97 CheckForSubstitution(FILE_PATH_LITERAL("//$C/${program_files}"),
88 FILE_PATH_LITERAL("${program_files}")); 98 FILE_PATH_LITERAL("${program_files}"));
89 CheckForSubstitution(FILE_PATH_LITERAL("//$C/${windows}"), 99 CheckForSubstitution(FILE_PATH_LITERAL("//$C/${windows}"),
90 FILE_PATH_LITERAL("${windows}")); 100 FILE_PATH_LITERAL("${windows}"));
91 } 101 }
92 102
93 #endif // OS_WIN 103 #endif // OS_WIN
94 104
95 } // namespace policy 105 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698