diff options
Diffstat (limited to '')
-rw-r--r-- | third_party/libwebrtc/p2p/base/transport_description_factory_unittest.cc | 112 |
1 files changed, 51 insertions, 61 deletions
diff --git a/third_party/libwebrtc/p2p/base/transport_description_factory_unittest.cc b/third_party/libwebrtc/p2p/base/transport_description_factory_unittest.cc index 0da5b7c294..0d38ac6d7b 100644 --- a/third_party/libwebrtc/p2p/base/transport_description_factory_unittest.cc +++ b/third_party/libwebrtc/p2p/base/transport_description_factory_unittest.cc @@ -33,6 +33,7 @@ using cricket::TransportDescriptionFactory; using cricket::TransportOptions; using ::testing::Contains; using ::testing::Not; +using ::testing::NotNull; class TransportDescriptionFactoryTest : public ::testing::Test { public: @@ -43,7 +44,11 @@ class TransportDescriptionFactoryTest : public ::testing::Test { cert1_(rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>( new rtc::FakeSSLIdentity("User1")))), cert2_(rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>( - new rtc::FakeSSLIdentity("User2")))) {} + new rtc::FakeSSLIdentity("User2")))) { + // By default, certificates are supplied. + f1_.set_certificate(cert1_); + f2_.set_certificate(cert2_); + } void CheckDesc(const TransportDescription* desc, absl::string_view opt, @@ -75,7 +80,12 @@ class TransportDescriptionFactoryTest : public ::testing::Test { // in the offer and answer is changed. // If `dtls` is true, the test verifies that the finger print is not changed. void TestIceRestart(bool dtls) { - SetDtls(dtls); + if (dtls) { + f1_.set_certificate(cert1_); + f2_.set_certificate(cert2_); + } else { + SetInsecure(); + } cricket::TransportOptions options; // The initial offer / answer exchange. std::unique_ptr<TransportDescription> offer = @@ -102,6 +112,8 @@ class TransportDescriptionFactoryTest : public ::testing::Test { void VerifyUfragAndPasswordChanged(bool dtls, const TransportDescription* org_desc, const TransportDescription* restart_desc) { + ASSERT_THAT(org_desc, NotNull()); + ASSERT_THAT(restart_desc, NotNull()); EXPECT_NE(org_desc->ice_pwd, restart_desc->ice_pwd); EXPECT_NE(org_desc->ice_ufrag, restart_desc->ice_ufrag); EXPECT_EQ(static_cast<size_t>(cricket::ICE_UFRAG_LENGTH), @@ -118,7 +130,9 @@ class TransportDescriptionFactoryTest : public ::testing::Test { } void TestIceRenomination(bool dtls) { - SetDtls(dtls); + if (!dtls) { + SetInsecureNoDtls(); + } cricket::TransportOptions options; // The initial offer / answer exchange. @@ -148,16 +162,16 @@ class TransportDescriptionFactoryTest : public ::testing::Test { } protected: - void SetDtls(bool dtls) { - if (dtls) { - f1_.set_secure(cricket::SEC_ENABLED); - f2_.set_secure(cricket::SEC_ENABLED); - f1_.set_certificate(cert1_); - f2_.set_certificate(cert2_); - } else { - f1_.set_secure(cricket::SEC_DISABLED); - f2_.set_secure(cricket::SEC_DISABLED); - } + // This will enable responding to non-DTLS requests. + void SetInsecure() { + f1_.SetInsecureForTesting(); + f2_.SetInsecureForTesting(); + } + // This will disable the ability to respond to DTLS requests. + void SetInsecureNoDtls() { + SetInsecure(); + f1_.set_certificate(nullptr); + f2_.set_certificate(nullptr); } webrtc::test::ScopedKeyValueConfig field_trials_; @@ -169,30 +183,18 @@ class TransportDescriptionFactoryTest : public ::testing::Test { rtc::scoped_refptr<rtc::RTCCertificate> cert2_; }; -TEST_F(TransportDescriptionFactoryTest, TestOfferDefault) { - std::unique_ptr<TransportDescription> desc = - f1_.CreateOffer(TransportOptions(), NULL, &ice_credentials_); - CheckDesc(desc.get(), "", "", "", ""); -} - TEST_F(TransportDescriptionFactoryTest, TestOfferDtls) { - f1_.set_secure(cricket::SEC_ENABLED); - f1_.set_certificate(cert1_); std::string digest_alg; ASSERT_TRUE( cert1_->GetSSLCertificate().GetSignatureDigestAlgorithm(&digest_alg)); std::unique_ptr<TransportDescription> desc = f1_.CreateOffer(TransportOptions(), NULL, &ice_credentials_); CheckDesc(desc.get(), "", "", "", digest_alg); - // Ensure it also works with SEC_REQUIRED. - f1_.set_secure(cricket::SEC_REQUIRED); - desc = f1_.CreateOffer(TransportOptions(), NULL, &ice_credentials_); - CheckDesc(desc.get(), "", "", "", digest_alg); } // Test generating an offer with DTLS fails with no identity. TEST_F(TransportDescriptionFactoryTest, TestOfferDtlsWithNoIdentity) { - f1_.set_secure(cricket::SEC_ENABLED); + f1_.set_certificate(nullptr); std::unique_ptr<TransportDescription> desc = f1_.CreateOffer(TransportOptions(), NULL, &ice_credentials_); ASSERT_TRUE(desc.get() == NULL); @@ -201,8 +203,6 @@ TEST_F(TransportDescriptionFactoryTest, TestOfferDtlsWithNoIdentity) { // Test updating an offer with DTLS to pick ICE. // The ICE credentials should stay the same in the new offer. TEST_F(TransportDescriptionFactoryTest, TestOfferDtlsReofferDtls) { - f1_.set_secure(cricket::SEC_ENABLED); - f1_.set_certificate(cert1_); std::string digest_alg; ASSERT_TRUE( cert1_->GetSSLCertificate().GetSignatureDigestAlgorithm(&digest_alg)); @@ -215,19 +215,25 @@ TEST_F(TransportDescriptionFactoryTest, TestOfferDtlsReofferDtls) { } TEST_F(TransportDescriptionFactoryTest, TestAnswerDefault) { + std::string digest_alg; + ASSERT_TRUE( + cert1_->GetSSLCertificate().GetSignatureDigestAlgorithm(&digest_alg)); std::unique_ptr<TransportDescription> offer = f1_.CreateOffer(TransportOptions(), NULL, &ice_credentials_); ASSERT_TRUE(offer.get() != NULL); std::unique_ptr<TransportDescription> desc = f2_.CreateAnswer( offer.get(), TransportOptions(), true, NULL, &ice_credentials_); - CheckDesc(desc.get(), "", "", "", ""); + CheckDesc(desc.get(), "", "", "", digest_alg); desc = f2_.CreateAnswer(offer.get(), TransportOptions(), true, NULL, &ice_credentials_); - CheckDesc(desc.get(), "", "", "", ""); + CheckDesc(desc.get(), "", "", "", digest_alg); } // Test that we can update an answer properly; ICE credentials shouldn't change. TEST_F(TransportDescriptionFactoryTest, TestReanswer) { + std::string digest_alg; + ASSERT_TRUE( + cert1_->GetSSLCertificate().GetSignatureDigestAlgorithm(&digest_alg)); std::unique_ptr<TransportDescription> offer = f1_.CreateOffer(TransportOptions(), NULL, &ice_credentials_); ASSERT_TRUE(offer.get() != NULL); @@ -237,13 +243,13 @@ TEST_F(TransportDescriptionFactoryTest, TestReanswer) { std::unique_ptr<TransportDescription> desc = f2_.CreateAnswer( offer.get(), TransportOptions(), true, old_desc.get(), &ice_credentials_); ASSERT_TRUE(desc.get() != NULL); - CheckDesc(desc.get(), "", old_desc->ice_ufrag, old_desc->ice_pwd, ""); + CheckDesc(desc.get(), "", old_desc->ice_ufrag, old_desc->ice_pwd, digest_alg); } // Test that we handle answering an offer with DTLS with no DTLS. TEST_F(TransportDescriptionFactoryTest, TestAnswerDtlsToNoDtls) { - f1_.set_secure(cricket::SEC_ENABLED); - f1_.set_certificate(cert1_); + f2_.SetInsecureForTesting(); + f2_.set_certificate(nullptr); std::unique_ptr<TransportDescription> offer = f1_.CreateOffer(TransportOptions(), NULL, &ice_credentials_); ASSERT_TRUE(offer.get() != NULL); @@ -255,28 +261,25 @@ TEST_F(TransportDescriptionFactoryTest, TestAnswerDtlsToNoDtls) { // Test that we handle answering an offer without DTLS if we have DTLS enabled, // but fail if we require DTLS. TEST_F(TransportDescriptionFactoryTest, TestAnswerNoDtlsToDtls) { - f2_.set_secure(cricket::SEC_ENABLED); - f2_.set_certificate(cert2_); + f1_.SetInsecureForTesting(); + f1_.set_certificate(nullptr); std::unique_ptr<TransportDescription> offer = f1_.CreateOffer(TransportOptions(), NULL, &ice_credentials_); ASSERT_TRUE(offer.get() != NULL); + // Normal case. std::unique_ptr<TransportDescription> desc = f2_.CreateAnswer( offer.get(), TransportOptions(), true, NULL, &ice_credentials_); - CheckDesc(desc.get(), "", "", "", ""); - f2_.set_secure(cricket::SEC_REQUIRED); + ASSERT_TRUE(desc.get() == NULL); + // Insecure case. + f2_.SetInsecureForTesting(); desc = f2_.CreateAnswer(offer.get(), TransportOptions(), true, NULL, &ice_credentials_); - ASSERT_TRUE(desc.get() == NULL); + CheckDesc(desc.get(), "", "", "", ""); } -// Test that we handle answering an DTLS offer with DTLS, both if we have -// DTLS enabled and required. +// Test that we handle answering an DTLS offer with DTLS, +// even if we don't require DTLS. TEST_F(TransportDescriptionFactoryTest, TestAnswerDtlsToDtls) { - f1_.set_secure(cricket::SEC_ENABLED); - f1_.set_certificate(cert1_); - - f2_.set_secure(cricket::SEC_ENABLED); - f2_.set_certificate(cert2_); // f2_ produces the answer that is being checked in this test, so the // answer must contain fingerprint lines with cert2_'s digest algorithm. std::string digest_alg2; @@ -289,7 +292,8 @@ TEST_F(TransportDescriptionFactoryTest, TestAnswerDtlsToDtls) { std::unique_ptr<TransportDescription> desc = f2_.CreateAnswer( offer.get(), TransportOptions(), true, NULL, &ice_credentials_); CheckDesc(desc.get(), "", "", "", digest_alg2); - f2_.set_secure(cricket::SEC_REQUIRED); + + f2_.SetInsecureForTesting(); desc = f2_.CreateAnswer(offer.get(), TransportOptions(), true, NULL, &ice_credentials_); CheckDesc(desc.get(), "", "", "", digest_alg2); @@ -325,6 +329,7 @@ TEST_F(TransportDescriptionFactoryTest, AddsTrickleIceOption) { cricket::TransportOptions options; std::unique_ptr<TransportDescription> offer = f1_.CreateOffer(options, nullptr, &ice_credentials_); + ASSERT_THAT(offer, NotNull()); EXPECT_TRUE(offer->HasOption("trickle")); std::unique_ptr<TransportDescription> answer = f2_.CreateAnswer(offer.get(), options, true, nullptr, &ice_credentials_); @@ -359,11 +364,6 @@ TEST_F(TransportDescriptionFactoryTest, CreateAnswerIceCredentialsIterator) { } TEST_F(TransportDescriptionFactoryTest, CreateAnswerToDtlsActpassOffer) { - f1_.set_secure(cricket::SEC_ENABLED); - f1_.set_certificate(cert1_); - - f2_.set_secure(cricket::SEC_ENABLED); - f2_.set_certificate(cert2_); cricket::TransportOptions options; std::unique_ptr<TransportDescription> offer = f1_.CreateOffer(options, nullptr, &ice_credentials_); @@ -374,11 +374,6 @@ TEST_F(TransportDescriptionFactoryTest, CreateAnswerToDtlsActpassOffer) { } TEST_F(TransportDescriptionFactoryTest, CreateAnswerToDtlsActiveOffer) { - f1_.set_secure(cricket::SEC_ENABLED); - f1_.set_certificate(cert1_); - - f2_.set_secure(cricket::SEC_ENABLED); - f2_.set_certificate(cert2_); cricket::TransportOptions options; std::unique_ptr<TransportDescription> offer = f1_.CreateOffer(options, nullptr, &ice_credentials_); @@ -390,11 +385,6 @@ TEST_F(TransportDescriptionFactoryTest, CreateAnswerToDtlsActiveOffer) { } TEST_F(TransportDescriptionFactoryTest, CreateAnswerToDtlsPassiveOffer) { - f1_.set_secure(cricket::SEC_ENABLED); - f1_.set_certificate(cert1_); - - f2_.set_secure(cricket::SEC_ENABLED); - f2_.set_certificate(cert2_); cricket::TransportOptions options; std::unique_ptr<TransportDescription> offer = f1_.CreateOffer(options, nullptr, &ice_credentials_); |