| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/cert/mock_cert_verifier.h" | 5 #include "net/cert/mock_cert_verifier.h" |
| 6 | 6 |
| 7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/strings/pattern.h" | 8 #include "base/strings/pattern.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 | 39 |
| 40 int MockCertVerifier::Verify(X509Certificate* cert, | 40 int MockCertVerifier::Verify(X509Certificate* cert, |
| 41 const std::string& hostname, | 41 const std::string& hostname, |
| 42 const std::string& ocsp_response, | 42 const std::string& ocsp_response, |
| 43 int flags, | 43 int flags, |
| 44 CRLSet* crl_set, | 44 CRLSet* crl_set, |
| 45 CertVerifyResult* verify_result, | 45 CertVerifyResult* verify_result, |
| 46 const CompletionCallback& callback, | 46 const CompletionCallback& callback, |
| 47 scoped_ptr<Request>* out_req, | 47 scoped_ptr<Request>* out_req, |
| 48 const BoundNetLog& net_log) { | 48 const BoundNetLog& net_log) { |
| 49 RuleList::const_iterator it; | 49 if (cert) { |
| 50 for (it = rules_.begin(); it != rules_.end(); ++it) { | 50 RuleList::const_iterator it; |
| 51 // Check just the server cert. Intermediates will be ignored. | 51 for (it = rules_.begin(); it != rules_.end(); ++it) { |
| 52 if (!it->cert->Equals(cert)) | 52 // Check just the server cert. Intermediates will be ignored. |
| 53 continue; | 53 if (!it->cert->Equals(cert)) |
| 54 if (!base::MatchPattern(hostname, it->hostname)) | 54 continue; |
| 55 continue; | 55 if (!base::MatchPattern(hostname, it->hostname)) |
| 56 *verify_result = it->result; | 56 continue; |
| 57 return it->rv; | 57 *verify_result = it->result; |
| 58 return it->rv; |
| 59 } |
| 58 } | 60 } |
| 59 | 61 |
| 60 // Fall through to the default. | 62 // Fall through to the default. |
| 61 verify_result->verified_cert = cert; | 63 verify_result->verified_cert = cert; |
| 62 verify_result->cert_status = MapNetErrorToCertStatus(default_result_); | 64 verify_result->cert_status = MapNetErrorToCertStatus(default_result_); |
| 63 return default_result_; | 65 return default_result_; |
| 64 } | 66 } |
| 65 | 67 |
| 66 void MockCertVerifier::AddResultForCert(X509Certificate* cert, | 68 void MockCertVerifier::AddResultForCert(X509Certificate* cert, |
| 67 const CertVerifyResult& verify_result, | 69 const CertVerifyResult& verify_result, |
| 68 int rv) { | 70 int rv) { |
| 69 AddResultForCertAndHost(cert, "*", verify_result, rv); | 71 AddResultForCertAndHost(cert, "*", verify_result, rv); |
| 70 } | 72 } |
| 71 | 73 |
| 72 void MockCertVerifier::AddResultForCertAndHost( | 74 void MockCertVerifier::AddResultForCertAndHost( |
| 73 X509Certificate* cert, | 75 X509Certificate* cert, |
| 74 const std::string& host_pattern, | 76 const std::string& host_pattern, |
| 75 const CertVerifyResult& verify_result, | 77 const CertVerifyResult& verify_result, |
| 76 int rv) { | 78 int rv) { |
| 77 Rule rule(cert, host_pattern, verify_result, rv); | 79 Rule rule(cert, host_pattern, verify_result, rv); |
| 78 rules_.push_back(rule); | 80 rules_.push_back(rule); |
| 79 } | 81 } |
| 80 | 82 |
| 81 } // namespace net | 83 } // namespace net |
| OLD | NEW |