Parameterize PeerConnection crypto tests for Unified Plan

Bug: webrtc:8765
Change-Id: I7ece0ecb38f033d31428bde0ff592000f8934024
Reviewed-on: https://webrtc-review.googlesource.com/40502
Commit-Queue: Steve Anton <steveanton@webrtc.org>
Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21703}
This commit is contained in:
Steve Anton 2018-01-19 14:59:54 -08:00 committed by Commit Bot
parent dbd780992d
commit 71182f4ded

View File

@ -32,12 +32,14 @@ using ::testing::Combine;
constexpr int kGenerateCertTimeout = 1000;
class PeerConnectionCryptoUnitTest : public ::testing::Test {
class PeerConnectionCryptoBaseTest : public ::testing::Test {
protected:
typedef std::unique_ptr<PeerConnectionWrapper> WrapperPtr;
PeerConnectionCryptoUnitTest()
: vss_(new rtc::VirtualSocketServer()), main_(vss_.get()) {
explicit PeerConnectionCryptoBaseTest(SdpSemantics sdp_semantics)
: vss_(new rtc::VirtualSocketServer()),
main_(vss_.get()),
sdp_semantics_(sdp_semantics) {
#ifdef WEBRTC_ANDROID
InitializeAndroidObjects();
#endif
@ -61,8 +63,10 @@ class PeerConnectionCryptoUnitTest : public ::testing::Test {
auto fake_port_allocator = rtc::MakeUnique<cricket::FakePortAllocator>(
rtc::Thread::Current(), nullptr);
auto observer = rtc::MakeUnique<MockPeerConnectionObserver>();
RTCConfiguration modified_config = config;
modified_config.sdp_semantics = sdp_semantics_;
auto pc = pc_factory_->CreatePeerConnection(
config, std::move(fake_port_allocator), std::move(cert_gen),
modified_config, std::move(fake_port_allocator), std::move(cert_gen),
observer.get());
if (!pc) {
return nullptr;
@ -107,6 +111,7 @@ class PeerConnectionCryptoUnitTest : public ::testing::Test {
std::unique_ptr<rtc::VirtualSocketServer> vss_;
rtc::AutoSocketServerThread main_;
rtc::scoped_refptr<PeerConnectionFactoryInterface> pc_factory_;
const SdpSemantics sdp_semantics_;
};
SdpContentPredicate HaveDtlsFingerprint() {
@ -143,6 +148,13 @@ SdpContentPredicate HaveSdesGcmCryptos(size_t num_crypto_suites) {
};
}
class PeerConnectionCryptoTest
: public PeerConnectionCryptoBaseTest,
public ::testing::WithParamInterface<SdpSemantics> {
protected:
PeerConnectionCryptoTest() : PeerConnectionCryptoBaseTest(GetParam()) {}
};
SdpContentMutator RemoveSdesCryptos() {
return [](cricket::ContentInfo* content, cricket::TransportInfo* transport) {
content->media_description()->set_cryptos({});
@ -157,7 +169,7 @@ SdpContentMutator RemoveDtlsFingerprint() {
// When DTLS is enabled, the SDP offer/answer should have a DTLS fingerprint and
// no SDES cryptos.
TEST_F(PeerConnectionCryptoUnitTest, CorrectCryptoInOfferWhenDtlsEnabled) {
TEST_P(PeerConnectionCryptoTest, CorrectCryptoInOfferWhenDtlsEnabled) {
RTCConfiguration config;
config.enable_dtls_srtp.emplace(true);
auto caller = CreatePeerConnectionWithAudioVideo(config);
@ -171,7 +183,7 @@ TEST_F(PeerConnectionCryptoUnitTest, CorrectCryptoInOfferWhenDtlsEnabled) {
EXPECT_TRUE(SdpContentsAll(HaveProtocol(cricket::kMediaProtocolDtlsSavpf),
offer->description()));
}
TEST_F(PeerConnectionCryptoUnitTest, CorrectCryptoInAnswerWhenDtlsEnabled) {
TEST_P(PeerConnectionCryptoTest, CorrectCryptoInAnswerWhenDtlsEnabled) {
RTCConfiguration config;
config.enable_dtls_srtp.emplace(true);
auto caller = CreatePeerConnectionWithAudioVideo(config);
@ -190,7 +202,7 @@ TEST_F(PeerConnectionCryptoUnitTest, CorrectCryptoInAnswerWhenDtlsEnabled) {
// When DTLS is disabled, the SDP offer/answer should include SDES cryptos and
// should not have a DTLS fingerprint.
TEST_F(PeerConnectionCryptoUnitTest, CorrectCryptoInOfferWhenDtlsDisabled) {
TEST_P(PeerConnectionCryptoTest, CorrectCryptoInOfferWhenDtlsDisabled) {
RTCConfiguration config;
config.enable_dtls_srtp.emplace(false);
auto caller = CreatePeerConnectionWithAudioVideo(config);
@ -204,7 +216,7 @@ TEST_F(PeerConnectionCryptoUnitTest, CorrectCryptoInOfferWhenDtlsDisabled) {
EXPECT_TRUE(SdpContentsAll(HaveProtocol(cricket::kMediaProtocolSavpf),
offer->description()));
}
TEST_F(PeerConnectionCryptoUnitTest, CorrectCryptoInAnswerWhenDtlsDisabled) {
TEST_P(PeerConnectionCryptoTest, CorrectCryptoInAnswerWhenDtlsDisabled) {
RTCConfiguration config;
config.enable_dtls_srtp.emplace(false);
auto caller = CreatePeerConnectionWithAudioVideo(config);
@ -223,8 +235,7 @@ TEST_F(PeerConnectionCryptoUnitTest, CorrectCryptoInAnswerWhenDtlsDisabled) {
// When encryption is disabled, the SDP offer/answer should have neither a DTLS
// fingerprint nor any SDES crypto options.
TEST_F(PeerConnectionCryptoUnitTest,
CorrectCryptoInOfferWhenEncryptionDisabled) {
TEST_P(PeerConnectionCryptoTest, CorrectCryptoInOfferWhenEncryptionDisabled) {
PeerConnectionFactoryInterface::Options options;
options.disable_encryption = true;
pc_factory_->SetOptions(options);
@ -242,8 +253,7 @@ TEST_F(PeerConnectionCryptoUnitTest,
EXPECT_TRUE(SdpContentsAll(HaveProtocol(cricket::kMediaProtocolAvpf),
offer->description()));
}
TEST_F(PeerConnectionCryptoUnitTest,
CorrectCryptoInAnswerWhenEncryptionDisabled) {
TEST_P(PeerConnectionCryptoTest, CorrectCryptoInAnswerWhenEncryptionDisabled) {
PeerConnectionFactoryInterface::Options options;
options.disable_encryption = true;
pc_factory_->SetOptions(options);
@ -268,7 +278,7 @@ TEST_F(PeerConnectionCryptoUnitTest,
// should have the correct ciphers in the SDES crypto options.
// With GCM cipher suites enabled, there will be 3 cryptos in the offer and 1
// in the answer.
TEST_F(PeerConnectionCryptoUnitTest, CorrectCryptoInOfferWithSdesAndGcm) {
TEST_P(PeerConnectionCryptoTest, CorrectCryptoInOfferWithSdesAndGcm) {
PeerConnectionFactoryInterface::Options options;
options.crypto_options.enable_gcm_crypto_suites = true;
pc_factory_->SetOptions(options);
@ -283,7 +293,7 @@ TEST_F(PeerConnectionCryptoUnitTest, CorrectCryptoInOfferWithSdesAndGcm) {
ASSERT_FALSE(offer->description()->contents().empty());
EXPECT_TRUE(SdpContentsAll(HaveSdesGcmCryptos(3), offer->description()));
}
TEST_F(PeerConnectionCryptoUnitTest, CorrectCryptoInAnswerWithSdesAndGcm) {
TEST_P(PeerConnectionCryptoTest, CorrectCryptoInAnswerWithSdesAndGcm) {
PeerConnectionFactoryInterface::Options options;
options.crypto_options.enable_gcm_crypto_suites = true;
pc_factory_->SetOptions(options);
@ -301,7 +311,7 @@ TEST_F(PeerConnectionCryptoUnitTest, CorrectCryptoInAnswerWithSdesAndGcm) {
EXPECT_TRUE(SdpContentsAll(HaveSdesGcmCryptos(1), answer->description()));
}
TEST_F(PeerConnectionCryptoUnitTest, CanSetSdesGcmRemoteOfferAndLocalAnswer) {
TEST_P(PeerConnectionCryptoTest, CanSetSdesGcmRemoteOfferAndLocalAnswer) {
PeerConnectionFactoryInterface::Options options;
options.crypto_options.enable_gcm_crypto_suites = true;
pc_factory_->SetOptions(options);
@ -323,7 +333,7 @@ TEST_F(PeerConnectionCryptoUnitTest, CanSetSdesGcmRemoteOfferAndLocalAnswer) {
// The following group tests that two PeerConnections can successfully exchange
// an offer/answer when DTLS is off and that they will refuse any offer/answer
// applied locally/remotely if it does not include SDES cryptos.
TEST_F(PeerConnectionCryptoUnitTest, ExchangeOfferAnswerWhenSdesOn) {
TEST_P(PeerConnectionCryptoTest, ExchangeOfferAnswerWhenSdesOn) {
RTCConfiguration config;
config.enable_dtls_srtp.emplace(false);
auto caller = CreatePeerConnectionWithAudioVideo(config);
@ -337,8 +347,7 @@ TEST_F(PeerConnectionCryptoUnitTest, ExchangeOfferAnswerWhenSdesOn) {
ASSERT_TRUE(answer);
ASSERT_TRUE(caller->SetRemoteDescription(std::move(answer)));
}
TEST_F(PeerConnectionCryptoUnitTest,
FailToSetLocalOfferWithNoCryptosWhenSdesOn) {
TEST_P(PeerConnectionCryptoTest, FailToSetLocalOfferWithNoCryptosWhenSdesOn) {
RTCConfiguration config;
config.enable_dtls_srtp.emplace(false);
auto caller = CreatePeerConnectionWithAudioVideo(config);
@ -348,8 +357,7 @@ TEST_F(PeerConnectionCryptoUnitTest,
EXPECT_FALSE(caller->SetLocalDescription(std::move(offer)));
}
TEST_F(PeerConnectionCryptoUnitTest,
FailToSetRemoteOfferWithNoCryptosWhenSdesOn) {
TEST_P(PeerConnectionCryptoTest, FailToSetRemoteOfferWithNoCryptosWhenSdesOn) {
RTCConfiguration config;
config.enable_dtls_srtp.emplace(false);
auto caller = CreatePeerConnectionWithAudioVideo(config);
@ -360,8 +368,7 @@ TEST_F(PeerConnectionCryptoUnitTest,
EXPECT_FALSE(callee->SetRemoteDescription(std::move(offer)));
}
TEST_F(PeerConnectionCryptoUnitTest,
FailToSetLocalAnswerWithNoCryptosWhenSdesOn) {
TEST_P(PeerConnectionCryptoTest, FailToSetLocalAnswerWithNoCryptosWhenSdesOn) {
RTCConfiguration config;
config.enable_dtls_srtp.emplace(false);
auto caller = CreatePeerConnectionWithAudioVideo(config);
@ -373,8 +380,7 @@ TEST_F(PeerConnectionCryptoUnitTest,
EXPECT_FALSE(callee->SetLocalDescription(std::move(answer)));
}
TEST_F(PeerConnectionCryptoUnitTest,
FailToSetRemoteAnswerWithNoCryptosWhenSdesOn) {
TEST_P(PeerConnectionCryptoTest, FailToSetRemoteAnswerWithNoCryptosWhenSdesOn) {
RTCConfiguration config;
config.enable_dtls_srtp.emplace(false);
auto caller = CreatePeerConnectionWithAudioVideo(config);
@ -390,7 +396,7 @@ TEST_F(PeerConnectionCryptoUnitTest,
// The following group tests that two PeerConnections can successfully exchange
// an offer/answer when DTLS is on and that they will refuse any offer/answer
// applied locally/remotely if it does not include a DTLS fingerprint.
TEST_F(PeerConnectionCryptoUnitTest, ExchangeOfferAnswerWhenDtlsOn) {
TEST_P(PeerConnectionCryptoTest, ExchangeOfferAnswerWhenDtlsOn) {
RTCConfiguration config;
config.enable_dtls_srtp.emplace(true);
auto caller = CreatePeerConnectionWithAudioVideo(config);
@ -404,7 +410,7 @@ TEST_F(PeerConnectionCryptoUnitTest, ExchangeOfferAnswerWhenDtlsOn) {
ASSERT_TRUE(answer);
ASSERT_TRUE(caller->SetRemoteDescription(std::move(answer)));
}
TEST_F(PeerConnectionCryptoUnitTest,
TEST_P(PeerConnectionCryptoTest,
FailToSetLocalOfferWithNoFingerprintWhenDtlsOn) {
RTCConfiguration config;
config.enable_dtls_srtp.emplace(true);
@ -415,7 +421,7 @@ TEST_F(PeerConnectionCryptoUnitTest,
EXPECT_FALSE(caller->SetLocalDescription(std::move(offer)));
}
TEST_F(PeerConnectionCryptoUnitTest,
TEST_P(PeerConnectionCryptoTest,
FailToSetRemoteOfferWithNoFingerprintWhenDtlsOn) {
RTCConfiguration config;
config.enable_dtls_srtp.emplace(true);
@ -427,7 +433,7 @@ TEST_F(PeerConnectionCryptoUnitTest,
EXPECT_FALSE(callee->SetRemoteDescription(std::move(offer)));
}
TEST_F(PeerConnectionCryptoUnitTest,
TEST_P(PeerConnectionCryptoTest,
FailToSetLocalAnswerWithNoFingerprintWhenDtlsOn) {
RTCConfiguration config;
config.enable_dtls_srtp.emplace(true);
@ -438,7 +444,7 @@ TEST_F(PeerConnectionCryptoUnitTest,
auto answer = callee->CreateAnswer();
SdpContentsForEach(RemoveDtlsFingerprint(), answer->description());
}
TEST_F(PeerConnectionCryptoUnitTest,
TEST_P(PeerConnectionCryptoTest,
FailToSetRemoteAnswerWithNoFingerprintWhenDtlsOn) {
RTCConfiguration config;
config.enable_dtls_srtp.emplace(true);
@ -453,7 +459,7 @@ TEST_F(PeerConnectionCryptoUnitTest,
}
// Test that an offer/answer can be exchanged when encryption is disabled.
TEST_F(PeerConnectionCryptoUnitTest, ExchangeOfferAnswerWhenNoEncryption) {
TEST_P(PeerConnectionCryptoTest, ExchangeOfferAnswerWhenNoEncryption) {
PeerConnectionFactoryInterface::Options options;
options.disable_encryption = true;
pc_factory_->SetOptions(options);
@ -474,7 +480,7 @@ TEST_F(PeerConnectionCryptoUnitTest, ExchangeOfferAnswerWhenNoEncryption) {
// Tests that a DTLS call can be established when the certificate is specified
// in the PeerConnection config and no certificate generator is specified.
TEST_F(PeerConnectionCryptoUnitTest,
TEST_P(PeerConnectionCryptoTest,
ExchangeOfferAnswerWhenDtlsCertificateInConfig) {
RTCConfiguration caller_config;
caller_config.enable_dtls_srtp.emplace(true);
@ -530,16 +536,20 @@ std::ostream& operator<<(std::ostream& out, CertGenResult value) {
}
}
class PeerConnectionCryptoDtlsCertGenUnitTest
: public PeerConnectionCryptoUnitTest,
public ::testing::WithParamInterface<
::testing::tuple<SdpType, CertGenTime, CertGenResult, size_t>> {
class PeerConnectionCryptoDtlsCertGenTest
: public PeerConnectionCryptoBaseTest,
public ::testing::WithParamInterface<std::tuple<SdpSemantics,
SdpType,
CertGenTime,
CertGenResult,
size_t>> {
protected:
PeerConnectionCryptoDtlsCertGenUnitTest() {
sdp_type_ = ::testing::get<0>(GetParam());
cert_gen_time_ = ::testing::get<1>(GetParam());
cert_gen_result_ = ::testing::get<2>(GetParam());
concurrent_calls_ = ::testing::get<3>(GetParam());
PeerConnectionCryptoDtlsCertGenTest()
: PeerConnectionCryptoBaseTest(std::get<0>(GetParam())) {
sdp_type_ = std::get<1>(GetParam());
cert_gen_time_ = std::get<2>(GetParam());
cert_gen_result_ = std::get<3>(GetParam());
concurrent_calls_ = std::get<4>(GetParam());
}
SdpType sdp_type_;
@ -548,7 +558,7 @@ class PeerConnectionCryptoDtlsCertGenUnitTest
size_t concurrent_calls_;
};
TEST_P(PeerConnectionCryptoDtlsCertGenUnitTest, TestCertificateGeneration) {
TEST_P(PeerConnectionCryptoDtlsCertGenTest, TestCertificateGeneration) {
RTCConfiguration config;
config.enable_dtls_srtp.emplace(true);
auto owned_fake_certificate_generator =
@ -600,9 +610,10 @@ TEST_P(PeerConnectionCryptoDtlsCertGenUnitTest, TestCertificateGeneration) {
}
INSTANTIATE_TEST_CASE_P(
PeerConnectionCryptoUnitTest,
PeerConnectionCryptoDtlsCertGenUnitTest,
Combine(Values(SdpType::kOffer, SdpType::kAnswer),
PeerConnectionCryptoTest,
PeerConnectionCryptoDtlsCertGenTest,
Combine(Values(SdpSemantics::kPlanB, SdpSemantics::kUnifiedPlan),
Values(SdpType::kOffer, SdpType::kAnswer),
Values(CertGenTime::kBefore, CertGenTime::kDuring),
Values(CertGenResult::kSucceed, CertGenResult::kFail),
Values(1, 3)));
@ -610,7 +621,7 @@ INSTANTIATE_TEST_CASE_P(
// Test that we can create and set an answer correctly when different
// SSL roles have been negotiated for different transports.
// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525
TEST_F(PeerConnectionCryptoUnitTest, CreateAnswerWithDifferentSslRoles) {
TEST_P(PeerConnectionCryptoTest, CreateAnswerWithDifferentSslRoles) {
auto caller = CreatePeerConnectionWithAudioVideo();
auto callee = CreatePeerConnectionWithAudioVideo();
@ -661,4 +672,9 @@ TEST_F(PeerConnectionCryptoUnitTest, CreateAnswerWithDifferentSslRoles) {
ASSERT_TRUE(callee->SetRemoteDescription(std::move(answer)));
}
INSTANTIATE_TEST_CASE_P(PeerConnectionCryptoTest,
PeerConnectionCryptoTest,
Values(SdpSemantics::kPlanB,
SdpSemantics::kUnifiedPlan));
} // namespace webrtc