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

Side by Side Diff: net/cert/sec_trust_util_unittest.cc

Issue 2225483002: [ios] Removed CertVerifierBlockAdapter. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Self review Created 4 years, 4 months 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "net/cert/sec_trust_util.h"
6
7 #include <CoreFoundation/CoreFoundation.h>
8 #include <Security/Security.h>
9
10 #include "base/mac/scoped_cftyperef.h"
11 #include "base/memory/ref_counted.h"
12 #include "net/cert/x509_certificate.h"
13 #include "net/test/cert_test_util.h"
14 #include "net/test/test_data_directory.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 namespace {
18
19 // Creates new SecTrustRef object backed up by cert from |cert_file|.
20 base::ScopedCFTypeRef<SecTrustRef> CreateSecTrust(
21 const std::string& cert_file) {
22 base::ScopedCFTypeRef<SecTrustRef> scoped_result;
23
24 scoped_refptr<net::X509Certificate> cert =
25 net::ImportCertFromFile(net::GetTestCertsDirectory(), cert_file);
26 base::ScopedCFTypeRef<CFMutableArrayRef> certs(
27 CFArrayCreateMutable(kCFAllocatorDefault, 1, &kCFTypeArrayCallBacks));
28 CFArrayAppendValue(certs, cert->os_cert_handle());
29
30 base::ScopedCFTypeRef<SecPolicyRef> policy(
31 SecPolicyCreateSSL(TRUE, CFSTR("chromium.org")));
32 SecTrustRef result = nullptr;
33 if (SecTrustCreateWithCertificates(certs, policy, &result) == errSecSuccess) {
34 scoped_result.reset(result);
35 }
36 return scoped_result;
37 }
38
39 } // namespace
40
41 namespace net {
42
43 // Tests |GetCertFailureStatusFromTrust| with null trust object.
44 TEST(SecTrustUtilTest, NullTrust) {
45 EXPECT_EQ(CERT_STATUS_INVALID, GetCertFailureStatusFromTrust(nullptr));
46 }
47
48 // Tests |GetCertFailureStatusFromTrust| with trust object that has not been
49 // evaluated backed by ok_cert.pem cert.
50 TEST(SecTrustUtilTest, NotEvaluatedTrust) {
51 CertStatus status =
52 GetCertFailureStatusFromTrust(CreateSecTrust("ok_cert.pem"));
53 EXPECT_TRUE(status & CERT_STATUS_INVALID);
54 EXPECT_TRUE(status & CERT_STATUS_AUTHORITY_INVALID);
55 EXPECT_FALSE(status & CERT_STATUS_DATE_INVALID);
56 }
57
58 // Tests |GetCertFailureStatusFromTrust| with evaluated trust object backed by
59 // expired_cert.pem cert.
60 TEST(SecTrustUtilTest, EvaluatedTrust) {
61 base::ScopedCFTypeRef<SecTrustRef> trust(CreateSecTrust("expired_cert.pem"));
62 ASSERT_TRUE(trust);
63 SecTrustEvaluate(trust, nullptr);
64
65 CertStatus status = GetCertFailureStatusFromTrust(trust);
66 EXPECT_TRUE(status & CERT_STATUS_INVALID);
67 EXPECT_TRUE(status & CERT_STATUS_AUTHORITY_INVALID);
68 EXPECT_TRUE(status & CERT_STATUS_DATE_INVALID);
69 }
70
71 } // namespace net
OLDNEW
« net/cert/sec_trust_util.h ('K') | « net/cert/sec_trust_util.cc ('k') | net/net.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698