@@ -144,19 +144,17 @@ class TransportDescriptionFactoryTest : public ::testing::Test {
144
144
}
145
145
146
146
protected:
147
- void SetDtls (bool f1_dtls, bool f2_dtls) {
148
- if (f1_dtls) {
147
+ void SetDtls (bool dtls) {
148
+ if (dtls) {
149
+ f1_.set_secure (cricket::SEC_ENABLED);
150
+ f2_.set_secure (cricket::SEC_ENABLED);
149
151
f1_.set_certificate (cert1_);
150
- } else {
151
- f1_.set_certificate (nullptr );
152
- }
153
- if (f2_dtls) {
154
152
f2_.set_certificate (cert2_);
155
153
} else {
156
- f2_.set_certificate (nullptr );
154
+ f1_.set_secure (cricket::SEC_DISABLED);
155
+ f2_.set_secure (cricket::SEC_DISABLED);
157
156
}
158
157
}
159
- void SetDtls (bool dtls) { SetDtls (dtls, dtls); }
160
158
161
159
cricket::IceCredentialsIterator ice_credentials_;
162
160
TransportDescriptionFactory f1_;
@@ -173,19 +171,33 @@ TEST_F(TransportDescriptionFactoryTest, TestOfferDefault) {
173
171
}
174
172
175
173
TEST_F (TransportDescriptionFactoryTest, TestOfferDtls) {
176
- SetDtls (true );
174
+ f1_.set_secure (cricket::SEC_ENABLED);
175
+ f1_.set_certificate (cert1_);
177
176
std::string digest_alg;
178
177
ASSERT_TRUE (
179
178
cert1_->GetSSLCertificate ().GetSignatureDigestAlgorithm (&digest_alg));
180
179
std::unique_ptr<TransportDescription> desc =
181
180
f1_.CreateOffer (TransportOptions (), NULL , &ice_credentials_);
182
181
CheckDesc (desc.get (), " " , " " , " " , digest_alg);
182
+ // Ensure it also works with SEC_REQUIRED.
183
+ f1_.set_secure (cricket::SEC_REQUIRED);
184
+ desc = f1_.CreateOffer (TransportOptions (), NULL , &ice_credentials_);
185
+ CheckDesc (desc.get (), " " , " " , " " , digest_alg);
186
+ }
187
+
188
+ // Test generating an offer with DTLS fails with no identity.
189
+ TEST_F (TransportDescriptionFactoryTest, TestOfferDtlsWithNoIdentity) {
190
+ f1_.set_secure (cricket::SEC_ENABLED);
191
+ std::unique_ptr<TransportDescription> desc =
192
+ f1_.CreateOffer (TransportOptions (), NULL , &ice_credentials_);
193
+ ASSERT_TRUE (desc.get () == NULL );
183
194
}
184
195
185
196
// Test updating an offer with DTLS to pick ICE.
186
197
// The ICE credentials should stay the same in the new offer.
187
198
TEST_F (TransportDescriptionFactoryTest, TestOfferDtlsReofferDtls) {
188
- SetDtls (true );
199
+ f1_.set_secure (cricket::SEC_ENABLED);
200
+ f1_.set_certificate (cert1_);
189
201
std::string digest_alg;
190
202
ASSERT_TRUE (
191
203
cert1_->GetSSLCertificate ().GetSignatureDigestAlgorithm (&digest_alg));
@@ -225,7 +237,8 @@ TEST_F(TransportDescriptionFactoryTest, TestReanswer) {
225
237
226
238
// Test that we handle answering an offer with DTLS with no DTLS.
227
239
TEST_F (TransportDescriptionFactoryTest, TestAnswerDtlsToNoDtls) {
228
- SetDtls (true , false );
240
+ f1_.set_secure (cricket::SEC_ENABLED);
241
+ f1_.set_certificate (cert1_);
229
242
std::unique_ptr<TransportDescription> offer =
230
243
f1_.CreateOffer (TransportOptions (), NULL , &ice_credentials_);
231
244
ASSERT_TRUE (offer.get () != NULL );
@@ -234,20 +247,31 @@ TEST_F(TransportDescriptionFactoryTest, TestAnswerDtlsToNoDtls) {
234
247
CheckDesc (desc.get (), " " , " " , " " , " " );
235
248
}
236
249
237
- // Test that we reject answering an offer without DTLS if we have DTLS enabled.
250
+ // Test that we handle answering an offer without DTLS if we have DTLS enabled,
251
+ // but fail if we require DTLS.
238
252
TEST_F (TransportDescriptionFactoryTest, TestAnswerNoDtlsToDtls) {
239
- SetDtls (false , true );
253
+ f2_.set_secure (cricket::SEC_ENABLED);
254
+ f2_.set_certificate (cert2_);
240
255
std::unique_ptr<TransportDescription> offer =
241
256
f1_.CreateOffer (TransportOptions (), NULL , &ice_credentials_);
242
257
ASSERT_TRUE (offer.get () != NULL );
243
258
std::unique_ptr<TransportDescription> desc = f2_.CreateAnswer (
244
259
offer.get (), TransportOptions (), true , NULL , &ice_credentials_);
245
- ASSERT_FALSE (desc);
260
+ CheckDesc (desc.get (), " " , " " , " " , " " );
261
+ f2_.set_secure (cricket::SEC_REQUIRED);
262
+ desc = f2_.CreateAnswer (offer.get (), TransportOptions (), true , NULL ,
263
+ &ice_credentials_);
264
+ ASSERT_TRUE (desc.get () == NULL );
246
265
}
247
266
248
- // Test that we handle answering an DTLS offer with DTLS.
267
+ // Test that we handle answering an DTLS offer with DTLS, both if we have
268
+ // DTLS enabled and required.
249
269
TEST_F (TransportDescriptionFactoryTest, TestAnswerDtlsToDtls) {
250
- SetDtls (true , true );
270
+ f1_.set_secure (cricket::SEC_ENABLED);
271
+ f1_.set_certificate (cert1_);
272
+
273
+ f2_.set_secure (cricket::SEC_ENABLED);
274
+ f2_.set_certificate (cert2_);
251
275
// f2_ produces the answer that is being checked in this test, so the
252
276
// answer must contain fingerprint lines with cert2_'s digest algorithm.
253
277
std::string digest_alg2;
@@ -260,6 +284,10 @@ TEST_F(TransportDescriptionFactoryTest, TestAnswerDtlsToDtls) {
260
284
std::unique_ptr<TransportDescription> desc = f2_.CreateAnswer (
261
285
offer.get (), TransportOptions (), true , NULL , &ice_credentials_);
262
286
CheckDesc (desc.get (), " " , " " , " " , digest_alg2);
287
+ f2_.set_secure (cricket::SEC_REQUIRED);
288
+ desc = f2_.CreateAnswer (offer.get (), TransportOptions (), true , NULL ,
289
+ &ice_credentials_);
290
+ CheckDesc (desc.get (), " " , " " , " " , digest_alg2);
263
291
}
264
292
265
293
// Test that ice ufrag and password is changed in an updated offer and answer
@@ -326,7 +354,11 @@ TEST_F(TransportDescriptionFactoryTest, CreateAnswerIceCredentialsIterator) {
326
354
}
327
355
328
356
TEST_F (TransportDescriptionFactoryTest, CreateAnswerToDtlsActpassOffer) {
329
- SetDtls (true );
357
+ f1_.set_secure (cricket::SEC_ENABLED);
358
+ f1_.set_certificate (cert1_);
359
+
360
+ f2_.set_secure (cricket::SEC_ENABLED);
361
+ f2_.set_certificate (cert2_);
330
362
cricket::TransportOptions options;
331
363
std::unique_ptr<TransportDescription> offer =
332
364
f1_.CreateOffer (options, nullptr , &ice_credentials_);
@@ -337,7 +369,11 @@ TEST_F(TransportDescriptionFactoryTest, CreateAnswerToDtlsActpassOffer) {
337
369
}
338
370
339
371
TEST_F (TransportDescriptionFactoryTest, CreateAnswerToDtlsActiveOffer) {
340
- SetDtls (true );
372
+ f1_.set_secure (cricket::SEC_ENABLED);
373
+ f1_.set_certificate (cert1_);
374
+
375
+ f2_.set_secure (cricket::SEC_ENABLED);
376
+ f2_.set_certificate (cert2_);
341
377
cricket::TransportOptions options;
342
378
std::unique_ptr<TransportDescription> offer =
343
379
f1_.CreateOffer (options, nullptr , &ice_credentials_);
@@ -349,7 +385,11 @@ TEST_F(TransportDescriptionFactoryTest, CreateAnswerToDtlsActiveOffer) {
349
385
}
350
386
351
387
TEST_F (TransportDescriptionFactoryTest, CreateAnswerToDtlsPassiveOffer) {
352
- SetDtls (true );
388
+ f1_.set_secure (cricket::SEC_ENABLED);
389
+ f1_.set_certificate (cert1_);
390
+
391
+ f2_.set_secure (cricket::SEC_ENABLED);
392
+ f2_.set_certificate (cert2_);
353
393
cricket::TransportOptions options;
354
394
std::unique_ptr<TransportDescription> offer =
355
395
f1_.CreateOffer (options, nullptr , &ice_credentials_);
0 commit comments