Commit 20daf9a1 authored by bnc's avatar bnc Committed by Commit bot

Implement per-server ProofVerifyDetails in MockCryptoClientStreamFactory.

Implement per-server ProofVerifyDetails in MockCryptoClientStreamFactory, and
use them in QuicStreamFactoryTest.NoHttpsPoolingWithDifferentPins.  This is in
preparation for an upcoming change that will check certificates in
QuicStreamRequest(), therefore every test will have to provide valid
certificates (and pin configurations).

BUG=474217

Review URL: https://codereview.chromium.org/1140173002

Cr-Commit-Position: refs/heads/master@{#330118}
parent 666f3f02
...@@ -1254,7 +1254,7 @@ TEST_P(QuicNetworkTransactionTest, SecureResourceOverSecureQuic) { ...@@ -1254,7 +1254,7 @@ TEST_P(QuicNetworkTransactionTest, SecureResourceOverSecureQuic) {
cert->VerifyNameMatch("www.example.org", &common_name_fallback_used)); cert->VerifyNameMatch("www.example.org", &common_name_fallback_used));
ProofVerifyDetailsChromium verify_details; ProofVerifyDetailsChromium verify_details;
verify_details.cert_verify_result.verified_cert = cert; verify_details.cert_verify_result.verified_cert = cert;
crypto_client_stream_factory_.set_proof_verify_details(&verify_details); crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
request_.url = GURL("https://www.example.org:443"); request_.url = GURL("https://www.example.org:443");
AddHangingNonAlternateProtocolSocketData(); AddHangingNonAlternateProtocolSocketData();
......
...@@ -682,7 +682,7 @@ TEST_P(QuicStreamFactoryTest, HttpsPooling) { ...@@ -682,7 +682,7 @@ TEST_P(QuicStreamFactoryTest, HttpsPooling) {
ProofVerifyDetailsChromium verify_details; ProofVerifyDetailsChromium verify_details;
verify_details.cert_verify_result.verified_cert = test_cert; verify_details.cert_verify_result.verified_cert = test_cert;
verify_details.cert_verify_result.is_issued_by_known_root = true; verify_details.cert_verify_result.is_issued_by_known_root = true;
crypto_client_stream_factory_.set_proof_verify_details(&verify_details); crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
host_resolver_.set_synchronous_mode(true); host_resolver_.set_synchronous_mode(true);
host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", "");
...@@ -746,7 +746,7 @@ TEST_P(QuicStreamFactoryTest, NoHttpsPoolingIfDisabled) { ...@@ -746,7 +746,7 @@ TEST_P(QuicStreamFactoryTest, NoHttpsPoolingIfDisabled) {
ProofVerifyDetailsChromium verify_details; ProofVerifyDetailsChromium verify_details;
verify_details.cert_verify_result.verified_cert = test_cert; verify_details.cert_verify_result.verified_cert = test_cert;
verify_details.cert_verify_result.is_issued_by_known_root = true; verify_details.cert_verify_result.is_issued_by_known_root = true;
crypto_client_stream_factory_.set_proof_verify_details(&verify_details); crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
host_resolver_.set_synchronous_mode(true); host_resolver_.set_synchronous_mode(true);
host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", "");
...@@ -815,8 +815,7 @@ TEST_P(QuicStreamFactoryTest, NoHttpsPoolingWithCertMismatch) { ...@@ -815,8 +815,7 @@ TEST_P(QuicStreamFactoryTest, NoHttpsPoolingWithCertMismatch) {
ASSERT_NE(static_cast<X509Certificate*>(nullptr), test_cert.get()); ASSERT_NE(static_cast<X509Certificate*>(nullptr), test_cert.get());
ProofVerifyDetailsChromium verify_details; ProofVerifyDetailsChromium verify_details;
verify_details.cert_verify_result.verified_cert = test_cert; verify_details.cert_verify_result.verified_cert = test_cert;
crypto_client_stream_factory_.set_proof_verify_details(&verify_details); crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
host_resolver_.set_synchronous_mode(true); host_resolver_.set_synchronous_mode(true);
host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", "");
...@@ -884,8 +883,7 @@ TEST_P(QuicStreamFactoryTest, HttpsPoolingWithMatchingPins) { ...@@ -884,8 +883,7 @@ TEST_P(QuicStreamFactoryTest, HttpsPoolingWithMatchingPins) {
verify_details.cert_verify_result.is_issued_by_known_root = true; verify_details.cert_verify_result.is_issued_by_known_root = true;
verify_details.cert_verify_result.public_key_hashes.push_back( verify_details.cert_verify_result.public_key_hashes.push_back(
test::GetTestHashValue(primary_pin)); test::GetTestHashValue(primary_pin));
crypto_client_stream_factory_.set_proof_verify_details(&verify_details); crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
host_resolver_.set_synchronous_mode(true); host_resolver_.set_synchronous_mode(true);
host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", "");
...@@ -954,8 +952,7 @@ TEST_P(QuicStreamFactoryTest, NoHttpsPoolingWithMatchingPinsIfDisabled) { ...@@ -954,8 +952,7 @@ TEST_P(QuicStreamFactoryTest, NoHttpsPoolingWithMatchingPinsIfDisabled) {
verify_details.cert_verify_result.is_issued_by_known_root = true; verify_details.cert_verify_result.is_issued_by_known_root = true;
verify_details.cert_verify_result.public_key_hashes.push_back( verify_details.cert_verify_result.public_key_hashes.push_back(
test::GetTestHashValue(primary_pin)); test::GetTestHashValue(primary_pin));
crypto_client_stream_factory_.set_proof_verify_details(&verify_details); crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
host_resolver_.set_synchronous_mode(true); host_resolver_.set_synchronous_mode(true);
host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", "");
...@@ -1025,13 +1022,20 @@ TEST_P(QuicStreamFactoryTest, NoHttpsPoolingWithDifferentPins) { ...@@ -1025,13 +1022,20 @@ TEST_P(QuicStreamFactoryTest, NoHttpsPoolingWithDifferentPins) {
scoped_refptr<X509Certificate> test_cert( scoped_refptr<X509Certificate> test_cert(
ImportCertFromFile(certs_dir, "spdy_pooling.pem")); ImportCertFromFile(certs_dir, "spdy_pooling.pem"));
ASSERT_NE(static_cast<X509Certificate*>(nullptr), test_cert.get()); ASSERT_NE(static_cast<X509Certificate*>(nullptr), test_cert.get());
ProofVerifyDetailsChromium verify_details;
verify_details.cert_verify_result.verified_cert = test_cert; ProofVerifyDetailsChromium verify_details1;
verify_details.cert_verify_result.is_issued_by_known_root = true; verify_details1.cert_verify_result.verified_cert = test_cert;
verify_details.cert_verify_result.public_key_hashes.push_back( verify_details1.cert_verify_result.is_issued_by_known_root = true;
verify_details1.cert_verify_result.public_key_hashes.push_back(
test::GetTestHashValue(bad_pin)); test::GetTestHashValue(bad_pin));
crypto_client_stream_factory_.set_proof_verify_details(&verify_details); crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details1);
ProofVerifyDetailsChromium verify_details2;
verify_details2.cert_verify_result.verified_cert = test_cert;
verify_details2.cert_verify_result.is_issued_by_known_root = true;
verify_details2.cert_verify_result.public_key_hashes.push_back(
test::GetTestHashValue(primary_pin));
crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details2);
host_resolver_.set_synchronous_mode(true); host_resolver_.set_synchronous_mode(true);
host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", "");
......
...@@ -13,10 +13,12 @@ using std::string; ...@@ -13,10 +13,12 @@ using std::string;
namespace net { namespace net {
MockCryptoClientStreamFactory::~MockCryptoClientStreamFactory() {
}
MockCryptoClientStreamFactory::MockCryptoClientStreamFactory() MockCryptoClientStreamFactory::MockCryptoClientStreamFactory()
: handshake_mode_(MockCryptoClientStream::CONFIRM_HANDSHAKE), : handshake_mode_(MockCryptoClientStream::CONFIRM_HANDSHAKE),
last_stream_(nullptr), last_stream_(nullptr) {
proof_verify_details_(nullptr) {
} }
QuicCryptoClientStream* QuicCryptoClientStream*
...@@ -24,9 +26,14 @@ MockCryptoClientStreamFactory::CreateQuicCryptoClientStream( ...@@ -24,9 +26,14 @@ MockCryptoClientStreamFactory::CreateQuicCryptoClientStream(
const QuicServerId& server_id, const QuicServerId& server_id,
QuicClientSession* session, QuicClientSession* session,
QuicCryptoClientConfig* crypto_config) { QuicCryptoClientConfig* crypto_config) {
last_stream_ = new MockCryptoClientStream( const ProofVerifyDetails* proof_verify_details = nullptr;
server_id, session, nullptr, crypto_config, handshake_mode_, if (!proof_verify_details_queue_.empty()) {
proof_verify_details_); proof_verify_details = proof_verify_details_queue_.front();
proof_verify_details_queue_.pop();
}
last_stream_ =
new MockCryptoClientStream(server_id, session, nullptr, crypto_config,
handshake_mode_, proof_verify_details);
return last_stream_; return last_stream_;
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef NET_QUIC_TEST_TOOLS_MOCK_CRYPTO_CLIENT_STREAM_FACTORY_H_ #ifndef NET_QUIC_TEST_TOOLS_MOCK_CRYPTO_CLIENT_STREAM_FACTORY_H_
#define NET_QUIC_TEST_TOOLS_MOCK_CRYPTO_CLIENT_STREAM_FACTORY_H_ #define NET_QUIC_TEST_TOOLS_MOCK_CRYPTO_CLIENT_STREAM_FACTORY_H_
#include <queue>
#include <string> #include <string>
#include "net/quic/quic_crypto_client_stream.h" #include "net/quic/quic_crypto_client_stream.h"
...@@ -18,7 +19,7 @@ class QuicServerId; ...@@ -18,7 +19,7 @@ class QuicServerId;
class MockCryptoClientStreamFactory : public QuicCryptoClientStreamFactory { class MockCryptoClientStreamFactory : public QuicCryptoClientStreamFactory {
public: public:
MockCryptoClientStreamFactory(); MockCryptoClientStreamFactory();
~MockCryptoClientStreamFactory() override {} ~MockCryptoClientStreamFactory() override;
QuicCryptoClientStream* CreateQuicCryptoClientStream( QuicCryptoClientStream* CreateQuicCryptoClientStream(
const QuicServerId& server_id, const QuicServerId& server_id,
...@@ -30,9 +31,9 @@ class MockCryptoClientStreamFactory : public QuicCryptoClientStreamFactory { ...@@ -30,9 +31,9 @@ class MockCryptoClientStreamFactory : public QuicCryptoClientStreamFactory {
handshake_mode_ = handshake_mode; handshake_mode_ = handshake_mode;
} }
void set_proof_verify_details( // The caller keeps ownership of |proof_verify_details|.
const ProofVerifyDetails* proof_verify_details) { void AddProofVerifyDetails(const ProofVerifyDetails* proof_verify_details) {
proof_verify_details_ = proof_verify_details; proof_verify_details_queue_.push(proof_verify_details);
} }
MockCryptoClientStream* last_stream() const { MockCryptoClientStream* last_stream() const {
...@@ -42,7 +43,7 @@ class MockCryptoClientStreamFactory : public QuicCryptoClientStreamFactory { ...@@ -42,7 +43,7 @@ class MockCryptoClientStreamFactory : public QuicCryptoClientStreamFactory {
private: private:
MockCryptoClientStream::HandshakeMode handshake_mode_; MockCryptoClientStream::HandshakeMode handshake_mode_;
MockCryptoClientStream* last_stream_; MockCryptoClientStream* last_stream_;
const ProofVerifyDetails* proof_verify_details_; std::queue<const ProofVerifyDetails*> proof_verify_details_queue_;
DISALLOW_COPY_AND_ASSIGN(MockCryptoClientStreamFactory); DISALLOW_COPY_AND_ASSIGN(MockCryptoClientStreamFactory);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment