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

Side by Side Diff: components/cast_certificate/cast_cert_validator_test_helpers.cc

Issue 2050983002: Cast device revocation checking. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed test failure on 32 bit systems. Created 4 years, 5 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
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 "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)
20 std::string ReadTestFileToString(const base::StringPiece& file_name) { 16 std::string ReadTestFileToString(const base::StringPiece& file_name) {
21 base::FilePath filepath; 17 base::FilePath filepath;
22 PathService::Get(base::DIR_SOURCE_ROOT, &filepath); 18 PathService::Get(base::DIR_SOURCE_ROOT, &filepath);
23 filepath = filepath.Append(FILE_PATH_LITERAL("components")); 19 filepath = filepath.Append(FILE_PATH_LITERAL("components"));
24 filepath = filepath.Append(FILE_PATH_LITERAL("test")); 20 filepath = filepath.Append(FILE_PATH_LITERAL("test"));
25 filepath = filepath.Append(FILE_PATH_LITERAL("data")); 21 filepath = filepath.Append(FILE_PATH_LITERAL("data"));
26 filepath = filepath.Append(FILE_PATH_LITERAL("cast_certificate")); 22 filepath = filepath.Append(FILE_PATH_LITERAL("cast_certificate"));
27 filepath = filepath.AppendASCII(file_name); 23 filepath = filepath.AppendASCII(file_name);
28 24
29 // Read the full contents of the file. 25 // Read the full contents of the file.
30 std::string file_data; 26 std::string file_data;
31 if (!base::ReadFileToString(filepath, &file_data)) { 27 if (!base::ReadFileToString(filepath, &file_data)) {
32 ADD_FAILURE() << "Couldn't read file: " << filepath.value(); 28 ADD_FAILURE() << "Couldn't read file: " << filepath.value();
33 return std::string(); 29 return std::string();
34 } 30 }
35 31
36 return file_data; 32 return file_data;
37 } 33 }
38 34
39 } // namespace
40
41 std::vector<std::string> ReadCertificateChainFromFile( 35 std::vector<std::string> ReadCertificateChainFromFile(
42 const base::StringPiece& file_name) { 36 const base::StringPiece& file_name) {
43 std::string file_data = ReadTestFileToString(file_name); 37 std::string file_data = ReadTestFileToString(file_name);
44 38
45 std::vector<std::string> pem_headers; 39 std::vector<std::string> pem_headers;
46 pem_headers.push_back("CERTIFICATE"); 40 pem_headers.push_back("CERTIFICATE");
47 41
48 std::vector<std::string> certs; 42 std::vector<std::string> certs;
49 net::PEMTokenizer pem_tokenizer(file_data, pem_headers); 43 net::PEMTokenizer pem_tokenizer(file_data, pem_headers);
50 while (pem_tokenizer.GetNext()) 44 while (pem_tokenizer.GetNext())
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 EXPECT_FALSE(result.message.empty()); 76 EXPECT_FALSE(result.message.empty());
83 EXPECT_FALSE(result.signature_sha1.empty()); 77 EXPECT_FALSE(result.signature_sha1.empty());
84 EXPECT_FALSE(result.signature_sha256.empty()); 78 EXPECT_FALSE(result.signature_sha256.empty());
85 79
86 return result; 80 return result;
87 } 81 }
88 82
89 } // namespace testing 83 } // namespace testing
90 84
91 } // namespace cast_certificate 85 } // namespace cast_certificate
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698