1 // Copyright 2015 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef NET_CERT_MOCK_CLIENT_CERT_VERIFIER_H_ 6 #define NET_CERT_MOCK_CLIENT_CERT_VERIFIER_H_ 7 8 #include <list> 9 #include <memory> 10 11 #include "net/base/completion_once_callback.h" 12 #include "net/base/net_errors.h" 13 #include "net/cert/client_cert_verifier.h" 14 15 namespace net { 16 17 class MockClientCertVerifier : public ClientCertVerifier { 18 public: 19 // Creates a new MockClientCertVerifier. By default, any call to Verify() will 20 // result in the cert status being flagged as CERT_STATUS_INVALID and return 21 // an ERR_CERT_INVALID network error code. This behaviour can be overridden 22 // by calling set_default_result() to change the default return value for 23 // Verify() or by calling one of the AddResult*() methods to specifically 24 // handle a certificate or certificate and host. 25 MockClientCertVerifier(); 26 27 ~MockClientCertVerifier() override; 28 29 // ClientCertVerifier implementation 30 int Verify(X509Certificate* cert, 31 CompletionOnceCallback callback, 32 std::unique_ptr<Request>* out_req) override; 33 34 // Sets the default return value for Verify() for certificates/hosts that do 35 // not have explicit results added via the AddResult*() methods. set_default_result(int default_result)36 void set_default_result(int default_result) { 37 default_result_ = default_result; 38 } 39 40 // Adds a rule that will cause any call to Verify() for |cert| to return rv. 41 // Note: Only the primary certificate of |cert| is checked. Any intermediate 42 // certificates will be ignored. 43 void AddResultForCert(X509Certificate* cert, int rv); 44 45 private: 46 struct Rule; 47 typedef std::list<Rule> RuleList; 48 49 int default_result_ = ERR_CERT_INVALID; 50 RuleList rules_; 51 }; 52 53 } // namespace net 54 55 #endif // NET_CERT_MOCK_CLIENT_CERT_VERIFIER_H_ 56