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