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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 f2_.set_secure(cricket::SEC_ENABLED); | 65 f2_.set_secure(cricket::SEC_ENABLED); |
66 f1_.set_certificate(cert1_); | 66 f1_.set_certificate(cert1_); |
67 f2_.set_certificate(cert2_); | 67 f2_.set_certificate(cert2_); |
68 } else { | 68 } else { |
69 f1_.set_secure(cricket::SEC_DISABLED); | 69 f1_.set_secure(cricket::SEC_DISABLED); |
70 f2_.set_secure(cricket::SEC_DISABLED); | 70 f2_.set_secure(cricket::SEC_DISABLED); |
71 } | 71 } |
72 | 72 |
73 cricket::TransportOptions options; | 73 cricket::TransportOptions options; |
74 // The initial offer / answer exchange. | 74 // The initial offer / answer exchange. |
75 rtc::scoped_ptr<TransportDescription> offer(f1_.CreateOffer( | 75 rtc::scoped_ptr<TransportDescription> offer( |
76 options, NULL)); | 76 f1_.CreateOffer(options, false, NULL)); |
77 rtc::scoped_ptr<TransportDescription> answer( | 77 rtc::scoped_ptr<TransportDescription> answer( |
78 f2_.CreateAnswer(offer.get(), | 78 f2_.CreateAnswer(offer.get(), options, false, NULL)); |
79 options, NULL)); | |
80 | 79 |
81 // Create an updated offer where we restart ice. | 80 // Create an updated offer where we restart ice. |
82 options.ice_restart = true; | 81 rtc::scoped_ptr<TransportDescription> restart_offer( |
83 rtc::scoped_ptr<TransportDescription> restart_offer(f1_.CreateOffer( | 82 f1_.CreateOffer(options, true, offer.get())); |
84 options, offer.get())); | |
85 | 83 |
86 VerifyUfragAndPasswordChanged(dtls, offer.get(), restart_offer.get()); | 84 VerifyUfragAndPasswordChanged(dtls, offer.get(), restart_offer.get()); |
87 | 85 |
88 // Create a new answer. The transport ufrag and password is changed since | 86 // Create a new answer. The transport ufrag and password is changed since |
89 // |options.ice_restart == true| | 87 // |ice_restart == true| |
90 rtc::scoped_ptr<TransportDescription> restart_answer( | 88 rtc::scoped_ptr<TransportDescription> restart_answer( |
91 f2_.CreateAnswer(restart_offer.get(), options, answer.get())); | 89 f2_.CreateAnswer(restart_offer.get(), options, true, answer.get())); |
92 ASSERT_TRUE(restart_answer.get() != NULL); | 90 ASSERT_TRUE(restart_answer.get() != NULL); |
93 | 91 |
94 VerifyUfragAndPasswordChanged(dtls, answer.get(), restart_answer.get()); | 92 VerifyUfragAndPasswordChanged(dtls, answer.get(), restart_answer.get()); |
95 } | 93 } |
96 | 94 |
97 void VerifyUfragAndPasswordChanged(bool dtls, | 95 void VerifyUfragAndPasswordChanged(bool dtls, |
98 const TransportDescription* org_desc, | 96 const TransportDescription* org_desc, |
99 const TransportDescription* restart_desc) { | 97 const TransportDescription* restart_desc) { |
100 EXPECT_NE(org_desc->ice_pwd, restart_desc->ice_pwd); | 98 EXPECT_NE(org_desc->ice_pwd, restart_desc->ice_pwd); |
101 EXPECT_NE(org_desc->ice_ufrag, restart_desc->ice_ufrag); | 99 EXPECT_NE(org_desc->ice_ufrag, restart_desc->ice_ufrag); |
(...skipping 12 matching lines...) Expand all Loading... |
114 | 112 |
115 protected: | 113 protected: |
116 TransportDescriptionFactory f1_; | 114 TransportDescriptionFactory f1_; |
117 TransportDescriptionFactory f2_; | 115 TransportDescriptionFactory f2_; |
118 | 116 |
119 rtc::scoped_refptr<rtc::RTCCertificate> cert1_; | 117 rtc::scoped_refptr<rtc::RTCCertificate> cert1_; |
120 rtc::scoped_refptr<rtc::RTCCertificate> cert2_; | 118 rtc::scoped_refptr<rtc::RTCCertificate> cert2_; |
121 }; | 119 }; |
122 | 120 |
123 TEST_F(TransportDescriptionFactoryTest, TestOfferDefault) { | 121 TEST_F(TransportDescriptionFactoryTest, TestOfferDefault) { |
124 scoped_ptr<TransportDescription> desc(f1_.CreateOffer( | 122 scoped_ptr<TransportDescription> desc( |
125 TransportOptions(), NULL)); | 123 f1_.CreateOffer(TransportOptions(), false, NULL)); |
126 CheckDesc(desc.get(), "", "", "", ""); | 124 CheckDesc(desc.get(), "", "", "", ""); |
127 } | 125 } |
128 | 126 |
129 TEST_F(TransportDescriptionFactoryTest, TestOfferDtls) { | 127 TEST_F(TransportDescriptionFactoryTest, TestOfferDtls) { |
130 f1_.set_secure(cricket::SEC_ENABLED); | 128 f1_.set_secure(cricket::SEC_ENABLED); |
131 f1_.set_certificate(cert1_); | 129 f1_.set_certificate(cert1_); |
132 std::string digest_alg; | 130 std::string digest_alg; |
133 ASSERT_TRUE(cert1_->ssl_certificate().GetSignatureDigestAlgorithm( | 131 ASSERT_TRUE(cert1_->ssl_certificate().GetSignatureDigestAlgorithm( |
134 &digest_alg)); | 132 &digest_alg)); |
135 scoped_ptr<TransportDescription> desc(f1_.CreateOffer( | 133 scoped_ptr<TransportDescription> desc( |
136 TransportOptions(), NULL)); | 134 f1_.CreateOffer(TransportOptions(), false, NULL)); |
137 CheckDesc(desc.get(), "", "", "", digest_alg); | 135 CheckDesc(desc.get(), "", "", "", digest_alg); |
138 // Ensure it also works with SEC_REQUIRED. | 136 // Ensure it also works with SEC_REQUIRED. |
139 f1_.set_secure(cricket::SEC_REQUIRED); | 137 f1_.set_secure(cricket::SEC_REQUIRED); |
140 desc.reset(f1_.CreateOffer(TransportOptions(), NULL)); | 138 desc.reset(f1_.CreateOffer(TransportOptions(), false, NULL)); |
141 CheckDesc(desc.get(), "", "", "", digest_alg); | 139 CheckDesc(desc.get(), "", "", "", digest_alg); |
142 } | 140 } |
143 | 141 |
144 // Test generating an offer with DTLS fails with no identity. | 142 // Test generating an offer with DTLS fails with no identity. |
145 TEST_F(TransportDescriptionFactoryTest, TestOfferDtlsWithNoIdentity) { | 143 TEST_F(TransportDescriptionFactoryTest, TestOfferDtlsWithNoIdentity) { |
146 f1_.set_secure(cricket::SEC_ENABLED); | 144 f1_.set_secure(cricket::SEC_ENABLED); |
147 scoped_ptr<TransportDescription> desc(f1_.CreateOffer( | 145 scoped_ptr<TransportDescription> desc( |
148 TransportOptions(), NULL)); | 146 f1_.CreateOffer(TransportOptions(), false, NULL)); |
149 ASSERT_TRUE(desc.get() == NULL); | 147 ASSERT_TRUE(desc.get() == NULL); |
150 } | 148 } |
151 | 149 |
152 // Test updating an offer with DTLS to pick ICE. | 150 // Test updating an offer with DTLS to pick ICE. |
153 // The ICE credentials should stay the same in the new offer. | 151 // The ICE credentials should stay the same in the new offer. |
154 TEST_F(TransportDescriptionFactoryTest, TestOfferDtlsReofferDtls) { | 152 TEST_F(TransportDescriptionFactoryTest, TestOfferDtlsReofferDtls) { |
155 f1_.set_secure(cricket::SEC_ENABLED); | 153 f1_.set_secure(cricket::SEC_ENABLED); |
156 f1_.set_certificate(cert1_); | 154 f1_.set_certificate(cert1_); |
157 std::string digest_alg; | 155 std::string digest_alg; |
158 ASSERT_TRUE(cert1_->ssl_certificate().GetSignatureDigestAlgorithm( | 156 ASSERT_TRUE(cert1_->ssl_certificate().GetSignatureDigestAlgorithm( |
159 &digest_alg)); | 157 &digest_alg)); |
160 scoped_ptr<TransportDescription> old_desc(f1_.CreateOffer( | 158 scoped_ptr<TransportDescription> old_desc( |
161 TransportOptions(), NULL)); | 159 f1_.CreateOffer(TransportOptions(), false, NULL)); |
162 ASSERT_TRUE(old_desc.get() != NULL); | 160 ASSERT_TRUE(old_desc.get() != NULL); |
163 scoped_ptr<TransportDescription> desc( | 161 scoped_ptr<TransportDescription> desc( |
164 f1_.CreateOffer(TransportOptions(), old_desc.get())); | 162 f1_.CreateOffer(TransportOptions(), false, old_desc.get())); |
165 CheckDesc(desc.get(), "", | 163 CheckDesc(desc.get(), "", |
166 old_desc->ice_ufrag, old_desc->ice_pwd, digest_alg); | 164 old_desc->ice_ufrag, old_desc->ice_pwd, digest_alg); |
167 } | 165 } |
168 | 166 |
169 TEST_F(TransportDescriptionFactoryTest, TestAnswerDefault) { | 167 TEST_F(TransportDescriptionFactoryTest, TestAnswerDefault) { |
170 scoped_ptr<TransportDescription> offer(f1_.CreateOffer( | 168 scoped_ptr<TransportDescription> offer( |
171 TransportOptions(), NULL)); | 169 f1_.CreateOffer(TransportOptions(), false, NULL)); |
172 ASSERT_TRUE(offer.get() != NULL); | 170 ASSERT_TRUE(offer.get() != NULL); |
173 scoped_ptr<TransportDescription> desc(f2_.CreateAnswer( | 171 scoped_ptr<TransportDescription> desc( |
174 offer.get(), TransportOptions(), NULL)); | 172 f2_.CreateAnswer(offer.get(), TransportOptions(), false, NULL)); |
175 CheckDesc(desc.get(), "", "", "", ""); | 173 CheckDesc(desc.get(), "", "", "", ""); |
176 desc.reset(f2_.CreateAnswer(offer.get(), TransportOptions(), | 174 desc.reset(f2_.CreateAnswer(offer.get(), TransportOptions(), false, NULL)); |
177 NULL)); | |
178 CheckDesc(desc.get(), "", "", "", ""); | 175 CheckDesc(desc.get(), "", "", "", ""); |
179 } | 176 } |
180 | 177 |
181 // Test that we can update an answer properly; ICE credentials shouldn't change. | 178 // Test that we can update an answer properly; ICE credentials shouldn't change. |
182 TEST_F(TransportDescriptionFactoryTest, TestReanswer) { | 179 TEST_F(TransportDescriptionFactoryTest, TestReanswer) { |
183 scoped_ptr<TransportDescription> offer( | 180 scoped_ptr<TransportDescription> offer( |
184 f1_.CreateOffer(TransportOptions(), NULL)); | 181 f1_.CreateOffer(TransportOptions(), false, NULL)); |
185 ASSERT_TRUE(offer.get() != NULL); | 182 ASSERT_TRUE(offer.get() != NULL); |
186 scoped_ptr<TransportDescription> old_desc( | 183 scoped_ptr<TransportDescription> old_desc( |
187 f2_.CreateAnswer(offer.get(), TransportOptions(), NULL)); | 184 f2_.CreateAnswer(offer.get(), TransportOptions(), false, NULL)); |
188 ASSERT_TRUE(old_desc.get() != NULL); | 185 ASSERT_TRUE(old_desc.get() != NULL); |
189 scoped_ptr<TransportDescription> desc( | 186 scoped_ptr<TransportDescription> desc( |
190 f2_.CreateAnswer(offer.get(), TransportOptions(), | 187 f2_.CreateAnswer(offer.get(), TransportOptions(), false, old_desc.get())); |
191 old_desc.get())); | |
192 ASSERT_TRUE(desc.get() != NULL); | 188 ASSERT_TRUE(desc.get() != NULL); |
193 CheckDesc(desc.get(), "", | 189 CheckDesc(desc.get(), "", |
194 old_desc->ice_ufrag, old_desc->ice_pwd, ""); | 190 old_desc->ice_ufrag, old_desc->ice_pwd, ""); |
195 } | 191 } |
196 | 192 |
197 // Test that we handle answering an offer with DTLS with no DTLS. | 193 // Test that we handle answering an offer with DTLS with no DTLS. |
198 TEST_F(TransportDescriptionFactoryTest, TestAnswerDtlsToNoDtls) { | 194 TEST_F(TransportDescriptionFactoryTest, TestAnswerDtlsToNoDtls) { |
199 f1_.set_secure(cricket::SEC_ENABLED); | 195 f1_.set_secure(cricket::SEC_ENABLED); |
200 f1_.set_certificate(cert1_); | 196 f1_.set_certificate(cert1_); |
201 scoped_ptr<TransportDescription> offer( | 197 scoped_ptr<TransportDescription> offer( |
202 f1_.CreateOffer(TransportOptions(), NULL)); | 198 f1_.CreateOffer(TransportOptions(), false, NULL)); |
203 ASSERT_TRUE(offer.get() != NULL); | 199 ASSERT_TRUE(offer.get() != NULL); |
204 scoped_ptr<TransportDescription> desc( | 200 scoped_ptr<TransportDescription> desc( |
205 f2_.CreateAnswer(offer.get(), TransportOptions(), NULL)); | 201 f2_.CreateAnswer(offer.get(), TransportOptions(), false, NULL)); |
206 CheckDesc(desc.get(), "", "", "", ""); | 202 CheckDesc(desc.get(), "", "", "", ""); |
207 } | 203 } |
208 | 204 |
209 // Test that we handle answering an offer without DTLS if we have DTLS enabled, | 205 // Test that we handle answering an offer without DTLS if we have DTLS enabled, |
210 // but fail if we require DTLS. | 206 // but fail if we require DTLS. |
211 TEST_F(TransportDescriptionFactoryTest, TestAnswerNoDtlsToDtls) { | 207 TEST_F(TransportDescriptionFactoryTest, TestAnswerNoDtlsToDtls) { |
212 f2_.set_secure(cricket::SEC_ENABLED); | 208 f2_.set_secure(cricket::SEC_ENABLED); |
213 f2_.set_certificate(cert2_); | 209 f2_.set_certificate(cert2_); |
214 scoped_ptr<TransportDescription> offer( | 210 scoped_ptr<TransportDescription> offer( |
215 f1_.CreateOffer(TransportOptions(), NULL)); | 211 f1_.CreateOffer(TransportOptions(), false, NULL)); |
216 ASSERT_TRUE(offer.get() != NULL); | 212 ASSERT_TRUE(offer.get() != NULL); |
217 scoped_ptr<TransportDescription> desc( | 213 scoped_ptr<TransportDescription> desc( |
218 f2_.CreateAnswer(offer.get(), TransportOptions(), NULL)); | 214 f2_.CreateAnswer(offer.get(), TransportOptions(), false, NULL)); |
219 CheckDesc(desc.get(), "", "", "", ""); | 215 CheckDesc(desc.get(), "", "", "", ""); |
220 f2_.set_secure(cricket::SEC_REQUIRED); | 216 f2_.set_secure(cricket::SEC_REQUIRED); |
221 desc.reset(f2_.CreateAnswer(offer.get(), TransportOptions(), | 217 desc.reset(f2_.CreateAnswer(offer.get(), TransportOptions(), false, NULL)); |
222 NULL)); | |
223 ASSERT_TRUE(desc.get() == NULL); | 218 ASSERT_TRUE(desc.get() == NULL); |
224 } | 219 } |
225 | 220 |
226 // Test that we handle answering an DTLS offer with DTLS, both if we have | 221 // Test that we handle answering an DTLS offer with DTLS, both if we have |
227 // DTLS enabled and required. | 222 // DTLS enabled and required. |
228 TEST_F(TransportDescriptionFactoryTest, TestAnswerDtlsToDtls) { | 223 TEST_F(TransportDescriptionFactoryTest, TestAnswerDtlsToDtls) { |
229 f1_.set_secure(cricket::SEC_ENABLED); | 224 f1_.set_secure(cricket::SEC_ENABLED); |
230 f1_.set_certificate(cert1_); | 225 f1_.set_certificate(cert1_); |
231 | 226 |
232 f2_.set_secure(cricket::SEC_ENABLED); | 227 f2_.set_secure(cricket::SEC_ENABLED); |
233 f2_.set_certificate(cert2_); | 228 f2_.set_certificate(cert2_); |
234 // f2_ produces the answer that is being checked in this test, so the | 229 // f2_ produces the answer that is being checked in this test, so the |
235 // answer must contain fingerprint lines with cert2_'s digest algorithm. | 230 // answer must contain fingerprint lines with cert2_'s digest algorithm. |
236 std::string digest_alg2; | 231 std::string digest_alg2; |
237 ASSERT_TRUE(cert2_->ssl_certificate().GetSignatureDigestAlgorithm( | 232 ASSERT_TRUE(cert2_->ssl_certificate().GetSignatureDigestAlgorithm( |
238 &digest_alg2)); | 233 &digest_alg2)); |
239 | 234 |
240 scoped_ptr<TransportDescription> offer( | 235 scoped_ptr<TransportDescription> offer( |
241 f1_.CreateOffer(TransportOptions(), NULL)); | 236 f1_.CreateOffer(TransportOptions(), false, NULL)); |
242 ASSERT_TRUE(offer.get() != NULL); | 237 ASSERT_TRUE(offer.get() != NULL); |
243 scoped_ptr<TransportDescription> desc( | 238 scoped_ptr<TransportDescription> desc( |
244 f2_.CreateAnswer(offer.get(), TransportOptions(), NULL)); | 239 f2_.CreateAnswer(offer.get(), TransportOptions(), false, NULL)); |
245 CheckDesc(desc.get(), "", "", "", digest_alg2); | 240 CheckDesc(desc.get(), "", "", "", digest_alg2); |
246 f2_.set_secure(cricket::SEC_REQUIRED); | 241 f2_.set_secure(cricket::SEC_REQUIRED); |
247 desc.reset(f2_.CreateAnswer(offer.get(), TransportOptions(), | 242 desc.reset(f2_.CreateAnswer(offer.get(), TransportOptions(), false, NULL)); |
248 NULL)); | |
249 CheckDesc(desc.get(), "", "", "", digest_alg2); | 243 CheckDesc(desc.get(), "", "", "", digest_alg2); |
250 } | 244 } |
251 | 245 |
252 // Test that ice ufrag and password is changed in an updated offer and answer | 246 // Test that ice ufrag and password is changed in an updated offer and answer |
253 // if |TransportDescriptionOptions::ice_restart| is true. | 247 // if |TransportDescriptionOptions::ice_restart| is true. |
254 TEST_F(TransportDescriptionFactoryTest, TestIceRestart) { | 248 TEST_F(TransportDescriptionFactoryTest, TestIceRestart) { |
255 TestIceRestart(false); | 249 TestIceRestart(false); |
256 } | 250 } |
257 | 251 |
258 // 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 |
259 // if |TransportDescriptionOptions::ice_restart| is true and DTLS is enabled. | 253 // if |TransportDescriptionOptions::ice_restart| is true and DTLS is enabled. |
260 TEST_F(TransportDescriptionFactoryTest, TestIceRestartWithDtls) { | 254 TEST_F(TransportDescriptionFactoryTest, TestIceRestartWithDtls) { |
261 TestIceRestart(true); | 255 TestIceRestart(true); |
262 } | 256 } |
OLD | NEW |