OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "net/cert/internal/parse_certificate.h" | 5 #include "net/cert/internal/parse_certificate.h" |
6 | 6 |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "net/cert/internal/test_helpers.h" | 8 #include "net/cert/internal/test_helpers.h" |
9 #include "net/der/input.h" | 9 #include "net/der/input.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 namespace net { | 12 namespace net { |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 // Pretty-prints a GeneralizedTime as a human-readable string for use in test | 16 // Pretty-prints a GeneralizedTime as a human-readable string for use in test |
17 // expectations (it is more readable to specify the expected results as a | 17 // expectations (it is more readable to specify the expected results as a |
18 // string). | 18 // string). |
19 std::string ToString(const der::GeneralizedTime& time) { | 19 std::string ToString(const der::GeneralizedTime& time) { |
20 return base::StringPrintf( | 20 return base::StringPrintf( |
21 "year=%d, month=%d, day=%d, hours=%d, minutes=%d, seconds=%d", time.year, | 21 "year=%d, month=%d, day=%d, hours=%d, minutes=%d, seconds=%d", time.year, |
22 time.month, time.day, time.hours, time.minutes, time.seconds); | 22 time.month, time.day, time.hours, time.minutes, time.seconds); |
23 } | 23 } |
24 | 24 |
25 std::string GetFilePath(const std::string file_name) { | 25 std::string GetFilePath(const std::string& file_name) { |
26 return std::string("net/data/parse_certificate_unittest/") + file_name; | 26 return std::string("net/data/parse_certificate_unittest/") + file_name; |
27 } | 27 } |
28 | 28 |
29 // Loads certificate data and expectations from the PEM file |file_name|. | 29 // Loads certificate data and expectations from the PEM file |file_name|. |
30 // Verifies that parsing the Certificate succeeds, and each parsed field matches | 30 // Verifies that parsing the Certificate succeeds, and each parsed field matches |
31 // the expectations. | 31 // the expectations. |
32 void EnsureParsingCertificateSucceeds(const std::string& file_name) { | 32 void EnsureParsingCertificateSucceeds(const std::string& file_name) { |
33 std::string data; | 33 std::string data; |
34 std::string expected_tbs_certificate; | 34 std::string expected_tbs_certificate; |
35 std::string expected_signature_algorithm; | 35 std::string expected_signature_algorithm; |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 | 322 |
323 // Parses a TBSCertificate whose "validity" field does not strictly follow | 323 // Parses a TBSCertificate whose "validity" field does not strictly follow |
324 // the DER rules (and fails to be parsed). | 324 // the DER rules (and fails to be parsed). |
325 TEST(ParseTbsCertificateTest, ValidityRelaxed) { | 325 TEST(ParseTbsCertificateTest, ValidityRelaxed) { |
326 EnsureParsingTbsFails("tbs_validity_relaxed.pem"); | 326 EnsureParsingTbsFails("tbs_validity_relaxed.pem"); |
327 } | 327 } |
328 | 328 |
329 } // namespace | 329 } // namespace |
330 | 330 |
331 } // namespace net | 331 } // namespace net |
OLD | NEW |