Skip to content

Commit d4b4b74

Browse files
authored
PYTHON-4509 Update to FIPS host with Python 3.8 binary (mongodb#1688)
1 parent 76fa468 commit d4b4b74

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
@@ -344,6 +344,7 @@ def tearDown(self):
344344
client_context.drop_user("pymongo_test", "user")
345345
super().tearDown()
346346

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

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

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

test/test_client.py

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

10231023
@client_context.require_auth
1024+
@client_context.require_no_fips
10241025
def test_auth_from_uri(self):
10251026
host, port = client_context.host, client_context.port
10261027
client_context.create_user("admin", "admin", "pass")
@@ -1077,6 +1078,7 @@ def test_username_and_password(self):
10771078
rs_or_single_client_noauth(username="ad min", password="foo").server_info()
10781079

10791080
@client_context.require_auth
1081+
@client_context.require_no_fips
10801082
def test_lazy_auth_raises_operation_failure(self):
10811083
lazy_client = rs_or_single_client_noauth(
10821084
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
@@ -432,6 +432,7 @@ def test_cursor_command(self):
432432
def test_cursor_command_invalid(self):
433433
self.assertRaises(InvalidOperation, self.db.cursor_command, "usersInfo", "test")
434434

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

0 commit comments

Comments
 (0)