|
1 | | -from unittest.mock import MagicMock, patch |
| 1 | +import os |
| 2 | +from unittest.mock import MagicMock, mock_open, patch |
2 | 3 |
|
3 | 4 | import assertpy |
4 | 5 |
|
|
7 | 8 | RemoteOfflineStoreConfig, |
8 | 9 | _create_retrieval_metadata, |
9 | 10 | ) |
10 | | -from feast.offline_server import OfflineServer |
| 11 | +from feast.offline_server import ( |
| 12 | + OfflineServer, |
| 13 | + _configure_grpc_fips, |
| 14 | + _is_fips_enabled, |
| 15 | +) |
11 | 16 |
|
12 | 17 |
|
13 | 18 | def test_create_retrieval_metadata_with_sql_string(): |
@@ -86,3 +91,49 @@ def test_offline_server_get_historical_features_passes_sql_to_store(): |
86 | 91 | assertpy.assert_that(result).is_equal_to(mock_job) |
87 | 92 | _, kwargs = mock_offline_store.get_historical_features.call_args |
88 | 93 | assertpy.assert_that(kwargs["entity_df"]).is_equal_to(sql) |
| 94 | + |
| 95 | + |
| 96 | +def test_is_fips_enabled_returns_true(): |
| 97 | + with patch("builtins.open", mock_open(read_data="1\n")): |
| 98 | + assert _is_fips_enabled() is True |
| 99 | + |
| 100 | + |
| 101 | +def test_is_fips_enabled_returns_false(): |
| 102 | + with patch("builtins.open", mock_open(read_data="0\n")): |
| 103 | + assert _is_fips_enabled() is False |
| 104 | + |
| 105 | + |
| 106 | +def test_is_fips_enabled_missing_file(): |
| 107 | + with patch("builtins.open", side_effect=FileNotFoundError): |
| 108 | + assert _is_fips_enabled() is False |
| 109 | + |
| 110 | + |
| 111 | +def test_configure_grpc_fips_sets_cipher_suites(): |
| 112 | + with ( |
| 113 | + patch("feast.offline_server._is_fips_enabled", return_value=True), |
| 114 | + patch.dict(os.environ, {}, clear=False), |
| 115 | + ): |
| 116 | + os.environ.pop("GRPC_SSL_CIPHER_SUITES", None) |
| 117 | + _configure_grpc_fips() |
| 118 | + assert "GRPC_SSL_CIPHER_SUITES" in os.environ |
| 119 | + assert "AES128-GCM-SHA256" in os.environ["GRPC_SSL_CIPHER_SUITES"] |
| 120 | + del os.environ["GRPC_SSL_CIPHER_SUITES"] |
| 121 | + |
| 122 | + |
| 123 | +def test_configure_grpc_fips_respects_existing_env(): |
| 124 | + with ( |
| 125 | + patch("feast.offline_server._is_fips_enabled", return_value=True), |
| 126 | + patch.dict(os.environ, {"GRPC_SSL_CIPHER_SUITES": "custom"}, clear=False), |
| 127 | + ): |
| 128 | + _configure_grpc_fips() |
| 129 | + assert os.environ["GRPC_SSL_CIPHER_SUITES"] == "custom" |
| 130 | + |
| 131 | + |
| 132 | +def test_configure_grpc_fips_noop_without_fips(): |
| 133 | + with ( |
| 134 | + patch("feast.offline_server._is_fips_enabled", return_value=False), |
| 135 | + patch.dict(os.environ, {}, clear=False), |
| 136 | + ): |
| 137 | + os.environ.pop("GRPC_SSL_CIPHER_SUITES", None) |
| 138 | + _configure_grpc_fips() |
| 139 | + assert "GRPC_SSL_CIPHER_SUITES" not in os.environ |
0 commit comments