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

Unified Diff: net/ssl/ssl_platform_key_chromecast_unittest.cc

Issue 2577683002: Add unit tests for NSS-backed SSLPrivateKeys. (Closed)
Patch Set: rebase atop asan fix Created 4 years 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 side-by-side diff with in-line comments
Download patch
Index: net/ssl/ssl_platform_key_chromecast_unittest.cc
diff --git a/net/ssl/ssl_platform_key_chromecast_unittest.cc b/net/ssl/ssl_platform_key_chromecast_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..78979c5069384245d19b21db9d62df507065b4f7
--- /dev/null
+++ b/net/ssl/ssl_platform_key_chromecast_unittest.cc
@@ -0,0 +1,52 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/ssl/ssl_platform_key.h"
+
+#include <pk11pub.h>
+#include <stdint.h>
+#include <string.h>
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "base/files/file_path.h"
+#include "base/files/file_util.h"
+#include "base/memory/ref_counted.h"
+#include "crypto/scoped_test_nss_db.h"
+#include "net/ssl/ssl_private_key.h"
+#include "net/ssl/ssl_private_key_test_util.h"
+#include "net/test/cert_test_util.h"
+#include "net/test/test_data_directory.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace net {
+
+TEST(SSLPlatformKeyChromecastTest, KeyMatches) {
+ std::string pkcs8;
+ base::FilePath pkcs8_path =
+ GetTestCertsDirectory().AppendASCII("client_1.pk8");
+ ASSERT_TRUE(base::ReadFileToString(pkcs8_path, &pkcs8));
+
+ // Import the key into a test NSS database.
+ crypto::ScopedTestNSSDB test_db;
+ scoped_refptr<X509Certificate> cert = ImportClientCertAndKeyFromFile(
+ GetTestCertsDirectory(), "client_1.pem", "client_1.pk8", test_db.slot());
+ ASSERT_TRUE(cert);
+
+ // Look up the key.
+ scoped_refptr<SSLPrivateKey> key = FetchClientCertPrivateKey(cert.get());
+ ASSERT_TRUE(key);
+
+ // Only support SHA-256 and SHA-1.
+ std::vector<SSLPrivateKey::Hash> expected_hashes = {
+ SSLPrivateKey::Hash::SHA256, SSLPrivateKey::Hash::SHA1,
+ };
+ EXPECT_EQ(expected_hashes, key->GetDigestPreferences());
+
+ TestSSLPrivateKeyMatches(key.get(), pkcs8);
+}
+
+} // namespace net

Powered by Google App Engine
This is Rietveld 408576698