| 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 "components/cast_certificate/cast_cert_validator_test_helpers.h" | 5 #include "components/cast_certificate/cast_cert_validator_test_helpers.h" |
| 6 | 6 |
| 7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "net/cert/pem_tokenizer.h" | 9 #include "net/cert/pem_tokenizer.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 11 |
| 12 namespace cast_certificate { | 12 namespace cast_certificate { |
| 13 | 13 |
| 14 namespace testing { | 14 namespace testing { |
| 15 | 15 |
| 16 namespace { |
| 17 |
| 18 // Reads a file from the test data directory |
| 19 // (//src/components/test/data/cast_certificate) |
| 16 std::string ReadTestFileToString(const base::StringPiece& file_name) { | 20 std::string ReadTestFileToString(const base::StringPiece& file_name) { |
| 17 base::FilePath filepath; | 21 base::FilePath filepath; |
| 18 PathService::Get(base::DIR_SOURCE_ROOT, &filepath); | 22 PathService::Get(base::DIR_SOURCE_ROOT, &filepath); |
| 19 filepath = filepath.Append(FILE_PATH_LITERAL("components")); | 23 filepath = filepath.Append(FILE_PATH_LITERAL("components")); |
| 20 filepath = filepath.Append(FILE_PATH_LITERAL("test")); | 24 filepath = filepath.Append(FILE_PATH_LITERAL("test")); |
| 21 filepath = filepath.Append(FILE_PATH_LITERAL("data")); | 25 filepath = filepath.Append(FILE_PATH_LITERAL("data")); |
| 22 filepath = filepath.Append(FILE_PATH_LITERAL("cast_certificate")); | 26 filepath = filepath.Append(FILE_PATH_LITERAL("cast_certificate")); |
| 23 filepath = filepath.AppendASCII(file_name); | 27 filepath = filepath.AppendASCII(file_name); |
| 24 | 28 |
| 25 // Read the full contents of the file. | 29 // Read the full contents of the file. |
| 26 std::string file_data; | 30 std::string file_data; |
| 27 if (!base::ReadFileToString(filepath, &file_data)) { | 31 if (!base::ReadFileToString(filepath, &file_data)) { |
| 28 ADD_FAILURE() << "Couldn't read file: " << filepath.value(); | 32 ADD_FAILURE() << "Couldn't read file: " << filepath.value(); |
| 29 return std::string(); | 33 return std::string(); |
| 30 } | 34 } |
| 31 | 35 |
| 32 return file_data; | 36 return file_data; |
| 33 } | 37 } |
| 34 | 38 |
| 39 } // namespace |
| 40 |
| 35 std::vector<std::string> ReadCertificateChainFromFile( | 41 std::vector<std::string> ReadCertificateChainFromFile( |
| 36 const base::StringPiece& file_name) { | 42 const base::StringPiece& file_name) { |
| 37 std::string file_data = ReadTestFileToString(file_name); | 43 std::string file_data = ReadTestFileToString(file_name); |
| 38 | 44 |
| 39 std::vector<std::string> pem_headers; | 45 std::vector<std::string> pem_headers; |
| 40 pem_headers.push_back("CERTIFICATE"); | 46 pem_headers.push_back("CERTIFICATE"); |
| 41 | 47 |
| 42 std::vector<std::string> certs; | 48 std::vector<std::string> certs; |
| 43 net::PEMTokenizer pem_tokenizer(file_data, pem_headers); | 49 net::PEMTokenizer pem_tokenizer(file_data, pem_headers); |
| 44 while (pem_tokenizer.GetNext()) | 50 while (pem_tokenizer.GetNext()) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 EXPECT_FALSE(result.message.empty()); | 82 EXPECT_FALSE(result.message.empty()); |
| 77 EXPECT_FALSE(result.signature_sha1.empty()); | 83 EXPECT_FALSE(result.signature_sha1.empty()); |
| 78 EXPECT_FALSE(result.signature_sha256.empty()); | 84 EXPECT_FALSE(result.signature_sha256.empty()); |
| 79 | 85 |
| 80 return result; | 86 return result; |
| 81 } | 87 } |
| 82 | 88 |
| 83 } // namespace testing | 89 } // namespace testing |
| 84 | 90 |
| 85 } // namespace cast_certificate | 91 } // namespace cast_certificate |
| OLD | NEW |