| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "webrtc/p2p/base/constants.h" | 14 #include "webrtc/p2p/base/constants.h" |
| 15 #include "webrtc/p2p/base/transportdescription.h" | 15 #include "webrtc/p2p/base/transportdescription.h" |
| 16 #include "webrtc/p2p/base/transportdescriptionfactory.h" | 16 #include "webrtc/p2p/base/transportdescriptionfactory.h" |
| 17 #include "webrtc/base/fakesslidentity.h" | 17 #include "webrtc/base/fakesslidentity.h" |
| 18 #include "webrtc/base/gunit.h" | 18 #include "webrtc/base/gunit.h" |
| 19 #include "webrtc/base/ssladapter.h" | 19 #include "webrtc/base/ssladapter.h" |
| 20 | 20 |
| 21 using rtc::scoped_ptr; | 21 using rtc::scoped_ptr; |
| 22 using cricket::TransportDescriptionFactory; | 22 using cricket::TransportDescriptionFactory; |
| 23 using cricket::TransportDescription; | 23 using cricket::TransportDescription; |
| 24 using cricket::TransportOptions; | 24 using cricket::TransportOptions; |
| 25 | 25 |
| 26 class TransportDescriptionFactoryTest : public testing::Test { | 26 class TransportDescriptionFactoryTest : public testing::Test { |
| 27 public: | 27 public: |
| 28 TransportDescriptionFactoryTest() | 28 TransportDescriptionFactoryTest() |
| 29 : id1_(new rtc::FakeSSLIdentity("User1")), | 29 : cert1_(rtc::RTCCertificate::Create(scoped_ptr<rtc::SSLIdentity>( |
| 30 id2_(new rtc::FakeSSLIdentity("User2")) { | 30 new rtc::FakeSSLIdentity("User1")).Pass())), |
| 31 cert2_(rtc::RTCCertificate::Create(scoped_ptr<rtc::SSLIdentity>( |
| 32 new rtc::FakeSSLIdentity("User2")).Pass())) { |
| 31 } | 33 } |
| 32 | 34 |
| 33 void CheckDesc(const TransportDescription* desc, | 35 void CheckDesc(const TransportDescription* desc, |
| 34 const std::string& opt, const std::string& ice_ufrag, | 36 const std::string& opt, const std::string& ice_ufrag, |
| 35 const std::string& ice_pwd, const std::string& dtls_alg) { | 37 const std::string& ice_pwd, const std::string& dtls_alg) { |
| 36 ASSERT_TRUE(desc != NULL); | 38 ASSERT_TRUE(desc != NULL); |
| 37 EXPECT_EQ(!opt.empty(), desc->HasOption(opt)); | 39 EXPECT_EQ(!opt.empty(), desc->HasOption(opt)); |
| 38 if (ice_ufrag.empty() && ice_pwd.empty()) { | 40 if (ice_ufrag.empty() && ice_pwd.empty()) { |
| 39 EXPECT_EQ(static_cast<size_t>(cricket::ICE_UFRAG_LENGTH), | 41 EXPECT_EQ(static_cast<size_t>(cricket::ICE_UFRAG_LENGTH), |
| 40 desc->ice_ufrag.size()); | 42 desc->ice_ufrag.size()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 54 } | 56 } |
| 55 | 57 |
| 56 // This test ice restart by doing two offer answer exchanges. On the second | 58 // This test ice restart by doing two offer answer exchanges. On the second |
| 57 // exchange ice is restarted. The test verifies that the ufrag and password | 59 // exchange ice is restarted. The test verifies that the ufrag and password |
| 58 // in the offer and answer is changed. | 60 // in the offer and answer is changed. |
| 59 // If |dtls| is true, the test verifies that the finger print is not changed. | 61 // If |dtls| is true, the test verifies that the finger print is not changed. |
| 60 void TestIceRestart(bool dtls) { | 62 void TestIceRestart(bool dtls) { |
| 61 if (dtls) { | 63 if (dtls) { |
| 62 f1_.set_secure(cricket::SEC_ENABLED); | 64 f1_.set_secure(cricket::SEC_ENABLED); |
| 63 f2_.set_secure(cricket::SEC_ENABLED); | 65 f2_.set_secure(cricket::SEC_ENABLED); |
| 64 f1_.set_identity(id1_.get()); | 66 f1_.set_certificate(cert1_); |
| 65 f2_.set_identity(id2_.get()); | 67 f2_.set_certificate(cert2_); |
| 66 } else { | 68 } else { |
| 67 f1_.set_secure(cricket::SEC_DISABLED); | 69 f1_.set_secure(cricket::SEC_DISABLED); |
| 68 f2_.set_secure(cricket::SEC_DISABLED); | 70 f2_.set_secure(cricket::SEC_DISABLED); |
| 69 } | 71 } |
| 70 | 72 |
| 71 cricket::TransportOptions options; | 73 cricket::TransportOptions options; |
| 72 // The initial offer / answer exchange. | 74 // The initial offer / answer exchange. |
| 73 rtc::scoped_ptr<TransportDescription> offer(f1_.CreateOffer( | 75 rtc::scoped_ptr<TransportDescription> offer(f1_.CreateOffer( |
| 74 options, NULL)); | 76 options, NULL)); |
| 75 rtc::scoped_ptr<TransportDescription> answer( | 77 rtc::scoped_ptr<TransportDescription> answer( |
| (...skipping 30 matching lines...) Expand all Loading... |
| 106 EXPECT_FALSE( | 108 EXPECT_FALSE( |
| 107 org_desc->identity_fingerprint->GetRfc4572Fingerprint().empty()); | 109 org_desc->identity_fingerprint->GetRfc4572Fingerprint().empty()); |
| 108 EXPECT_EQ(org_desc->identity_fingerprint->GetRfc4572Fingerprint(), | 110 EXPECT_EQ(org_desc->identity_fingerprint->GetRfc4572Fingerprint(), |
| 109 restart_desc->identity_fingerprint->GetRfc4572Fingerprint()); | 111 restart_desc->identity_fingerprint->GetRfc4572Fingerprint()); |
| 110 } | 112 } |
| 111 } | 113 } |
| 112 | 114 |
| 113 protected: | 115 protected: |
| 114 TransportDescriptionFactory f1_; | 116 TransportDescriptionFactory f1_; |
| 115 TransportDescriptionFactory f2_; | 117 TransportDescriptionFactory f2_; |
| 116 scoped_ptr<rtc::SSLIdentity> id1_; | 118 |
| 117 scoped_ptr<rtc::SSLIdentity> id2_; | 119 rtc::scoped_refptr<rtc::RTCCertificate> cert1_; |
| 120 rtc::scoped_refptr<rtc::RTCCertificate> cert2_; |
| 118 }; | 121 }; |
| 119 | 122 |
| 120 TEST_F(TransportDescriptionFactoryTest, TestOfferDefault) { | 123 TEST_F(TransportDescriptionFactoryTest, TestOfferDefault) { |
| 121 scoped_ptr<TransportDescription> desc(f1_.CreateOffer( | 124 scoped_ptr<TransportDescription> desc(f1_.CreateOffer( |
| 122 TransportOptions(), NULL)); | 125 TransportOptions(), NULL)); |
| 123 CheckDesc(desc.get(), "", "", "", ""); | 126 CheckDesc(desc.get(), "", "", "", ""); |
| 124 } | 127 } |
| 125 | 128 |
| 126 TEST_F(TransportDescriptionFactoryTest, TestOfferDtls) { | 129 TEST_F(TransportDescriptionFactoryTest, TestOfferDtls) { |
| 127 f1_.set_secure(cricket::SEC_ENABLED); | 130 f1_.set_secure(cricket::SEC_ENABLED); |
| 128 f1_.set_identity(id1_.get()); | 131 f1_.set_certificate(cert1_); |
| 129 std::string digest_alg; | 132 std::string digest_alg; |
| 130 ASSERT_TRUE(id1_->certificate().GetSignatureDigestAlgorithm(&digest_alg)); | 133 ASSERT_TRUE(cert1_->ssl_certificate().GetSignatureDigestAlgorithm( |
| 134 &digest_alg)); |
| 131 scoped_ptr<TransportDescription> desc(f1_.CreateOffer( | 135 scoped_ptr<TransportDescription> desc(f1_.CreateOffer( |
| 132 TransportOptions(), NULL)); | 136 TransportOptions(), NULL)); |
| 133 CheckDesc(desc.get(), "", "", "", digest_alg); | 137 CheckDesc(desc.get(), "", "", "", digest_alg); |
| 134 // Ensure it also works with SEC_REQUIRED. | 138 // Ensure it also works with SEC_REQUIRED. |
| 135 f1_.set_secure(cricket::SEC_REQUIRED); | 139 f1_.set_secure(cricket::SEC_REQUIRED); |
| 136 desc.reset(f1_.CreateOffer(TransportOptions(), NULL)); | 140 desc.reset(f1_.CreateOffer(TransportOptions(), NULL)); |
| 137 CheckDesc(desc.get(), "", "", "", digest_alg); | 141 CheckDesc(desc.get(), "", "", "", digest_alg); |
| 138 } | 142 } |
| 139 | 143 |
| 140 // Test generating an offer with DTLS fails with no identity. | 144 // Test generating an offer with DTLS fails with no identity. |
| 141 TEST_F(TransportDescriptionFactoryTest, TestOfferDtlsWithNoIdentity) { | 145 TEST_F(TransportDescriptionFactoryTest, TestOfferDtlsWithNoIdentity) { |
| 142 f1_.set_secure(cricket::SEC_ENABLED); | 146 f1_.set_secure(cricket::SEC_ENABLED); |
| 143 scoped_ptr<TransportDescription> desc(f1_.CreateOffer( | 147 scoped_ptr<TransportDescription> desc(f1_.CreateOffer( |
| 144 TransportOptions(), NULL)); | 148 TransportOptions(), NULL)); |
| 145 ASSERT_TRUE(desc.get() == NULL); | 149 ASSERT_TRUE(desc.get() == NULL); |
| 146 } | 150 } |
| 147 | 151 |
| 148 // Test updating an offer with DTLS to pick ICE. | 152 // Test updating an offer with DTLS to pick ICE. |
| 149 // The ICE credentials should stay the same in the new offer. | 153 // The ICE credentials should stay the same in the new offer. |
| 150 TEST_F(TransportDescriptionFactoryTest, TestOfferDtlsReofferDtls) { | 154 TEST_F(TransportDescriptionFactoryTest, TestOfferDtlsReofferDtls) { |
| 151 f1_.set_secure(cricket::SEC_ENABLED); | 155 f1_.set_secure(cricket::SEC_ENABLED); |
| 152 f1_.set_identity(id1_.get()); | 156 f1_.set_certificate(cert1_); |
| 153 std::string digest_alg; | 157 std::string digest_alg; |
| 154 ASSERT_TRUE(id1_->certificate().GetSignatureDigestAlgorithm(&digest_alg)); | 158 ASSERT_TRUE(cert1_->ssl_certificate().GetSignatureDigestAlgorithm( |
| 159 &digest_alg)); |
| 155 scoped_ptr<TransportDescription> old_desc(f1_.CreateOffer( | 160 scoped_ptr<TransportDescription> old_desc(f1_.CreateOffer( |
| 156 TransportOptions(), NULL)); | 161 TransportOptions(), NULL)); |
| 157 ASSERT_TRUE(old_desc.get() != NULL); | 162 ASSERT_TRUE(old_desc.get() != NULL); |
| 158 scoped_ptr<TransportDescription> desc( | 163 scoped_ptr<TransportDescription> desc( |
| 159 f1_.CreateOffer(TransportOptions(), old_desc.get())); | 164 f1_.CreateOffer(TransportOptions(), old_desc.get())); |
| 160 CheckDesc(desc.get(), "", | 165 CheckDesc(desc.get(), "", |
| 161 old_desc->ice_ufrag, old_desc->ice_pwd, digest_alg); | 166 old_desc->ice_ufrag, old_desc->ice_pwd, digest_alg); |
| 162 } | 167 } |
| 163 | 168 |
| 164 TEST_F(TransportDescriptionFactoryTest, TestAnswerDefault) { | 169 TEST_F(TransportDescriptionFactoryTest, TestAnswerDefault) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 185 f2_.CreateAnswer(offer.get(), TransportOptions(), | 190 f2_.CreateAnswer(offer.get(), TransportOptions(), |
| 186 old_desc.get())); | 191 old_desc.get())); |
| 187 ASSERT_TRUE(desc.get() != NULL); | 192 ASSERT_TRUE(desc.get() != NULL); |
| 188 CheckDesc(desc.get(), "", | 193 CheckDesc(desc.get(), "", |
| 189 old_desc->ice_ufrag, old_desc->ice_pwd, ""); | 194 old_desc->ice_ufrag, old_desc->ice_pwd, ""); |
| 190 } | 195 } |
| 191 | 196 |
| 192 // Test that we handle answering an offer with DTLS with no DTLS. | 197 // Test that we handle answering an offer with DTLS with no DTLS. |
| 193 TEST_F(TransportDescriptionFactoryTest, TestAnswerDtlsToNoDtls) { | 198 TEST_F(TransportDescriptionFactoryTest, TestAnswerDtlsToNoDtls) { |
| 194 f1_.set_secure(cricket::SEC_ENABLED); | 199 f1_.set_secure(cricket::SEC_ENABLED); |
| 195 f1_.set_identity(id1_.get()); | 200 f1_.set_certificate(cert1_); |
| 196 scoped_ptr<TransportDescription> offer( | 201 scoped_ptr<TransportDescription> offer( |
| 197 f1_.CreateOffer(TransportOptions(), NULL)); | 202 f1_.CreateOffer(TransportOptions(), NULL)); |
| 198 ASSERT_TRUE(offer.get() != NULL); | 203 ASSERT_TRUE(offer.get() != NULL); |
| 199 scoped_ptr<TransportDescription> desc( | 204 scoped_ptr<TransportDescription> desc( |
| 200 f2_.CreateAnswer(offer.get(), TransportOptions(), NULL)); | 205 f2_.CreateAnswer(offer.get(), TransportOptions(), NULL)); |
| 201 CheckDesc(desc.get(), "", "", "", ""); | 206 CheckDesc(desc.get(), "", "", "", ""); |
| 202 } | 207 } |
| 203 | 208 |
| 204 // Test that we handle answering an offer without DTLS if we have DTLS enabled, | 209 // Test that we handle answering an offer without DTLS if we have DTLS enabled, |
| 205 // but fail if we require DTLS. | 210 // but fail if we require DTLS. |
| 206 TEST_F(TransportDescriptionFactoryTest, TestAnswerNoDtlsToDtls) { | 211 TEST_F(TransportDescriptionFactoryTest, TestAnswerNoDtlsToDtls) { |
| 207 f2_.set_secure(cricket::SEC_ENABLED); | 212 f2_.set_secure(cricket::SEC_ENABLED); |
| 208 f2_.set_identity(id2_.get()); | 213 f2_.set_certificate(cert2_); |
| 209 scoped_ptr<TransportDescription> offer( | 214 scoped_ptr<TransportDescription> offer( |
| 210 f1_.CreateOffer(TransportOptions(), NULL)); | 215 f1_.CreateOffer(TransportOptions(), NULL)); |
| 211 ASSERT_TRUE(offer.get() != NULL); | 216 ASSERT_TRUE(offer.get() != NULL); |
| 212 scoped_ptr<TransportDescription> desc( | 217 scoped_ptr<TransportDescription> desc( |
| 213 f2_.CreateAnswer(offer.get(), TransportOptions(), NULL)); | 218 f2_.CreateAnswer(offer.get(), TransportOptions(), NULL)); |
| 214 CheckDesc(desc.get(), "", "", "", ""); | 219 CheckDesc(desc.get(), "", "", "", ""); |
| 215 f2_.set_secure(cricket::SEC_REQUIRED); | 220 f2_.set_secure(cricket::SEC_REQUIRED); |
| 216 desc.reset(f2_.CreateAnswer(offer.get(), TransportOptions(), | 221 desc.reset(f2_.CreateAnswer(offer.get(), TransportOptions(), |
| 217 NULL)); | 222 NULL)); |
| 218 ASSERT_TRUE(desc.get() == NULL); | 223 ASSERT_TRUE(desc.get() == NULL); |
| 219 } | 224 } |
| 220 | 225 |
| 221 // Test that we handle answering an DTLS offer with DTLS, both if we have | 226 // Test that we handle answering an DTLS offer with DTLS, both if we have |
| 222 // DTLS enabled and required. | 227 // DTLS enabled and required. |
| 223 TEST_F(TransportDescriptionFactoryTest, TestAnswerDtlsToDtls) { | 228 TEST_F(TransportDescriptionFactoryTest, TestAnswerDtlsToDtls) { |
| 224 f1_.set_secure(cricket::SEC_ENABLED); | 229 f1_.set_secure(cricket::SEC_ENABLED); |
| 225 f1_.set_identity(id1_.get()); | 230 f1_.set_certificate(cert1_); |
| 226 | 231 |
| 227 f2_.set_secure(cricket::SEC_ENABLED); | 232 f2_.set_secure(cricket::SEC_ENABLED); |
| 228 f2_.set_identity(id2_.get()); | 233 f2_.set_certificate(cert2_); |
| 229 // f2_ produces the answer that is being checked in this test, so the | 234 // f2_ produces the answer that is being checked in this test, so the |
| 230 // answer must contain fingerprint lines with id2_'s digest algorithm. | 235 // answer must contain fingerprint lines with cert2_'s digest algorithm. |
| 231 std::string digest_alg2; | 236 std::string digest_alg2; |
| 232 ASSERT_TRUE(id2_->certificate().GetSignatureDigestAlgorithm(&digest_alg2)); | 237 ASSERT_TRUE(cert2_->ssl_certificate().GetSignatureDigestAlgorithm( |
| 238 &digest_alg2)); |
| 233 | 239 |
| 234 scoped_ptr<TransportDescription> offer( | 240 scoped_ptr<TransportDescription> offer( |
| 235 f1_.CreateOffer(TransportOptions(), NULL)); | 241 f1_.CreateOffer(TransportOptions(), NULL)); |
| 236 ASSERT_TRUE(offer.get() != NULL); | 242 ASSERT_TRUE(offer.get() != NULL); |
| 237 scoped_ptr<TransportDescription> desc( | 243 scoped_ptr<TransportDescription> desc( |
| 238 f2_.CreateAnswer(offer.get(), TransportOptions(), NULL)); | 244 f2_.CreateAnswer(offer.get(), TransportOptions(), NULL)); |
| 239 CheckDesc(desc.get(), "", "", "", digest_alg2); | 245 CheckDesc(desc.get(), "", "", "", digest_alg2); |
| 240 f2_.set_secure(cricket::SEC_REQUIRED); | 246 f2_.set_secure(cricket::SEC_REQUIRED); |
| 241 desc.reset(f2_.CreateAnswer(offer.get(), TransportOptions(), | 247 desc.reset(f2_.CreateAnswer(offer.get(), TransportOptions(), |
| 242 NULL)); | 248 NULL)); |
| 243 CheckDesc(desc.get(), "", "", "", digest_alg2); | 249 CheckDesc(desc.get(), "", "", "", digest_alg2); |
| 244 } | 250 } |
| 245 | 251 |
| 246 // Test that ice ufrag and password is changed in an updated offer and answer | 252 // Test that ice ufrag and password is changed in an updated offer and answer |
| 247 // if |TransportDescriptionOptions::ice_restart| is true. | 253 // if |TransportDescriptionOptions::ice_restart| is true. |
| 248 TEST_F(TransportDescriptionFactoryTest, TestIceRestart) { | 254 TEST_F(TransportDescriptionFactoryTest, TestIceRestart) { |
| 249 TestIceRestart(false); | 255 TestIceRestart(false); |
| 250 } | 256 } |
| 251 | 257 |
| 252 // Test that ice ufrag and password is changed in an updated offer and answer | 258 // Test that ice ufrag and password is changed in an updated offer and answer |
| 253 // if |TransportDescriptionOptions::ice_restart| is true and DTLS is enabled. | 259 // if |TransportDescriptionOptions::ice_restart| is true and DTLS is enabled. |
| 254 TEST_F(TransportDescriptionFactoryTest, TestIceRestartWithDtls) { | 260 TEST_F(TransportDescriptionFactoryTest, TestIceRestartWithDtls) { |
| 255 TestIceRestart(true); | 261 TestIceRestart(true); |
| 256 } | 262 } |
| OLD | NEW |