/src/mozilla-central/security/manager/ssl/tests/gtest/CertDBTest.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
3 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
4 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
5 | | |
6 | | #include "gtest/gtest.h" |
7 | | #include "nsCOMPtr.h" |
8 | | #include "nsIPrefService.h" |
9 | | #include "nsISimpleEnumerator.h" |
10 | | #include "nsIX509Cert.h" |
11 | | #include "nsIX509CertDB.h" |
12 | | #include "nsIX509CertList.h" |
13 | | #include "nsServiceManagerUtils.h" |
14 | | |
15 | | TEST(psm_CertDB, Test) |
16 | 0 | { |
17 | 0 | { |
18 | 0 | nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID)); |
19 | 0 | ASSERT_TRUE(prefs) << "couldn't get nsIPrefBranch"; |
20 | 0 | |
21 | 0 | // When PSM initializes, it attempts to get some localized strings. |
22 | 0 | // As a result, Android flips out if this isn't set. |
23 | 0 | nsresult rv = prefs->SetBoolPref("intl.locale.matchOS", true); |
24 | 0 | ASSERT_TRUE(NS_SUCCEEDED(rv)) << "couldn't set pref 'intl.locale.matchOS'"; |
25 | 0 | |
26 | 0 | nsCOMPtr<nsIX509CertDB> certdb(do_GetService(NS_X509CERTDB_CONTRACTID)); |
27 | 0 | ASSERT_TRUE(certdb) << "couldn't get certdb"; |
28 | 0 | |
29 | 0 | nsCOMPtr<nsIX509CertList> certList; |
30 | 0 | rv = certdb->GetCerts(getter_AddRefs(certList)); |
31 | 0 | ASSERT_TRUE(NS_SUCCEEDED(rv)) << "couldn't get list of certificates"; |
32 | 0 | |
33 | 0 | nsCOMPtr<nsISimpleEnumerator> enumerator; |
34 | 0 | rv = certList->GetEnumerator(getter_AddRefs(enumerator)); |
35 | 0 | ASSERT_TRUE(NS_SUCCEEDED(rv)) << "couldn't enumerate certificate list"; |
36 | 0 | |
37 | 0 | bool foundBuiltIn = false; |
38 | 0 | bool hasMore = false; |
39 | 0 | while (NS_SUCCEEDED(enumerator->HasMoreElements(&hasMore)) && hasMore) { |
40 | 0 | nsCOMPtr<nsISupports> supports; |
41 | 0 | ASSERT_TRUE(NS_SUCCEEDED(enumerator->GetNext(getter_AddRefs(supports)))) |
42 | 0 | << "couldn't get next certificate"; |
43 | 0 | |
44 | 0 | nsCOMPtr<nsIX509Cert> cert(do_QueryInterface(supports)); |
45 | 0 | ASSERT_TRUE(cert) << "couldn't QI to nsIX509Cert"; |
46 | 0 | |
47 | 0 | ASSERT_TRUE(NS_SUCCEEDED(cert->GetIsBuiltInRoot(&foundBuiltIn))) << |
48 | 0 | "GetIsBuiltInRoot failed"; |
49 | 0 | |
50 | 0 | if (foundBuiltIn) { |
51 | 0 | break; |
52 | 0 | } |
53 | 0 | } |
54 | 0 |
|
55 | 0 | ASSERT_TRUE(foundBuiltIn) << "didn't load any built-in certificates"; |
56 | 0 | |
57 | 0 | printf("successfully loaded at least one built-in certificate\n"); |
58 | 0 |
|
59 | 0 | } // this scopes the nsCOMPtrs |
60 | 0 | } |