|
1 | 1 |
|
2 | 2 | #include "bridge/ApiRequestHandler.h" |
3 | 3 | #include "bridge/Mixer.h" |
| 4 | +#include "bridge/TransportDescription.h" |
4 | 5 | #include "mocks/EngineMixerSpy.h" |
5 | 6 | #include "mocks/MixerManagerSpy.h" |
6 | 7 | #include "mocks/RtcTransportMock.h" |
@@ -384,3 +385,104 @@ TEST_F(ApiRequestHandlerTest, allocateEndpointWithVideoFieldWhenVideoIsEnableSho |
384 | 385 | EXPECT_NE(responseJson.end(), responseJson.find("video")); |
385 | 386 | EXPECT_NE(responseJson.end(), responseJson.find("data")); |
386 | 387 | } |
| 388 | + |
| 389 | +TEST_F(ApiRequestHandlerTest, allocateEndpointWithPrivateShouldPassFlagToFactory) |
| 390 | +{ |
| 391 | + auto requestHandler = createApiRequestHandler(); |
| 392 | + |
| 393 | + const auto conferenceId = createConference(requestHandler, R"({ |
| 394 | + "last-n": 9, |
| 395 | + "enable-video": true |
| 396 | + })"); |
| 397 | + |
| 398 | + const char* body = R"({ |
| 399 | + "action": "allocate", |
| 400 | + "bundle-transport": { |
| 401 | + "ice": true, |
| 402 | + "dtls": true, |
| 403 | + "private-port": true |
| 404 | + }, |
| 405 | + "audio": { |
| 406 | + "relay-type": "ssrc-rewrite" |
| 407 | + } |
| 408 | + })"; |
| 409 | + |
| 410 | + const auto urlPath = std::string("/conferences/").append(conferenceId).append("/session0"); |
| 411 | + |
| 412 | + httpd::Request request("POST", urlPath.c_str()); |
| 413 | + request.body.append(body, strlen(body)); |
| 414 | + |
| 415 | + EXPECT_CALL(*_mixerManagerSpyResources->transportFactoryMock, create(_, _, _, _, _, _, _, true)).Times(1); |
| 416 | + |
| 417 | + const auto response = requestHandler.onRequest(request); |
| 418 | + |
| 419 | + EXPECT_EQ(httpd::StatusCode::OK, response.statusCode); |
| 420 | + EXPECT_EQ(false, response.body.empty()); |
| 421 | + |
| 422 | + Mixer* mixer = nullptr; |
| 423 | + |
| 424 | + auto lock = _mixerManagerSpy->getMixer(conferenceId, mixer); |
| 425 | + |
| 426 | + ASSERT_NE(nullptr, mixer); |
| 427 | + |
| 428 | + bridge::TransportDescription transportDescription; |
| 429 | + ASSERT_TRUE(mixer->getTransportBundleDescription("session0", transportDescription)); |
| 430 | +} |
| 431 | + |
| 432 | +TEST_F(ApiRequestHandlerTest, allocateEndpointWithoutPrivateShouldPassFlagToFactory) |
| 433 | +{ |
| 434 | + auto requestHandler = createApiRequestHandler(); |
| 435 | + |
| 436 | + const auto conferenceId = createConference(requestHandler, R"({ |
| 437 | + "last-n": 9, |
| 438 | + "enable-video": true |
| 439 | + })"); |
| 440 | + |
| 441 | + const char* body0 = R"({ |
| 442 | + "action": "allocate", |
| 443 | + "bundle-transport": { |
| 444 | + "ice": true, |
| 445 | + "dtls": true, |
| 446 | + "private-port": false |
| 447 | + }, |
| 448 | + "audio": { |
| 449 | + "relay-type": "ssrc-rewrite" |
| 450 | + } |
| 451 | + })"; |
| 452 | + |
| 453 | + const char* body1 = R"({ |
| 454 | + "action": "allocate", |
| 455 | + "bundle-transport": { |
| 456 | + "ice": true, |
| 457 | + "dtls": true |
| 458 | + }, |
| 459 | + "audio": { |
| 460 | + "relay-type": "ssrc-rewrite" |
| 461 | + } |
| 462 | + })"; |
| 463 | + |
| 464 | + EXPECT_CALL(*_mixerManagerSpyResources->transportFactoryMock, |
| 465 | + create(_, utils::hash<std::string>{}("session0"), _, _, _, _, _, false)) |
| 466 | + .Times(1); |
| 467 | + |
| 468 | + EXPECT_CALL(*_mixerManagerSpyResources->transportFactoryMock, |
| 469 | + create(_, utils::hash<std::string>{}("session1"), _, _, _, _, _, false)) |
| 470 | + .Times(1); |
| 471 | + |
| 472 | + const auto urlPath0 = std::string("/conferences/").append(conferenceId).append("/session0"); |
| 473 | + const auto urlPath1 = std::string("/conferences/").append(conferenceId).append("/session1"); |
| 474 | + |
| 475 | + httpd::Request request0("POST", urlPath0.c_str()); |
| 476 | + request0.body.append(body0, strlen(body0)); |
| 477 | + |
| 478 | + const auto response0 = requestHandler.onRequest(request0); |
| 479 | + EXPECT_EQ(httpd::StatusCode::OK, response0.statusCode); |
| 480 | + EXPECT_EQ(false, response0.body.empty()); |
| 481 | + |
| 482 | + httpd::Request request1("POST", urlPath1.c_str()); |
| 483 | + request1.body.append(body1, strlen(body1)); |
| 484 | + |
| 485 | + const auto response1 = requestHandler.onRequest(request1); |
| 486 | + EXPECT_EQ(httpd::StatusCode::OK, response1.statusCode); |
| 487 | + EXPECT_EQ(false, response1.body.empty()); |
| 488 | +} |
0 commit comments