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 <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "net/cert/internal/extended_key_usage.h" | 8 #include "net/cert/internal/extended_key_usage.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 // Helper method to check if an EKU is present in a std::vector of EKUs. | 16 // Helper method to check if an EKU is present in a std::vector of EKUs. |
17 bool HasEKU(const std::vector<der::Input>& list, const der::Input& eku) { | 17 bool HasEKU(const std::vector<der::Input>& list, const der::Input& eku) { |
18 for (const auto& oid : list) { | 18 for (const auto& oid : list) { |
19 if (oid.Equals(eku)) | 19 if (oid == eku) |
20 return true; | 20 return true; |
21 } | 21 } |
22 return false; | 22 return false; |
23 } | 23 } |
24 | 24 |
25 // Check that we can read multiple EKUs from an extension. | 25 // Check that we can read multiple EKUs from an extension. |
26 TEST(ExtendedKeyUsageTest, ParseEKUExtension) { | 26 TEST(ExtendedKeyUsageTest, ParseEKUExtension) { |
27 // clang-format off | 27 // clang-format off |
28 const uint8_t raw_extension_value[] = { | 28 const uint8_t raw_extension_value[] = { |
29 0x30, 0x14, // SEQUENCE (20 bytes) | 29 0x30, 0x14, // SEQUENCE (20 bytes) |
(...skipping 25 matching lines...) Expand all Loading... |
55 0x06, 0x08, // OBJECT IDENTIFIER (8 bytes) | 55 0x06, 0x08, // OBJECT IDENTIFIER (8 bytes) |
56 0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x01 // 1.3.6.1.5.5.7.3.1 | 56 0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x01 // 1.3.6.1.5.5.7.3.1 |
57 }; | 57 }; |
58 // clang-format on | 58 // clang-format on |
59 der::Input extension(extension_bytes); | 59 der::Input extension(extension_bytes); |
60 | 60 |
61 std::vector<der::Input> ekus; | 61 std::vector<der::Input> ekus; |
62 EXPECT_TRUE(ParseEKUExtension(extension, &ekus)); | 62 EXPECT_TRUE(ParseEKUExtension(extension, &ekus)); |
63 EXPECT_EQ(2u, ekus.size()); | 63 EXPECT_EQ(2u, ekus.size()); |
64 for (const auto& eku : ekus) { | 64 for (const auto& eku : ekus) { |
65 EXPECT_TRUE(eku.Equals(ServerAuth())); | 65 EXPECT_EQ(ServerAuth(), eku); |
66 } | 66 } |
67 } | 67 } |
68 | 68 |
69 // Check that parsing an EKU extension which contains a private OID doesn't | 69 // Check that parsing an EKU extension which contains a private OID doesn't |
70 // cause an error. | 70 // cause an error. |
71 TEST(ExtendedKeyUsageTest, ParseEKUExtensionGracefullyHandlesPrivateOids) { | 71 TEST(ExtendedKeyUsageTest, ParseEKUExtensionGracefullyHandlesPrivateOids) { |
72 // clang-format off | 72 // clang-format off |
73 const uint8_t extension_bytes[] = { | 73 const uint8_t extension_bytes[] = { |
74 0x30, 0x13, // SEQUENCE (19 bytes) | 74 0x30, 0x13, // SEQUENCE (19 bytes) |
75 0x06, 0x08, // OBJECT IDENTIFIER (8 bytes) | 75 0x06, 0x08, // OBJECT IDENTIFIER (8 bytes) |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 | 158 |
159 // The extension value must not be empty. | 159 // The extension value must not be empty. |
160 TEST(ExtendedKeyUsageTest, EmptyExtension) { | 160 TEST(ExtendedKeyUsageTest, EmptyExtension) { |
161 std::vector<der::Input> ekus; | 161 std::vector<der::Input> ekus; |
162 EXPECT_FALSE(ParseEKUExtension(der::Input(), &ekus)); | 162 EXPECT_FALSE(ParseEKUExtension(der::Input(), &ekus)); |
163 } | 163 } |
164 | 164 |
165 } // namespace | 165 } // namespace |
166 | 166 |
167 } // namespace net | 167 } // namespace net |
OLD | NEW |