-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request from GHSA-3f48-9j7q-q2gv
* service: Listen on loopback interface and log listener URL * pyproject.toml: Add dev-dependency on psutil * Update poetry.lock * tests: Verify the service listens on the loopback interface * Update poetry.lock * tests: Use non-deprecated API to get server port
- Loading branch information
Showing
4 changed files
with
84 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from ipaddress import ip_address | ||
from typing import Generator | ||
|
||
import psutil | ||
import pytest | ||
|
||
from ni_measurementlink_service.measurement.service import MeasurementService | ||
from tests.utilities import loopback_measurement | ||
from tests.utilities.discovery_service_process import DiscoveryServiceProcess | ||
|
||
|
||
def test___loopback_measurement___listening_on_loopback_interface( | ||
measurement_service: MeasurementService, | ||
): | ||
insecure_port = int(measurement_service.service_location.insecure_port) | ||
|
||
listener_ips = [ | ||
ip_address(conn.laddr.ip) | ||
for conn in psutil.Process().connections() | ||
if conn.laddr.port == insecure_port and conn.status == psutil.CONN_LISTEN | ||
] | ||
assert len(listener_ips) >= 1 and all([ip.is_loopback for ip in listener_ips]) | ||
assert measurement_service.service_location.ssl_authenticated_port == "" | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def measurement_service( | ||
discovery_service_process: DiscoveryServiceProcess, | ||
) -> Generator[MeasurementService, None, None]: | ||
"""Test fixture that creates and hosts a measurement service.""" | ||
with loopback_measurement.measurement_service.host_service() as service: | ||
yield service |