This source file includes following definitions.
- TEST
- TEST
- TEST
#include "chrome/common/net/x509_certificate_model.h"
#include "base/files/file_path.h"
#include "base/path_service.h"
#include "net/base/test_data_directory.h"
#include "net/test/cert_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#if defined(USE_NSS)
#include "net/cert/nss_cert_database.h"
#endif
TEST(X509CertificateModelTest, GetTypeCA) {
scoped_refptr<net::X509Certificate> cert(
net::ImportCertFromFile(net::GetTestCertsDirectory(),
"root_ca_cert.pem"));
ASSERT_TRUE(cert.get());
#if defined(USE_OPENSSL)
EXPECT_EQ(net::OTHER_CERT,
x509_certificate_model::GetType(cert->os_cert_handle()));
#else
EXPECT_EQ(net::CA_CERT,
x509_certificate_model::GetType(cert->os_cert_handle()));
EXPECT_TRUE(net::NSSCertDatabase::GetInstance()->SetCertTrust(
cert.get(), net::CA_CERT, net::NSSCertDatabase::DISTRUSTED_SSL));
EXPECT_EQ(net::CA_CERT,
x509_certificate_model::GetType(cert->os_cert_handle()));
#endif
}
TEST(X509CertificateModelTest, GetTypeServer) {
scoped_refptr<net::X509Certificate> cert(
net::ImportCertFromFile(net::GetTestCertsDirectory(),
"google.single.der"));
ASSERT_TRUE(cert.get());
#if defined(USE_OPENSSL)
EXPECT_EQ(net::OTHER_CERT,
x509_certificate_model::GetType(cert->os_cert_handle()));
#else
EXPECT_EQ(net::OTHER_CERT,
x509_certificate_model::GetType(cert->os_cert_handle()));
net::NSSCertDatabase* cert_db = net::NSSCertDatabase::GetInstance();
EXPECT_TRUE(cert_db->SetCertTrust(
cert.get(), net::SERVER_CERT, net::NSSCertDatabase::TRUSTED_SSL));
EXPECT_EQ(net::SERVER_CERT,
x509_certificate_model::GetType(cert->os_cert_handle()));
EXPECT_TRUE(cert_db->SetCertTrust(
cert.get(), net::SERVER_CERT, net::NSSCertDatabase::DISTRUSTED_SSL));
EXPECT_EQ(net::SERVER_CERT,
x509_certificate_model::GetType(cert->os_cert_handle()));
#endif
}
TEST(X509CertificateModelTest, GetVersionOmitted) {
scoped_refptr<net::X509Certificate> cert(
net::ImportCertFromFile(net::GetTestCertsDirectory(),
"ndn.ca.crt"));
ASSERT_TRUE(cert.get());
EXPECT_EQ("1", x509_certificate_model::GetVersion(cert->os_cert_handle()));
}