src/net/cert/nss_cert_database_chromeos_unittest.cc
TEST_F(NSSCertDatabaseChromeOSTest, ImportCACerts) {
  // Load test certs from disk.
  ScopedCERTCertificateList certs_1 = CreateCERTCertificateListFromFile(
      GetTestCertsDirectory(), "root_ca_cert.pem",
      X509Certificate::FORMAT_AUTO);
  ASSERT_EQ(1U, certs_1.size());

  ScopedCERTCertificateList certs_2 = CreateCERTCertificateListFromFile(
      GetTestCertsDirectory(), "2048-rsa-root.pem",
      X509Certificate::FORMAT_AUTO);
  ASSERT_EQ(1U, certs_2.size());

  // Import one cert for each user.
  NSSCertDatabase::ImportCertFailureList failed;
  EXPECT_TRUE(
      db_1_->ImportCACerts(certs_1, NSSCertDatabase::TRUSTED_SSL, &failed));
  EXPECT_EQ(0U, failed.size());
  failed.clear();
  EXPECT_TRUE(
      db_2_->ImportCACerts(certs_2, NSSCertDatabase::TRUSTED_SSL, &failed));
  EXPECT_EQ(0U, failed.size());

  // Get cert list for each user.
  ScopedCERTCertificateList user_1_certlist;
  ScopedCERTCertificateList user_2_certlist;
  db_1_->ListCerts(
      base::BindOnce(&SwapCertLists, base::Unretained(&user_1_certlist)));
  db_2_->ListCerts(
      base::BindOnce(&SwapCertLists, base::Unretained(&user_2_certlist)));

  // Run the message loop so the observer notifications get processed and
  // lookups are completed.
  RunUntilIdle();
  // Should have gotten two OnCertDBChanged notifications.
  ASSERT_EQ(2, db_changed_count_);

  EXPECT_TRUE(IsCertInCertificateList(certs_1[0].get(), user_1_certlist));
  EXPECT_FALSE(IsCertInCertificateList(certs_1[0].get(), user_2_certlist));

  EXPECT_TRUE(IsCertInCertificateList(certs_2[0].get(), user_2_certlist));
  EXPECT_FALSE(IsCertInCertificateList(certs_2[0].get(), user_1_certlist));
}
// Test that ImportCACerts imports the cert to the correct slot, and that
// ListCerts includes the added cert for the correct user, and does not include
// it for the other user.
Test that ImportCACerts imports the cert to the correct slot, and that
ListCerts includes the added cert for the correct user, and does not include
it for the other user.
Test that ImportCACerts imports the cert to the correct slot and that ListCerts includes the added cert for the correct user and does not include it for the other user .
TEST_F(NSSCertDatabaseChromeOSTest, ImportCACerts) {
  ScopedCERTCertificateList certs_1 = CreateCERTCertificateListFromFile(
      GetTestCertsDirectory(), "root_ca_cert.pem",
      X509Certificate::FORMAT_AUTO);
  ASSERT_EQ(1U, certs_1.size());
  ScopedCERTCertificateList certs_2 = CreateCERTCertificateListFromFile(
      GetTestCertsDirectory(), "2048-rsa-root.pem",
      X509Certificate::FORMAT_AUTO);
  ASSERT_EQ(1U, certs_2.size());
  NSSCertDatabase::ImportCertFailureList failed;
  EXPECT_TRUE(
      db_1_->ImportCACerts(certs_1, NSSCertDatabase::TRUSTED_SSL, &failed));
  EXPECT_EQ(0U, failed.size());
  failed.clear();
  EXPECT_TRUE(
      db_2_->ImportCACerts(certs_2, NSSCertDatabase::TRUSTED_SSL, &failed));
  EXPECT_EQ(0U, failed.size());
  ScopedCERTCertificateList user_1_certlist;
  ScopedCERTCertificateList user_2_certlist;
  db_1_->ListCerts(
      base::BindOnce(&SwapCertLists, base::Unretained(&user_1_certlist)));
  db_2_->ListCerts(
      base::BindOnce(&SwapCertLists, base::Unretained(&user_2_certlist)));
  RunUntilIdle();
  ASSERT_EQ(2, db_changed_count_);
  EXPECT_TRUE(IsCertInCertificateList(certs_1[0].get(), user_1_certlist));
  EXPECT_FALSE(IsCertInCertificateList(certs_1[0].get(), user_2_certlist));
  EXPECT_TRUE(IsCertInCertificateList(certs_2[0].get(), user_2_certlist));
  EXPECT_FALSE(IsCertInCertificateList(certs_2[0].get(), user_1_certlist));
}
TEST_F ( NSSCertDatabaseChromeOSTest , ImportCACerts ) { ScopedCERTCertificateList certs_1 = CreateCERTCertificateListFromFile ( GetTestCertsDirectory ( ) , " " , X509Certificate :: FORMAT_AUTO ) ; ASSERT_EQ ( 1U , certs_1 . size ( ) ) ; ScopedCERTCertificateList certs_2 = CreateCERTCertificateListFromFile ( GetTestCertsDirectory ( ) , " " , X509Certificate :: FORMAT_AUTO ) ; ASSERT_EQ ( 1U , certs_2 . size ( ) ) ; NSSCertDatabase :: ImportCertFailureList failed ; EXPECT_TRUE ( db_1_ -> ImportCACerts ( certs_1 , NSSCertDatabase :: TRUSTED_SSL , & failed ) ) ; EXPECT_EQ ( 0U , failed . size ( ) ) ; failed . clear ( ) ; EXPECT_TRUE ( db_2_ -> ImportCACerts ( certs_2 , NSSCertDatabase :: TRUSTED_SSL , & failed ) ) ; EXPECT_EQ ( 0U , failed . size ( ) ) ; ScopedCERTCertificateList user_1_certlist ; ScopedCERTCertificateList user_2_certlist ; db_1_ -> ListCerts ( base :: BindOnce ( & SwapCertLists , base :: Unretained ( & user_1_certlist ) ) ) ; db_2_ -> ListCerts ( base :: BindOnce ( & SwapCertLists , base :: Unretained ( & user_2_certlist ) ) ) ; RunUntilIdle ( ) ; ASSERT_EQ ( 2 , db_changed_count_ ) ; EXPECT_TRUE ( IsCertInCertificateList ( certs_1 [ 0 ] . get ( ) , user_1_certlist ) ) ; EXPECT_FALSE ( IsCertInCertificateList ( certs_1 [ 0 ] . get ( ) , user_2_certlist ) ) ; EXPECT_TRUE ( IsCertInCertificateList ( certs_2 [ 0 ] . get ( ) , user_2_certlist ) ) ; EXPECT_FALSE ( IsCertInCertificateList ( certs_2 [ 0 ] . get ( ) , user_1_certlist ) ) ; }
Test that ImportCACerts imports the cert to the correct slot, and that
ListCerts includes the added cert for the correct user, and does not include
it for the other user.
Test that ImportCACerts imports the cert to the correct slot and that ListCerts includes the added cert for the correct user and does not include it for the other user .
// Load test certs from disk. // Import one cert for each user. // Get cert list for each user. // Run the message loop so the observer notifications get processed and // lookups are completed. // Should have gotten two OnCertDBChanged notifications.