Index: net/quic/crypto/proof_test.cc |
diff --git a/net/quic/crypto/proof_test.cc b/net/quic/crypto/proof_test.cc |
index 5392a635d60e709d1ccbe3d6cd7ff25cfe50212f..615cc12b71db3079775ac2a9a51beb4f704e0fd2 100644 |
--- a/net/quic/crypto/proof_test.cc |
+++ b/net/quic/crypto/proof_test.cc |
@@ -106,6 +106,38 @@ string LoadTestCert(const string& file_name) { |
return der_bytes; |
} |
+class TestCallback : public ProofSource::Callback { |
+ public: |
+ explicit TestCallback(bool* called, |
+ bool* ok, |
+ scoped_refptr<ProofSource::Chain>* chain, |
+ string* signature, |
+ string* leaf_cert_sct) |
+ : called_(called), |
+ ok_(ok), |
+ chain_(chain), |
+ signature_(signature), |
+ leaf_cert_sct_(leaf_cert_sct) {} |
+ |
+ void Run(bool ok, |
+ const scoped_refptr<ProofSource::Chain>& chain, |
+ const string& signature, |
+ const string& leaf_cert_sct) override { |
+ *ok_ = ok; |
+ *chain_ = chain; |
+ *signature_ = signature; |
+ *leaf_cert_sct_ = leaf_cert_sct; |
+ *called_ = true; |
+ } |
+ |
+ private: |
+ bool* called_; |
+ bool* ok_; |
+ scoped_refptr<ProofSource::Chain>* chain_; |
+ string* signature_; |
+ string* leaf_cert_sct_; |
+}; |
+ |
class ProofTest : public ::testing::TestWithParam<QuicVersion> {}; |
} // namespace |
@@ -172,6 +204,43 @@ TEST_P(ProofTest, DISABLED_Verify) { |
first_chlo_hash, wrong_certs, corrupt_signature, false); |
} |
+TEST_P(ProofTest, VerifySourceAsync) { |
+ std::unique_ptr<ProofSource> source(CryptoTestUtils::ProofSourceForTesting()); |
+ |
+ const string server_config = "server config bytes"; |
+ const string hostname = "test.example.com"; |
+ const string first_chlo_hash = "first chlo hash bytes"; |
+ const string second_chlo_hash = "first chlo hash bytes"; |
+ const QuicVersion quic_version = GetParam(); |
+ IPAddress server_ip; |
+ |
+ // Call synchronous version |
+ scoped_refptr<ProofSource::Chain> expected_chain; |
+ string expected_signature; |
+ string expected_leaf_cert_sct; |
+ ASSERT_TRUE(source->GetProof(server_ip, hostname, server_config, quic_version, |
+ first_chlo_hash, false /* no ECDSA */, |
+ &expected_chain, &expected_signature, |
+ &expected_leaf_cert_sct)); |
+ |
+ // Call asynchronous version and compare results |
+ bool called = false; |
+ bool ok; |
+ scoped_refptr<ProofSource::Chain> chain; |
+ string signature; |
+ string leaf_cert_sct; |
+ std::unique_ptr<ProofSource::Callback> cb( |
+ new TestCallback(&called, &ok, &chain, &signature, &leaf_cert_sct)); |
+ source->GetProof(server_ip, hostname, server_config, quic_version, |
+ first_chlo_hash, false /* no ECDSA */, std::move(cb)); |
+ // TODO(gredner): whan GetProof really invokes the callback asynchronously, |
+ // figure out what to do here. |
+ ASSERT_TRUE(called); |
+ ASSERT_TRUE(ok); |
+ EXPECT_THAT(chain->certs, ::testing::ContainerEq(expected_chain->certs)); |
+ EXPECT_EQ(leaf_cert_sct, expected_leaf_cert_sct); |
+} |
+ |
TEST_P(ProofTest, UseAfterFree) { |
ProofSource* source = CryptoTestUtils::ProofSourceForTesting(); |