Skip to content

Commit 255d190

Browse files
authored
PYTHON-4509 [v4.8] Update to FIPS host with Python 3.8 binary (#1689)
1 parent 5d8b433 commit 255d190

File tree

6 files changed

+29
-5
lines changed

6 files changed

+29
-5
lines changed

.evergreen/config.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ task_groups:
962962
- ${DRIVERS_TOOLS}/.evergreen/csfle/azurekms/delete-vm.sh
963963
- func: "upload test results"
964964
setup_group_can_fail_task: true
965-
teardown_group_can_fail_task: true
965+
teardown_task_can_fail_task: true
966966
setup_group_timeout_secs: 1800
967967
tasks:
968968
- testazurekms-task
@@ -2220,9 +2220,9 @@ axes:
22202220
display_name: "RHEL 8.x"
22212221
run_on: rhel87-small
22222222
batchtime: 10080 # 7 days
2223-
- id: rhel80-fips
2224-
display_name: "RHEL 8.0 FIPS"
2225-
run_on: rhel80-fips
2223+
- id: rhel92-fips
2224+
display_name: "RHEL 9.2 FIPS"
2225+
run_on: rhel92-fips
22262226
batchtime: 10080 # 7 days
22272227
- id: ubuntu-22.04
22282228
display_name: "Ubuntu 22.04"
@@ -2596,7 +2596,7 @@ buildvariants:
25962596
- matrix_name: "tests-fips"
25972597
matrix_spec:
25982598
platform:
2599-
- rhel80-fips
2599+
- rhel92-fips
26002600
auth: "auth"
26012601
ssl: "ssl"
26022602
display_name: "${platform} ${auth} ${ssl}"

test/__init__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ def __init__(self):
277277
self.is_data_lake = False
278278
self.load_balancer = TEST_LOADBALANCER
279279
self.serverless = TEST_SERVERLESS
280+
self._fips_enabled = None
280281
if self.load_balancer or self.serverless:
281282
self.default_client_options["loadBalanced"] = True
282283
if COMPRESSORS:
@@ -523,6 +524,17 @@ def storage_engine(self):
523524
# Raised if self.server_status is None.
524525
return None
525526

527+
@property
528+
def fips_enabled(self):
529+
if self._fips_enabled is not None:
530+
return self._fips_enabled
531+
try:
532+
subprocess.check_call(["fips-mode-setup", "--is-enabled"])
533+
self._fips_enabled = True
534+
except (subprocess.SubprocessError, FileNotFoundError):
535+
self._fips_enabled = False
536+
return self._fips_enabled
537+
526538
def check_auth_type(self, auth_type):
527539
auth_mechs = self.server_parameters.get("authenticationMechanisms", [])
528540
return auth_type in auth_mechs
@@ -670,6 +682,12 @@ def require_auth(self, func):
670682
lambda: self.auth_enabled, "Authentication is not enabled on the server", func=func
671683
)
672684

685+
def require_no_fips(self, func):
686+
"""Run a test only if the host does not have FIPS enabled."""
687+
return self._require(
688+
lambda: not self.fips_enabled, "Test cannot run on a FIPS-enabled host", func=func
689+
)
690+
673691
def require_no_auth(self, func):
674692
"""Run a test only if the server is running without auth enabled."""
675693
return self._require(

test/test_auth.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ def tearDown(self):
343343
client_context.drop_user("pymongo_test", "user")
344344
super().tearDown()
345345

346+
@client_context.require_no_fips
346347
def test_scram_sha1(self):
347348
host, port = client_context.host, client_context.port
348349

@@ -404,6 +405,7 @@ def test_scram_skip_empty_exchange(self):
404405
else:
405406
self.assertEqual(started, ["saslStart", "saslContinue", "saslContinue"])
406407

408+
@client_context.require_no_fips
407409
def test_scram(self):
408410
# Step 1: create users
409411
client_context.create_user(

test/test_client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,7 @@ def test_bad_uri(self):
10161016
MongoClient("http://localhost")
10171017

10181018
@client_context.require_auth
1019+
@client_context.require_no_fips
10191020
def test_auth_from_uri(self):
10201021
host, port = client_context.host, client_context.port
10211022
client_context.create_user("admin", "admin", "pass")
@@ -1072,6 +1073,7 @@ def test_username_and_password(self):
10721073
rs_or_single_client_noauth(username="ad min", password="foo").server_info()
10731074

10741075
@client_context.require_auth
1076+
@client_context.require_no_fips
10751077
def test_lazy_auth_raises_operation_failure(self):
10761078
lazy_client = rs_or_single_client_noauth(
10771079
f"mongodb://user:wrong@{client_context.host}/pymongo_test", connect=False

test/test_connection_monitoring.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ def mock_connect(*args, **kwargs):
400400
failed_event = listener.events[3]
401401
self.assertEqual(failed_event.reason, ConnectionCheckOutFailedReason.CONN_ERROR)
402402

403+
@client_context.require_no_fips
403404
def test_5_check_out_fails_auth_error(self):
404405
listener = CMAPListener()
405406
client = single_client_noauth(

test/test_database.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ def test_cursor_command(self):
431431
def test_cursor_command_invalid(self):
432432
self.assertRaises(InvalidOperation, self.db.cursor_command, "usersInfo", "test")
433433

434+
@client_context.require_no_fips
434435
def test_password_digest(self):
435436
self.assertRaises(TypeError, auth._password_digest, 5)
436437
self.assertRaises(TypeError, auth._password_digest, True)

0 commit comments

Comments
 (0)