From 69e25431fe2a900dce9a6f8a7bd9e65755aedb0f Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Thu, 17 Oct 2024 15:24:47 -0500 Subject: [PATCH 1/5] PYTHON-4882 Use shrub.py for enterprise auth tests --- .evergreen/config.yml | 101 +++++++++++++++++++++----- .evergreen/scripts/generate_config.py | 25 ++++++- 2 files changed, 107 insertions(+), 19 deletions(-) diff --git a/.evergreen/config.yml b/.evergreen/config.yml index a7efc223b9..f5f0266c2a 100644 --- a/.evergreen/config.yml +++ b/.evergreen/config.yml @@ -3194,6 +3194,89 @@ buildvariants: COMPRESSORS: zstd PYTHON_BINARY: /opt/python/pypy3.9/bin/python3 +# Enterprise auth tests. +- name: enterprise-auth-rhel8-py3.9-auth + tasks: + - name: test-enterprise-auth + display_name: Enterprise Auth RHEL8 py3.9 Auth + run_on: + - rhel87-small + expansions: + AUTH: auth + PYTHON_BINARY: /opt/python/3.9/bin/python3 +- name: enterprise-auth-rhel8-py3.10-auth + tasks: + - name: test-enterprise-auth + display_name: Enterprise Auth RHEL8 py3.10 Auth + run_on: + - rhel87-small + expansions: + AUTH: auth + PYTHON_BINARY: /opt/python/3.10/bin/python3 +- name: enterprise-auth-rhel8-py3.11-auth + tasks: + - name: test-enterprise-auth + display_name: Enterprise Auth RHEL8 py3.11 Auth + run_on: + - rhel87-small + expansions: + AUTH: auth + PYTHON_BINARY: /opt/python/3.11/bin/python3 +- name: enterprise-auth-rhel8-py3.12-auth + tasks: + - name: test-enterprise-auth + display_name: Enterprise Auth RHEL8 py3.12 Auth + run_on: + - rhel87-small + expansions: + AUTH: auth + PYTHON_BINARY: /opt/python/3.12/bin/python3 +- name: enterprise-auth-rhel8-py3.13-auth + tasks: + - name: test-enterprise-auth + display_name: Enterprise Auth RHEL8 py3.13 Auth + run_on: + - rhel87-small + expansions: + AUTH: auth + PYTHON_BINARY: /opt/python/3.13/bin/python3 +- name: enterprise-auth-rhel8-pypy3.9-auth + tasks: + - name: test-enterprise-auth + display_name: Enterprise Auth RHEL8 pypy3.9 Auth + run_on: + - rhel87-small + expansions: + AUTH: auth + PYTHON_BINARY: /opt/python/pypy3.9/bin/python3 +- name: enterprise-auth-rhel8-pypy3.10-auth + tasks: + - name: test-enterprise-auth + display_name: Enterprise Auth RHEL8 pypy3.10 Auth + run_on: + - rhel87-small + expansions: + AUTH: auth + PYTHON_BINARY: /opt/python/pypy3.10/bin/python3 +- name: enterprise-auth-win64-py3.9-auth + tasks: + - name: test-enterprise-auth + display_name: Enterprise Auth Win64 py3.9 Auth + run_on: + - windows-64-vsMulti-small + expansions: + AUTH: auth + PYTHON_BINARY: C:/python/Python39/python.exe +- name: enterprise-auth-win64-py3.13-auth + tasks: + - name: test-enterprise-auth + display_name: Enterprise Auth Win64 py3.13 Auth + run_on: + - windows-64-vsMulti-small + expansions: + AUTH: auth + PYTHON_BINARY: C:/python/Python313/python.exe + - matrix_name: "tests-fips" matrix_spec: platform: @@ -3350,24 +3433,6 @@ buildvariants: tasks: - ".latest" -- matrix_name: "test-linux-enterprise-auth" - matrix_spec: - platform: rhel8 - python-version: "*" - auth: "auth" - display_name: "Enterprise ${auth} ${platform} ${python-version}" - tasks: - - name: "test-enterprise-auth" - -- matrix_name: "tests-windows-enterprise-auth" - matrix_spec: - platform: windows - python-version-windows: "*" - auth: "auth" - display_name: "Enterprise ${auth} ${platform} ${python-version-windows}" - tasks: - - name: "test-enterprise-auth" - - matrix_name: "test-search-index-helpers" matrix_spec: platform: rhel8 diff --git a/.evergreen/scripts/generate_config.py b/.evergreen/scripts/generate_config.py index 91dedeb620..63970f6ec5 100644 --- a/.evergreen/scripts/generate_config.py +++ b/.evergreen/scripts/generate_config.py @@ -384,10 +384,33 @@ def create_compression_variants(): return variants +def create_enterprise_auth_variants(): + expansions = dict(AUTH="auth") + variants = [] + + # All python versions on linux, min and max on Windows. + host = "rhel8" + for python in ALL_PYTHONS: + display_name = get_display_name("Enterprise Auth", host, python=python, **expansions) + variant = create_variant( + ["test-enterprise-auth"], display_name, host=host, python=python, expansions=expansions + ) + variants.append(variant) + + host = "win64" + for python in MIN_MAX_PYTHON: + display_name = get_display_name("Enterprise Auth", host, python=python, **expansions) + variant = create_variant( + ["test-enterprise-auth"], display_name, host=host, python=python, expansions=expansions + ) + variants.append(variant) + return variants + + ################## # Generate Config ################## -variants = create_compression_variants() +variants = create_enterprise_auth_variants() # print(len(variants)) generate_yaml(variants=variants) From 06eb1af53f1af6afff7ea7254ec2a005f623b64d Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Thu, 17 Oct 2024 15:35:25 -0500 Subject: [PATCH 2/5] use auth marker --- .evergreen/run-tests.sh | 2 ++ test/asynchronous/test_auth.py | 11 +++++++++++ test/test_auth.py | 11 +++++++++++ 3 files changed, 24 insertions(+) diff --git a/.evergreen/run-tests.sh b/.evergreen/run-tests.sh index 364570999f..36fa76e317 100755 --- a/.evergreen/run-tests.sh +++ b/.evergreen/run-tests.sh @@ -90,6 +90,8 @@ if [ -n "$TEST_ENTERPRISE_AUTH" ]; then export GSSAPI_HOST=${SASL_HOST} export GSSAPI_PORT=${SASL_PORT} export GSSAPI_PRINCIPAL=${PRINCIPAL} + + export TEST_SUITES="auth" fi if [ -n "$TEST_LOADBALANCER" ]; then diff --git a/test/asynchronous/test_auth.py b/test/asynchronous/test_auth.py index fbaca41f09..c806850f79 100644 --- a/test/asynchronous/test_auth.py +++ b/test/asynchronous/test_auth.py @@ -32,6 +32,8 @@ ) from test.utils import AllowListEventListener, delay, ignore_deprecations +import pytest + from pymongo import AsyncMongoClient, monitoring from pymongo.asynchronous.auth import HAVE_KERBEROS from pymongo.auth_shared import _build_credentials_tuple @@ -80,6 +82,7 @@ def run(self): class TestGSSAPI(AsyncPyMongoTestCase): + pytestmark = pytest.mark.auth mech_properties: str service_realm_required: bool @@ -266,6 +269,8 @@ async def test_gssapi_threaded(self): class TestSASLPlain(AsyncPyMongoTestCase): + pytestmark = pytest.mark.auth + @classmethod def setUpClass(cls): if not SASL_HOST or not SASL_USER or not SASL_PASS: @@ -339,6 +344,8 @@ def auth_string(user, password): class TestSCRAMSHA1(AsyncIntegrationTest): + pytestmark = pytest.mark.auth + @async_client_context.require_auth async def asyncSetUp(self): await super().asyncSetUp() @@ -373,6 +380,8 @@ async def test_scram_sha1(self): # https://github.com/mongodb/specifications/blob/master/source/auth/auth.rst#scram-sha-256-and-mechanism-negotiation class TestSCRAM(AsyncIntegrationTest): + pytestmark = pytest.mark.auth + @async_client_context.require_auth @async_client_context.require_version_min(3, 7, 2) async def asyncSetUp(self): @@ -612,6 +621,8 @@ async def test_scram_threaded(self): class TestAuthURIOptions(AsyncIntegrationTest): + pytestmark = pytest.mark.auth + @async_client_context.require_auth async def asyncSetUp(self): await super().asyncSetUp() diff --git a/test/test_auth.py b/test/test_auth.py index b311d330bc..a4150823e6 100644 --- a/test/test_auth.py +++ b/test/test_auth.py @@ -32,6 +32,8 @@ ) from test.utils import AllowListEventListener, delay, ignore_deprecations +import pytest + from pymongo import MongoClient, monitoring from pymongo.auth_shared import _build_credentials_tuple from pymongo.errors import OperationFailure @@ -80,6 +82,7 @@ def run(self): class TestGSSAPI(PyMongoTestCase): + pytestmark = pytest.mark.auth mech_properties: str service_realm_required: bool @@ -266,6 +269,8 @@ def test_gssapi_threaded(self): class TestSASLPlain(PyMongoTestCase): + pytestmark = pytest.mark.auth + @classmethod def setUpClass(cls): if not SASL_HOST or not SASL_USER or not SASL_PASS: @@ -339,6 +344,8 @@ def auth_string(user, password): class TestSCRAMSHA1(IntegrationTest): + pytestmark = pytest.mark.auth + @client_context.require_auth def setUp(self): super().setUp() @@ -371,6 +378,8 @@ def test_scram_sha1(self): # https://github.com/mongodb/specifications/blob/master/source/auth/auth.rst#scram-sha-256-and-mechanism-negotiation class TestSCRAM(IntegrationTest): + pytestmark = pytest.mark.auth + @client_context.require_auth @client_context.require_version_min(3, 7, 2) def setUp(self): @@ -608,6 +617,8 @@ def test_scram_threaded(self): class TestAuthURIOptions(IntegrationTest): + pytestmark = pytest.mark.auth + @client_context.require_auth def setUp(self): super().setUp() From 2db6ba5dfe64c8f2014da9b23974f487d25eb7f3 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Thu, 17 Oct 2024 15:42:02 -0500 Subject: [PATCH 3/5] use auth marker --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index b4f59f67d5..9a29a777fc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -99,6 +99,7 @@ filterwarnings = [ markers = [ "auth_aws: tests that rely on pymongo-auth-aws", "auth_oidc: tests that rely on oidc auth", + "auth: tests that rely on authentication", "ocsp: tests that rely on ocsp", "atlas: tests that rely on atlas", "data_lake: tests that rely on atlas data lake", From e10ea66c4eaca28c73a14214bad0c2696334b6a8 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Fri, 18 Oct 2024 05:26:44 -0500 Subject: [PATCH 4/5] compress matrix --- .evergreen/config.yml | 34 +++++++-------------------- .evergreen/scripts/generate_config.py | 16 ++++++------- 2 files changed, 15 insertions(+), 35 deletions(-) diff --git a/.evergreen/config.yml b/.evergreen/config.yml index f5f0266c2a..9e2ab77088 100644 --- a/.evergreen/config.yml +++ b/.evergreen/config.yml @@ -3195,15 +3195,15 @@ buildvariants: PYTHON_BINARY: /opt/python/pypy3.9/bin/python3 # Enterprise auth tests. -- name: enterprise-auth-rhel8-py3.9-auth +- name: enterprise-auth-macos-py3.9-auth tasks: - name: test-enterprise-auth - display_name: Enterprise Auth RHEL8 py3.9 Auth + display_name: Enterprise Auth macOS py3.9 Auth run_on: - - rhel87-small + - macos-14 expansions: AUTH: auth - PYTHON_BINARY: /opt/python/3.9/bin/python3 + PYTHON_BINARY: /Library/Frameworks/Python.Framework/Versions/3.9/bin/python3 - name: enterprise-auth-rhel8-py3.10-auth tasks: - name: test-enterprise-auth @@ -3231,15 +3231,15 @@ buildvariants: expansions: AUTH: auth PYTHON_BINARY: /opt/python/3.12/bin/python3 -- name: enterprise-auth-rhel8-py3.13-auth +- name: enterprise-auth-win64-py3.13-auth tasks: - name: test-enterprise-auth - display_name: Enterprise Auth RHEL8 py3.13 Auth + display_name: Enterprise Auth Win64 py3.13 Auth run_on: - - rhel87-small + - windows-64-vsMulti-small expansions: AUTH: auth - PYTHON_BINARY: /opt/python/3.13/bin/python3 + PYTHON_BINARY: C:/python/Python313/python.exe - name: enterprise-auth-rhel8-pypy3.9-auth tasks: - name: test-enterprise-auth @@ -3258,24 +3258,6 @@ buildvariants: expansions: AUTH: auth PYTHON_BINARY: /opt/python/pypy3.10/bin/python3 -- name: enterprise-auth-win64-py3.9-auth - tasks: - - name: test-enterprise-auth - display_name: Enterprise Auth Win64 py3.9 Auth - run_on: - - windows-64-vsMulti-small - expansions: - AUTH: auth - PYTHON_BINARY: C:/python/Python39/python.exe -- name: enterprise-auth-win64-py3.13-auth - tasks: - - name: test-enterprise-auth - display_name: Enterprise Auth Win64 py3.13 Auth - run_on: - - windows-64-vsMulti-small - expansions: - AUTH: auth - PYTHON_BINARY: C:/python/Python313/python.exe - matrix_name: "tests-fips" matrix_spec: diff --git a/.evergreen/scripts/generate_config.py b/.evergreen/scripts/generate_config.py index 63970f6ec5..c3bfeef7af 100644 --- a/.evergreen/scripts/generate_config.py +++ b/.evergreen/scripts/generate_config.py @@ -388,22 +388,20 @@ def create_enterprise_auth_variants(): expansions = dict(AUTH="auth") variants = [] - # All python versions on linux, min and max on Windows. - host = "rhel8" + # All python versions across platforms. for python in ALL_PYTHONS: + if python == CPYTHONS[0]: + host = "macos" + elif python == CPYTHONS[-1]: + host = "win64" + else: + host = "rhel8" display_name = get_display_name("Enterprise Auth", host, python=python, **expansions) variant = create_variant( ["test-enterprise-auth"], display_name, host=host, python=python, expansions=expansions ) variants.append(variant) - host = "win64" - for python in MIN_MAX_PYTHON: - display_name = get_display_name("Enterprise Auth", host, python=python, **expansions) - variant = create_variant( - ["test-enterprise-auth"], display_name, host=host, python=python, expansions=expansions - ) - variants.append(variant) return variants From cbfa3a0352eaddd29b0c7614adf95d0e4efd7c51 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Fri, 18 Oct 2024 08:23:44 -0500 Subject: [PATCH 5/5] try with single marker --- test/asynchronous/test_auth.py | 11 ++--------- test/test_auth.py | 11 ++--------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/test/asynchronous/test_auth.py b/test/asynchronous/test_auth.py index c806850f79..9262714374 100644 --- a/test/asynchronous/test_auth.py +++ b/test/asynchronous/test_auth.py @@ -44,6 +44,8 @@ _IS_SYNC = False +pytestmark = pytest.mark.auth + # YOU MUST RUN KINIT BEFORE RUNNING GSSAPI TESTS ON UNIX. GSSAPI_HOST = os.environ.get("GSSAPI_HOST") GSSAPI_PORT = int(os.environ.get("GSSAPI_PORT", "27017")) @@ -82,7 +84,6 @@ def run(self): class TestGSSAPI(AsyncPyMongoTestCase): - pytestmark = pytest.mark.auth mech_properties: str service_realm_required: bool @@ -269,8 +270,6 @@ async def test_gssapi_threaded(self): class TestSASLPlain(AsyncPyMongoTestCase): - pytestmark = pytest.mark.auth - @classmethod def setUpClass(cls): if not SASL_HOST or not SASL_USER or not SASL_PASS: @@ -344,8 +343,6 @@ def auth_string(user, password): class TestSCRAMSHA1(AsyncIntegrationTest): - pytestmark = pytest.mark.auth - @async_client_context.require_auth async def asyncSetUp(self): await super().asyncSetUp() @@ -380,8 +377,6 @@ async def test_scram_sha1(self): # https://github.com/mongodb/specifications/blob/master/source/auth/auth.rst#scram-sha-256-and-mechanism-negotiation class TestSCRAM(AsyncIntegrationTest): - pytestmark = pytest.mark.auth - @async_client_context.require_auth @async_client_context.require_version_min(3, 7, 2) async def asyncSetUp(self): @@ -621,8 +616,6 @@ async def test_scram_threaded(self): class TestAuthURIOptions(AsyncIntegrationTest): - pytestmark = pytest.mark.auth - @async_client_context.require_auth async def asyncSetUp(self): await super().asyncSetUp() diff --git a/test/test_auth.py b/test/test_auth.py index a4150823e6..310006afff 100644 --- a/test/test_auth.py +++ b/test/test_auth.py @@ -44,6 +44,8 @@ _IS_SYNC = True +pytestmark = pytest.mark.auth + # YOU MUST RUN KINIT BEFORE RUNNING GSSAPI TESTS ON UNIX. GSSAPI_HOST = os.environ.get("GSSAPI_HOST") GSSAPI_PORT = int(os.environ.get("GSSAPI_PORT", "27017")) @@ -82,7 +84,6 @@ def run(self): class TestGSSAPI(PyMongoTestCase): - pytestmark = pytest.mark.auth mech_properties: str service_realm_required: bool @@ -269,8 +270,6 @@ def test_gssapi_threaded(self): class TestSASLPlain(PyMongoTestCase): - pytestmark = pytest.mark.auth - @classmethod def setUpClass(cls): if not SASL_HOST or not SASL_USER or not SASL_PASS: @@ -344,8 +343,6 @@ def auth_string(user, password): class TestSCRAMSHA1(IntegrationTest): - pytestmark = pytest.mark.auth - @client_context.require_auth def setUp(self): super().setUp() @@ -378,8 +375,6 @@ def test_scram_sha1(self): # https://github.com/mongodb/specifications/blob/master/source/auth/auth.rst#scram-sha-256-and-mechanism-negotiation class TestSCRAM(IntegrationTest): - pytestmark = pytest.mark.auth - @client_context.require_auth @client_context.require_version_min(3, 7, 2) def setUp(self): @@ -617,8 +612,6 @@ def test_scram_threaded(self): class TestAuthURIOptions(IntegrationTest): - pytestmark = pytest.mark.auth - @client_context.require_auth def setUp(self): super().setUp()