| 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 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 // This test ice restart by doing two offer answer exchanges. On the second | 57 // This test ice restart by doing two offer answer exchanges. On the second |
| 58 // exchange ice is restarted. The test verifies that the ufrag and password | 58 // exchange ice is restarted. The test verifies that the ufrag and password |
| 59 // in the offer and answer is changed. | 59 // in the offer and answer is changed. |
| 60 // If |dtls| is true, the test verifies that the finger print is not changed. | 60 // If |dtls| is true, the test verifies that the finger print is not changed. |
| 61 void TestIceRestart(bool dtls) { | 61 void TestIceRestart(bool dtls) { |
| 62 SetDtls(dtls); | 62 SetDtls(dtls); |
| 63 cricket::TransportOptions options; | 63 cricket::TransportOptions options; |
| 64 // The initial offer / answer exchange. | 64 // The initial offer / answer exchange. |
| 65 std::unique_ptr<TransportDescription> offer(f1_.CreateOffer(options, NULL)); | 65 std::unique_ptr<TransportDescription> offer(f1_.CreateOffer(options, NULL)); |
| 66 std::unique_ptr<TransportDescription> answer( | 66 std::unique_ptr<TransportDescription> answer( |
| 67 f2_.CreateAnswer(offer.get(), options, NULL)); | 67 f2_.CreateAnswer(offer.get(), options, NULL, false)); |
| 68 | 68 |
| 69 // Create an updated offer where we restart ice. | 69 // Create an updated offer where we restart ice. |
| 70 options.ice_restart = true; | 70 options.ice_restart = true; |
| 71 std::unique_ptr<TransportDescription> restart_offer( | 71 std::unique_ptr<TransportDescription> restart_offer( |
| 72 f1_.CreateOffer(options, offer.get())); | 72 f1_.CreateOffer(options, offer.get())); |
| 73 | 73 |
| 74 VerifyUfragAndPasswordChanged(dtls, offer.get(), restart_offer.get()); | 74 VerifyUfragAndPasswordChanged(dtls, offer.get(), restart_offer.get()); |
| 75 | 75 |
| 76 // Create a new answer. The transport ufrag and password is changed since | 76 // Create a new answer. The transport ufrag and password is changed since |
| 77 // |options.ice_restart == true| | 77 // |options.ice_restart == true| |
| 78 std::unique_ptr<TransportDescription> restart_answer( | 78 std::unique_ptr<TransportDescription> restart_answer( |
| 79 f2_.CreateAnswer(restart_offer.get(), options, answer.get())); | 79 f2_.CreateAnswer(restart_offer.get(), options, answer.get(), false)); |
| 80 ASSERT_TRUE(restart_answer.get() != NULL); | 80 ASSERT_TRUE(restart_answer.get() != NULL); |
| 81 | 81 |
| 82 VerifyUfragAndPasswordChanged(dtls, answer.get(), restart_answer.get()); | 82 VerifyUfragAndPasswordChanged(dtls, answer.get(), restart_answer.get()); |
| 83 } | 83 } |
| 84 | 84 |
| 85 void VerifyUfragAndPasswordChanged(bool dtls, | 85 void VerifyUfragAndPasswordChanged(bool dtls, |
| 86 const TransportDescription* org_desc, | 86 const TransportDescription* org_desc, |
| 87 const TransportDescription* restart_desc) { | 87 const TransportDescription* restart_desc) { |
| 88 EXPECT_NE(org_desc->ice_pwd, restart_desc->ice_pwd); | 88 EXPECT_NE(org_desc->ice_pwd, restart_desc->ice_pwd); |
| 89 EXPECT_NE(org_desc->ice_ufrag, restart_desc->ice_ufrag); | 89 EXPECT_NE(org_desc->ice_ufrag, restart_desc->ice_ufrag); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 101 } | 101 } |
| 102 | 102 |
| 103 void TestIceRenomination(bool dtls) { | 103 void TestIceRenomination(bool dtls) { |
| 104 SetDtls(dtls); | 104 SetDtls(dtls); |
| 105 | 105 |
| 106 cricket::TransportOptions options; | 106 cricket::TransportOptions options; |
| 107 // The initial offer / answer exchange. | 107 // The initial offer / answer exchange. |
| 108 std::unique_ptr<TransportDescription> offer( | 108 std::unique_ptr<TransportDescription> offer( |
| 109 f1_.CreateOffer(options, nullptr)); | 109 f1_.CreateOffer(options, nullptr)); |
| 110 std::unique_ptr<TransportDescription> answer( | 110 std::unique_ptr<TransportDescription> answer( |
| 111 f2_.CreateAnswer(offer.get(), options, nullptr)); | 111 f2_.CreateAnswer(offer.get(), options, nullptr, false)); |
| 112 VerifyRenomination(offer.get(), false); | 112 VerifyRenomination(offer.get(), false); |
| 113 VerifyRenomination(answer.get(), false); | 113 VerifyRenomination(answer.get(), false); |
| 114 | 114 |
| 115 options.enable_ice_renomination = true; | 115 options.enable_ice_renomination = true; |
| 116 std::unique_ptr<TransportDescription> renomination_offer( | 116 std::unique_ptr<TransportDescription> renomination_offer( |
| 117 f1_.CreateOffer(options, offer.get())); | 117 f1_.CreateOffer(options, offer.get())); |
| 118 VerifyRenomination(renomination_offer.get(), true); | 118 VerifyRenomination(renomination_offer.get(), true); |
| 119 | 119 |
| 120 std::unique_ptr<TransportDescription> renomination_answer( | 120 std::unique_ptr<TransportDescription> renomination_answer(f2_.CreateAnswer( |
| 121 f2_.CreateAnswer(renomination_offer.get(), options, answer.get())); | 121 renomination_offer.get(), options, answer.get(), false)); |
| 122 VerifyRenomination(renomination_answer.get(), true); | 122 VerifyRenomination(renomination_answer.get(), true); |
| 123 } | 123 } |
| 124 | 124 |
| 125 protected: | 125 protected: |
| 126 void VerifyRenomination(TransportDescription* desc, | 126 void VerifyRenomination(TransportDescription* desc, |
| 127 bool renomination_expected) { | 127 bool renomination_expected) { |
| 128 ASSERT_TRUE(desc != nullptr); | 128 ASSERT_TRUE(desc != nullptr); |
| 129 std::vector<std::string>& options = desc->transport_options; | 129 std::vector<std::string>& options = desc->transport_options; |
| 130 auto iter = std::find(options.begin(), options.end(), | 130 auto iter = std::find(options.begin(), options.end(), |
| 131 cricket::ICE_RENOMINATION_STR); | 131 cricket::ICE_RENOMINATION_STR); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 f1_.CreateOffer(TransportOptions(), old_desc.get())); | 195 f1_.CreateOffer(TransportOptions(), old_desc.get())); |
| 196 CheckDesc(desc.get(), "", | 196 CheckDesc(desc.get(), "", |
| 197 old_desc->ice_ufrag, old_desc->ice_pwd, digest_alg); | 197 old_desc->ice_ufrag, old_desc->ice_pwd, digest_alg); |
| 198 } | 198 } |
| 199 | 199 |
| 200 TEST_F(TransportDescriptionFactoryTest, TestAnswerDefault) { | 200 TEST_F(TransportDescriptionFactoryTest, TestAnswerDefault) { |
| 201 std::unique_ptr<TransportDescription> offer( | 201 std::unique_ptr<TransportDescription> offer( |
| 202 f1_.CreateOffer(TransportOptions(), NULL)); | 202 f1_.CreateOffer(TransportOptions(), NULL)); |
| 203 ASSERT_TRUE(offer.get() != NULL); | 203 ASSERT_TRUE(offer.get() != NULL); |
| 204 std::unique_ptr<TransportDescription> desc( | 204 std::unique_ptr<TransportDescription> desc( |
| 205 f2_.CreateAnswer(offer.get(), TransportOptions(), NULL)); | 205 f2_.CreateAnswer(offer.get(), TransportOptions(), NULL, false)); |
| 206 CheckDesc(desc.get(), "", "", "", ""); | 206 CheckDesc(desc.get(), "", "", "", ""); |
| 207 desc.reset(f2_.CreateAnswer(offer.get(), TransportOptions(), | 207 desc.reset(f2_.CreateAnswer(offer.get(), TransportOptions(), NULL, false)); |
| 208 NULL)); | |
| 209 CheckDesc(desc.get(), "", "", "", ""); | 208 CheckDesc(desc.get(), "", "", "", ""); |
| 210 } | 209 } |
| 211 | 210 |
| 212 // Test that we can update an answer properly; ICE credentials shouldn't change. | 211 // Test that we can update an answer properly; ICE credentials shouldn't change. |
| 213 TEST_F(TransportDescriptionFactoryTest, TestReanswer) { | 212 TEST_F(TransportDescriptionFactoryTest, TestReanswer) { |
| 214 std::unique_ptr<TransportDescription> offer( | 213 std::unique_ptr<TransportDescription> offer( |
| 215 f1_.CreateOffer(TransportOptions(), NULL)); | 214 f1_.CreateOffer(TransportOptions(), NULL)); |
| 216 ASSERT_TRUE(offer.get() != NULL); | 215 ASSERT_TRUE(offer.get() != NULL); |
| 217 std::unique_ptr<TransportDescription> old_desc( | 216 std::unique_ptr<TransportDescription> old_desc( |
| 218 f2_.CreateAnswer(offer.get(), TransportOptions(), NULL)); | 217 f2_.CreateAnswer(offer.get(), TransportOptions(), NULL, false)); |
| 219 ASSERT_TRUE(old_desc.get() != NULL); | 218 ASSERT_TRUE(old_desc.get() != NULL); |
| 220 std::unique_ptr<TransportDescription> desc( | 219 std::unique_ptr<TransportDescription> desc( |
| 221 f2_.CreateAnswer(offer.get(), TransportOptions(), old_desc.get())); | 220 f2_.CreateAnswer(offer.get(), TransportOptions(), old_desc.get(), false)); |
| 222 ASSERT_TRUE(desc.get() != NULL); | 221 ASSERT_TRUE(desc.get() != NULL); |
| 223 CheckDesc(desc.get(), "", | 222 CheckDesc(desc.get(), "", |
| 224 old_desc->ice_ufrag, old_desc->ice_pwd, ""); | 223 old_desc->ice_ufrag, old_desc->ice_pwd, ""); |
| 225 } | 224 } |
| 226 | 225 |
| 227 // Test that we handle answering an offer with DTLS with no DTLS. | 226 // Test that we handle answering an offer with DTLS with no DTLS. |
| 228 TEST_F(TransportDescriptionFactoryTest, TestAnswerDtlsToNoDtls) { | 227 TEST_F(TransportDescriptionFactoryTest, TestAnswerDtlsToNoDtls) { |
| 229 f1_.set_secure(cricket::SEC_ENABLED); | 228 f1_.set_secure(cricket::SEC_ENABLED); |
| 230 f1_.set_certificate(cert1_); | 229 f1_.set_certificate(cert1_); |
| 231 std::unique_ptr<TransportDescription> offer( | 230 std::unique_ptr<TransportDescription> offer( |
| 232 f1_.CreateOffer(TransportOptions(), NULL)); | 231 f1_.CreateOffer(TransportOptions(), NULL)); |
| 233 ASSERT_TRUE(offer.get() != NULL); | 232 ASSERT_TRUE(offer.get() != NULL); |
| 234 std::unique_ptr<TransportDescription> desc( | 233 std::unique_ptr<TransportDescription> desc( |
| 235 f2_.CreateAnswer(offer.get(), TransportOptions(), NULL)); | 234 f2_.CreateAnswer(offer.get(), TransportOptions(), NULL, false)); |
| 236 CheckDesc(desc.get(), "", "", "", ""); | 235 CheckDesc(desc.get(), "", "", "", ""); |
| 237 } | 236 } |
| 238 | 237 |
| 239 // Test that we handle answering an offer without DTLS if we have DTLS enabled, | 238 // Test that we handle answering an offer without DTLS if we have DTLS enabled, |
| 240 // but fail if we require DTLS. | 239 // but fail if we require DTLS. |
| 241 TEST_F(TransportDescriptionFactoryTest, TestAnswerNoDtlsToDtls) { | 240 TEST_F(TransportDescriptionFactoryTest, TestAnswerNoDtlsToDtls) { |
| 242 f2_.set_secure(cricket::SEC_ENABLED); | 241 f2_.set_secure(cricket::SEC_ENABLED); |
| 243 f2_.set_certificate(cert2_); | 242 f2_.set_certificate(cert2_); |
| 244 std::unique_ptr<TransportDescription> offer( | 243 std::unique_ptr<TransportDescription> offer( |
| 245 f1_.CreateOffer(TransportOptions(), NULL)); | 244 f1_.CreateOffer(TransportOptions(), NULL)); |
| 246 ASSERT_TRUE(offer.get() != NULL); | 245 ASSERT_TRUE(offer.get() != NULL); |
| 247 std::unique_ptr<TransportDescription> desc( | 246 std::unique_ptr<TransportDescription> desc( |
| 248 f2_.CreateAnswer(offer.get(), TransportOptions(), NULL)); | 247 f2_.CreateAnswer(offer.get(), TransportOptions(), NULL, false)); |
| 249 CheckDesc(desc.get(), "", "", "", ""); | 248 CheckDesc(desc.get(), "", "", "", ""); |
| 250 f2_.set_secure(cricket::SEC_REQUIRED); | 249 f2_.set_secure(cricket::SEC_REQUIRED); |
| 251 desc.reset(f2_.CreateAnswer(offer.get(), TransportOptions(), | 250 desc.reset(f2_.CreateAnswer(offer.get(), TransportOptions(), NULL, false)); |
| 252 NULL)); | |
| 253 ASSERT_TRUE(desc.get() == NULL); | 251 ASSERT_TRUE(desc.get() == NULL); |
| 254 } | 252 } |
| 255 | 253 |
| 256 // Test that we handle answering an DTLS offer with DTLS, both if we have | 254 // Test that we handle answering an DTLS offer with DTLS, both if we have |
| 257 // DTLS enabled and required. | 255 // DTLS enabled and required. |
| 258 TEST_F(TransportDescriptionFactoryTest, TestAnswerDtlsToDtls) { | 256 TEST_F(TransportDescriptionFactoryTest, TestAnswerDtlsToDtls) { |
| 259 f1_.set_secure(cricket::SEC_ENABLED); | 257 f1_.set_secure(cricket::SEC_ENABLED); |
| 260 f1_.set_certificate(cert1_); | 258 f1_.set_certificate(cert1_); |
| 261 | 259 |
| 262 f2_.set_secure(cricket::SEC_ENABLED); | 260 f2_.set_secure(cricket::SEC_ENABLED); |
| 263 f2_.set_certificate(cert2_); | 261 f2_.set_certificate(cert2_); |
| 264 // f2_ produces the answer that is being checked in this test, so the | 262 // f2_ produces the answer that is being checked in this test, so the |
| 265 // answer must contain fingerprint lines with cert2_'s digest algorithm. | 263 // answer must contain fingerprint lines with cert2_'s digest algorithm. |
| 266 std::string digest_alg2; | 264 std::string digest_alg2; |
| 267 ASSERT_TRUE(cert2_->ssl_certificate().GetSignatureDigestAlgorithm( | 265 ASSERT_TRUE(cert2_->ssl_certificate().GetSignatureDigestAlgorithm( |
| 268 &digest_alg2)); | 266 &digest_alg2)); |
| 269 | 267 |
| 270 std::unique_ptr<TransportDescription> offer( | 268 std::unique_ptr<TransportDescription> offer( |
| 271 f1_.CreateOffer(TransportOptions(), NULL)); | 269 f1_.CreateOffer(TransportOptions(), NULL)); |
| 272 ASSERT_TRUE(offer.get() != NULL); | 270 ASSERT_TRUE(offer.get() != NULL); |
| 273 std::unique_ptr<TransportDescription> desc( | 271 std::unique_ptr<TransportDescription> desc( |
| 274 f2_.CreateAnswer(offer.get(), TransportOptions(), NULL)); | 272 f2_.CreateAnswer(offer.get(), TransportOptions(), NULL, false)); |
| 275 CheckDesc(desc.get(), "", "", "", digest_alg2); | 273 CheckDesc(desc.get(), "", "", "", digest_alg2); |
| 276 f2_.set_secure(cricket::SEC_REQUIRED); | 274 f2_.set_secure(cricket::SEC_REQUIRED); |
| 277 desc.reset(f2_.CreateAnswer(offer.get(), TransportOptions(), | 275 desc.reset(f2_.CreateAnswer(offer.get(), TransportOptions(), NULL, false)); |
| 278 NULL)); | |
| 279 CheckDesc(desc.get(), "", "", "", digest_alg2); | 276 CheckDesc(desc.get(), "", "", "", digest_alg2); |
| 280 } | 277 } |
| 281 | 278 |
| 282 // Test that ice ufrag and password is changed in an updated offer and answer | 279 // Test that ice ufrag and password is changed in an updated offer and answer |
| 283 // if |TransportDescriptionOptions::ice_restart| is true. | 280 // if |TransportDescriptionOptions::ice_restart| is true. |
| 284 TEST_F(TransportDescriptionFactoryTest, TestIceRestart) { | 281 TEST_F(TransportDescriptionFactoryTest, TestIceRestart) { |
| 285 TestIceRestart(false); | 282 TestIceRestart(false); |
| 286 } | 283 } |
| 287 | 284 |
| 288 // Test that ice ufrag and password is changed in an updated offer and answer | 285 // Test that ice ufrag and password is changed in an updated offer and answer |
| 289 // if |TransportDescriptionOptions::ice_restart| is true and DTLS is enabled. | 286 // if |TransportDescriptionOptions::ice_restart| is true and DTLS is enabled. |
| 290 TEST_F(TransportDescriptionFactoryTest, TestIceRestartWithDtls) { | 287 TEST_F(TransportDescriptionFactoryTest, TestIceRestartWithDtls) { |
| 291 TestIceRestart(true); | 288 TestIceRestart(true); |
| 292 } | 289 } |
| 293 | 290 |
| 294 // Test that ice renomination is set in an updated offer and answer | 291 // Test that ice renomination is set in an updated offer and answer |
| 295 // if |TransportDescriptionOptions::enable_ice_renomination| is true. | 292 // if |TransportDescriptionOptions::enable_ice_renomination| is true. |
| 296 TEST_F(TransportDescriptionFactoryTest, TestIceRenomination) { | 293 TEST_F(TransportDescriptionFactoryTest, TestIceRenomination) { |
| 297 TestIceRenomination(false); | 294 TestIceRenomination(false); |
| 298 } | 295 } |
| 299 | 296 |
| 300 // Test that ice renomination is set in an updated offer and answer | 297 // Test that ice renomination is set in an updated offer and answer |
| 301 // if |TransportDescriptionOptions::enable_ice_renomination| is true and DTLS | 298 // if |TransportDescriptionOptions::enable_ice_renomination| is true and DTLS |
| 302 // is enabled. | 299 // is enabled. |
| 303 TEST_F(TransportDescriptionFactoryTest, TestIceRenominationWithDtls) { | 300 TEST_F(TransportDescriptionFactoryTest, TestIceRenominationWithDtls) { |
| 304 TestIceRenomination(true); | 301 TestIceRenomination(true); |
| 305 } | 302 } |
| OLD | NEW |