This test uses two containers: one listens to 'validPort' and 'invalidPort' and writes data received to files; the other container attempts to connect to the previous container using 'validPort' and 'invalidPort'. Verify that only the connection through 'validPort' is successful by confirming that the expected data has been written to its output file.
| 458 | // through 'validPort' is successful by confirming that the expected |
| 459 | // data has been written to its output file. |
| 460 | TEST_F(PortMappingIsolatorTest, ROOT_NC_ContainerToContainerTCP) |
| 461 | { |
| 462 | Try<Isolator*> isolator = PortMappingIsolatorProcess::create(flags); |
| 463 | ASSERT_SOME(isolator); |
| 464 | |
| 465 | Try<Launcher*> launcher = LinuxLauncher::create(flags); |
| 466 | ASSERT_SOME(launcher); |
| 467 | |
| 468 | // Set the executor's resources. |
| 469 | ExecutorInfo executorInfo; |
| 470 | executorInfo.mutable_resources()->CopyFrom( |
| 471 | Resources::parse(container1Ports).get()); |
| 472 | |
| 473 | ContainerID containerId1; |
| 474 | containerId1.set_value(id::UUID::random().toString()); |
| 475 | |
| 476 | // Use a relative temporary directory so it gets cleaned up |
| 477 | // automatically with the test. |
| 478 | Try<string> dir1 = os::mkdtemp(path::join(os::getcwd(), "XXXXXX")); |
| 479 | ASSERT_SOME(dir1); |
| 480 | |
| 481 | ContainerConfig containerConfig1; |
| 482 | containerConfig1.mutable_executor_info()->CopyFrom(executorInfo); |
| 483 | containerConfig1.set_directory(dir1.get()); |
| 484 | |
| 485 | Future<Option<ContainerLaunchInfo>> launchInfo1 = |
| 486 | isolator.get()->prepare( |
| 487 | containerId1, |
| 488 | containerConfig1); |
| 489 | |
| 490 | AWAIT_READY(launchInfo1); |
| 491 | ASSERT_SOME(launchInfo1.get()); |
| 492 | ASSERT_EQ(1, launchInfo1.get()->pre_exec_commands().size()); |
| 493 | |
| 494 | ostringstream command1; |
| 495 | |
| 496 | // Listen to 'localhost' and 'port'. |
| 497 | command1 << "nc -l localhost " << validPort << " > " << trafficViaLoopback |
| 498 | << "& "; |
| 499 | |
| 500 | // Listen to 'public ip' and 'port'. |
| 501 | command1 << "nc -l " << hostIP << " " << validPort << " > " |
| 502 | << trafficViaPublic << "& "; |
| 503 | |
| 504 | // Listen to 'invalidPort'. This should not receive any data. |
| 505 | command1 << "nc -l " << invalidPort << " | tee " << trafficViaLoopback << " " |
| 506 | << trafficViaPublic << "& "; |
| 507 | |
| 508 | // Touch the guard file. |
| 509 | command1 << "touch " << container1Ready; |
| 510 | |
| 511 | int pipes[2]; |
| 512 | ASSERT_NE(-1, ::pipe(pipes)); |
| 513 | |
| 514 | Try<pid_t> pid = launchHelper( |
| 515 | launcher.get(), |
| 516 | pipes, |
| 517 | containerId1, |
nothing calls this directly
no test coverage detected