OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "chrome/browser/policy/test/local_policy_test_server.h" | 5 #include "chrome/browser/policy/test/local_policy_test_server.h" |
6 | 6 |
7 #include <ctype.h> | 7 #include <ctype.h> |
| 8 #include <stdint.h> |
8 | 9 |
9 #include <algorithm> | 10 #include <algorithm> |
10 #include <vector> | 11 #include <vector> |
11 | 12 |
12 #include "base/base_paths.h" | 13 #include "base/base_paths.h" |
13 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
14 #include "base/json/json_writer.h" | 15 #include "base/json/json_writer.h" |
15 #include "base/path_service.h" | 16 #include "base/path_service.h" |
16 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 18 #include "build/build_config.h" |
17 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | 19 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
18 #include "crypto/rsa_private_key.h" | 20 #include "crypto/rsa_private_key.h" |
19 #include "net/test/python_utils.h" | 21 #include "net/test/python_utils.h" |
20 | 22 |
21 namespace policy { | 23 namespace policy { |
22 | 24 |
23 namespace { | 25 namespace { |
24 | 26 |
25 // Filename in the temporary directory storing the policy data. | 27 // Filename in the temporary directory storing the policy data. |
26 const base::FilePath::CharType kPolicyFileName[] = FILE_PATH_LITERAL("policy"); | 28 const base::FilePath::CharType kPolicyFileName[] = FILE_PATH_LITERAL("policy"); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 .AppendASCII("policy") | 84 .AppendASCII("policy") |
83 .AppendASCII(base::StringPrintf("policy_%s.json", test_name.c_str())); | 85 .AppendASCII(base::StringPrintf("policy_%s.json", test_name.c_str())); |
84 } | 86 } |
85 | 87 |
86 LocalPolicyTestServer::~LocalPolicyTestServer() {} | 88 LocalPolicyTestServer::~LocalPolicyTestServer() {} |
87 | 89 |
88 bool LocalPolicyTestServer::SetSigningKeyAndSignature( | 90 bool LocalPolicyTestServer::SetSigningKeyAndSignature( |
89 const crypto::RSAPrivateKey* key, const std::string& signature) { | 91 const crypto::RSAPrivateKey* key, const std::string& signature) { |
90 CHECK(server_data_dir_.IsValid()); | 92 CHECK(server_data_dir_.IsValid()); |
91 | 93 |
92 std::vector<uint8> signing_key_bits; | 94 std::vector<uint8_t> signing_key_bits; |
93 if (!key->ExportPrivateKey(&signing_key_bits)) | 95 if (!key->ExportPrivateKey(&signing_key_bits)) |
94 return false; | 96 return false; |
95 | 97 |
96 policy_key_ = server_data_dir_.path().Append(kSigningKeyFileName); | 98 policy_key_ = server_data_dir_.path().Append(kSigningKeyFileName); |
97 int bytes_written = base::WriteFile( | 99 int bytes_written = base::WriteFile( |
98 policy_key_, reinterpret_cast<const char*>(signing_key_bits.data()), | 100 policy_key_, reinterpret_cast<const char*>(signing_key_bits.data()), |
99 signing_key_bits.size()); | 101 signing_key_bits.size()); |
100 | 102 |
101 if (bytes_written != static_cast<int>(signing_key_bits.size())) | 103 if (bytes_written != static_cast<int>(signing_key_bits.size())) |
102 return false; | 104 return false; |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 std::string LocalPolicyTestServer::GetSelector(const std::string& type, | 256 std::string LocalPolicyTestServer::GetSelector(const std::string& type, |
255 const std::string& entity_id) { | 257 const std::string& entity_id) { |
256 std::string selector = type; | 258 std::string selector = type; |
257 if (!entity_id.empty()) | 259 if (!entity_id.empty()) |
258 selector = base::StringPrintf("%s/%s", type.c_str(), entity_id.c_str()); | 260 selector = base::StringPrintf("%s/%s", type.c_str(), entity_id.c_str()); |
259 std::replace_if(selector.begin(), selector.end(), IsUnsafeCharacter, '_'); | 261 std::replace_if(selector.begin(), selector.end(), IsUnsafeCharacter, '_'); |
260 return selector; | 262 return selector; |
261 } | 263 } |
262 | 264 |
263 } // namespace policy | 265 } // namespace policy |
OLD | NEW |