-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6047f16
commit b50aefa
Showing
8 changed files
with
211 additions
and
14 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
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
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
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,90 @@ | ||
# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import pytest | ||
|
||
from nvflare.apis.fl_constant import ConnectionSecurity | ||
from nvflare.fuel.f3.comm_config_utils import requires_secure_connection | ||
from nvflare.fuel.f3.drivers.driver_params import DriverParams | ||
|
||
|
||
class TestCommConfigUtils: | ||
|
||
@pytest.mark.parametrize( | ||
"resources, expected", | ||
[ | ||
({}, False), | ||
({"x": 1, "y": 2}, False), | ||
({DriverParams.SECURE.value: True}, True), | ||
({DriverParams.SECURE.value: False}, False), | ||
({DriverParams.CONNECTION_SECURITY.value: ConnectionSecurity.INSECURE}, False), | ||
({DriverParams.CONNECTION_SECURITY.value: ConnectionSecurity.TLS}, True), | ||
({DriverParams.CONNECTION_SECURITY.value: ConnectionSecurity.MTLS}, True), | ||
( | ||
{ | ||
DriverParams.CONNECTION_SECURITY.value: ConnectionSecurity.MTLS | ||
}, | ||
True | ||
), | ||
( | ||
{ | ||
DriverParams.CONNECTION_SECURITY.value: ConnectionSecurity.TLS | ||
}, | ||
True | ||
), | ||
( | ||
{ | ||
DriverParams.CONNECTION_SECURITY.value: ConnectionSecurity.MTLS, | ||
DriverParams.SECURE.value: False, | ||
}, | ||
True | ||
), | ||
( | ||
{ | ||
DriverParams.CONNECTION_SECURITY.value: ConnectionSecurity.TLS, | ||
DriverParams.SECURE.value: False, | ||
}, | ||
True | ||
), | ||
( | ||
{ | ||
DriverParams.CONNECTION_SECURITY.value: ConnectionSecurity.MTLS, | ||
DriverParams.SECURE.value: True, | ||
}, | ||
True | ||
), | ||
( | ||
{ | ||
DriverParams.CONNECTION_SECURITY.value: ConnectionSecurity.TLS, | ||
DriverParams.SECURE.value: True, | ||
}, | ||
True | ||
), | ||
( | ||
{ | ||
DriverParams.CONNECTION_SECURITY.value: ConnectionSecurity.INSECURE, | ||
DriverParams.SECURE.value: True, | ||
}, | ||
False | ||
), | ||
( | ||
{ | ||
DriverParams.CONNECTION_SECURITY.value: ConnectionSecurity.INSECURE, | ||
}, | ||
False | ||
), | ||
], | ||
) | ||
def test_requires_secure_connection(self, resources, expected): | ||
result = requires_secure_connection(resources) | ||
assert result == expected |
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,66 @@ | ||
# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import pytest | ||
|
||
from nvflare.fuel.utils.url_utils import make_url | ||
|
||
|
||
class TestUrlUtils: | ||
|
||
@pytest.mark.parametrize( | ||
"scheme, address, secure, expected", | ||
[ | ||
("tcp", "xyz.com", False, "tcp://xyz.com"), | ||
("tcp", "xyz.com:1234", False, "tcp://xyz.com:1234"), | ||
("tcp", "xyz.com:1234", True, "stcp://xyz.com:1234"), | ||
("grpc", "xyz.com", False, "grpc://xyz.com"), | ||
("grpc", "xyz.com:1234", False, "grpc://xyz.com:1234"), | ||
("grpc", "xyz.com:1234", True, "grpcs://xyz.com:1234"), | ||
("http", "xyz.com", False, "http://xyz.com"), | ||
("http", "xyz.com:1234", False, "http://xyz.com:1234"), | ||
("http", "xyz.com:1234", True, "https://xyz.com:1234"), | ||
("tcp", ("xyz.com",), False, "tcp://xyz.com"), | ||
("tcp", ("xyz.com", 1234), False, "tcp://xyz.com:1234"), | ||
("tcp", ["xyz.com"], False, "tcp://xyz.com"), | ||
("tcp", ["xyz.com", 1234], False, "tcp://xyz.com:1234"), | ||
("tcp", {"host": "xyz.com"}, False, "tcp://xyz.com"), | ||
("tcp", {"host": "xyz.com", "port": 1234}, False, "tcp://xyz.com:1234"), | ||
], | ||
) | ||
def test_make_url(self, scheme, address, secure, expected): | ||
result = make_url(scheme, address, secure) | ||
assert result == expected | ||
|
||
@pytest.mark.parametrize( | ||
"scheme, address, secure", | ||
[ | ||
("tcp", "", False), | ||
("abc", "xyz.com:1234", False), | ||
("tcp", 1234, True), | ||
("grpc", [], False), | ||
("grpc", (), False), | ||
("grpc", {}, True), | ||
("http", [1234], False), | ||
("http", [1234, "xyz.com"], False), | ||
("http", ["xyz.com", 1234, 22], True), | ||
("http", (1234,), False), | ||
("http", (1234, "xyz.com"), False), | ||
("http", ("xyz.com", 1234, 22), True), | ||
("tcp", {"hosts": "xyz.com"}, False), | ||
("tcp", {"host": "xyz.com", "port": 1234, "extra": 2323}, False), | ||
], | ||
) | ||
def test_make_url_error(self, scheme, address, secure): | ||
with pytest.raises(ValueError): | ||
make_url(scheme, address, secure) |