From 1acffa7d841f8e67171878e7c6d35c6a26718976 Mon Sep 17 00:00:00 2001 From: PatersonProjects Date: Mon, 25 May 2026 09:22:43 -0700 Subject: [PATCH 1/4] Base test cases Signed-off-by: PatersonProjects --- ...st_connectionStatus_argument_validation.py | 63 ++++++++++++++ .../test_connectionStatus_auth_users.py | 58 +++++++++++++ .../test_connectionStatus_core_behavior.py | 51 +++++++++++ .../test_connectionStatus_edge_cases.py | 26 ++++++ .../test_connectionStatus_show_privileges.py | 84 +++++++++++++++++++ 5 files changed, 282 insertions(+) create mode 100644 documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_argument_validation.py create mode 100644 documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_auth_users.py create mode 100644 documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_core_behavior.py create mode 100644 documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_edge_cases.py create mode 100644 documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_show_privileges.py diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_argument_validation.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_argument_validation.py new file mode 100644 index 00000000..6fa28627 --- /dev/null +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_argument_validation.py @@ -0,0 +1,63 @@ +"""Tests for connectionStatus command argument validation.""" + +from __future__ import annotations + +from dataclasses import dataclass +from datetime import datetime, timezone +from typing import Any + +import pytest +from bson import Binary, Decimal128, Int64, MaxKey, MinKey, ObjectId, Regex, Timestamp + +from documentdb_tests.framework.assertions import assertFailureCode, assertSuccessPartial +from documentdb_tests.framework.error_codes import UNRECOGNIZED_COMMAND_FIELD_ERROR +from documentdb_tests.framework.executor import execute_admin_command +from documentdb_tests.framework.parametrize import pytest_params +from documentdb_tests.framework.test_case import BaseTestCase + +pytestmark = pytest.mark.admin + + +@dataclass(frozen=True) +class ConnStatusArgTest(BaseTestCase): + value: Any = None + + +# connectionStatus ignores the command field value — all types should succeed +ARG_TYPE_TESTS: list[ConnStatusArgTest] = [ + ConnStatusArgTest("int_1", value=1, msg="int should succeed"), + ConnStatusArgTest("int_0", value=0, msg="int 0 should succeed"), + ConnStatusArgTest("double", value=1.5, msg="double should succeed"), + ConnStatusArgTest("long", value=Int64(1), msg="long should succeed"), + ConnStatusArgTest("decimal128", value=Decimal128("1"), msg="decimal128 should succeed"), + ConnStatusArgTest("string", value="test", msg="string should succeed"), + ConnStatusArgTest("bool_true", value=True, msg="bool true should succeed"), + ConnStatusArgTest("bool_false", value=False, msg="bool false should succeed"), + ConnStatusArgTest( + "date", value=datetime(2024, 1, 1, tzinfo=timezone.utc), msg="date should succeed" + ), + ConnStatusArgTest("null", value=None, msg="null should succeed"), + ConnStatusArgTest("object", value={}, msg="object should succeed"), + ConnStatusArgTest("array", value=[], msg="array should succeed"), + ConnStatusArgTest("binData", value=Binary(b""), msg="binData should succeed"), + ConnStatusArgTest("objectId", value=ObjectId(), msg="objectId should succeed"), + ConnStatusArgTest("regex", value=Regex("test"), msg="regex should succeed"), + ConnStatusArgTest("timestamp", value=Timestamp(0, 0), msg="timestamp should succeed"), + ConnStatusArgTest("minKey", value=MinKey(), msg="minKey should succeed"), + ConnStatusArgTest("maxKey", value=MaxKey(), msg="maxKey should succeed"), +] + + +@pytest.mark.parametrize("test", pytest_params(ARG_TYPE_TESTS)) +def test_connectionStatus_accepts_any_type(collection, test): + """Test connectionStatus accepts all BSON types for command field value.""" + result = execute_admin_command(collection, {"connectionStatus": test.value}) + assertSuccessPartial(result, {"ok": 1.0}, msg=test.msg) + + +def test_connectionStatus_unrecognized_field(collection): + """Test connectionStatus with unrecognized extra field returns error.""" + result = execute_admin_command(collection, {"connectionStatus": 1, "foo": 1}) + assertFailureCode( + result, UNRECOGNIZED_COMMAND_FIELD_ERROR, msg="Unrecognized field should error" + ) diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_auth_users.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_auth_users.py new file mode 100644 index 00000000..af2b89e1 --- /dev/null +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_auth_users.py @@ -0,0 +1,58 @@ +"""Tests for connectionStatus authenticated users and roles. + +Note: Many auth-related tests require creating users with specific roles +and authenticating as them. These tests cover what's testable without +special RBAC setup (unauthenticated/default connection behavior). +""" + +import pytest + +from documentdb_tests.framework.assertions import assertResult +from documentdb_tests.framework.executor import execute_admin_command +from documentdb_tests.framework.property_checks import Exists, IsType + +pytestmark = pytest.mark.admin + + +def test_connectionStatus_authenticatedUsers_is_array(collection): + """Test authenticatedUsers is an array.""" + result = execute_admin_command(collection, {"connectionStatus": 1}) + assertResult( + result, + expected={"authInfo": {"authenticatedUsers": IsType("array")}}, + raw_res=True, + msg="authenticatedUsers should be array", + ) + + +def test_connectionStatus_authenticatedUserRoles_is_array(collection): + """Test authenticatedUserRoles is an array.""" + result = execute_admin_command(collection, {"connectionStatus": 1}) + assertResult( + result, + expected={"authInfo": {"authenticatedUserRoles": IsType("array")}}, + raw_res=True, + msg="authenticatedUserRoles should be array", + ) + + +def test_connectionStatus_showPrivileges_returns_privileges_array(collection): + """Test showPrivileges: true returns authenticatedUserPrivileges as array.""" + result = execute_admin_command(collection, {"connectionStatus": 1, "showPrivileges": True}) + assertResult( + result, + expected={"authInfo": {"authenticatedUserPrivileges": IsType("array")}}, + raw_res=True, + msg="authenticatedUserPrivileges should be array", + ) + + +def test_connectionStatus_authInfo_exists(collection): + """Test authInfo document is always present.""" + result = execute_admin_command(collection, {"connectionStatus": 1}) + assertResult( + result, + expected={"authInfo": Exists()}, + raw_res=True, + msg="authInfo should always exist", + ) diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_core_behavior.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_core_behavior.py new file mode 100644 index 00000000..c89fbca5 --- /dev/null +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_core_behavior.py @@ -0,0 +1,51 @@ +"""Tests for connectionStatus command core behavior and response structure.""" + +import pytest + +from documentdb_tests.framework.assertions import assertResult, assertSuccessPartial +from documentdb_tests.framework.executor import execute_admin_command +from documentdb_tests.framework.property_checks import Exists, IsType + +pytestmark = pytest.mark.admin + + +def test_connectionStatus_returns_ok(collection): + """Test connectionStatus returns ok: 1.""" + result = execute_admin_command(collection, {"connectionStatus": 1}) + assertSuccessPartial(result, {"ok": 1.0}, msg="Should return ok: 1") + + +def test_connectionStatus_returns_authInfo(collection): + """Test connectionStatus returns authInfo document.""" + result = execute_admin_command(collection, {"connectionStatus": 1}) + assertResult( + result, expected={"authInfo": Exists()}, raw_res=True, msg="Should return authInfo" + ) + + +def test_connectionStatus_authInfo_has_authenticatedUsers(collection): + """Test connectionStatus returns authInfo.authenticatedUsers as an array.""" + result = execute_admin_command(collection, {"connectionStatus": 1}) + assertResult( + result, + expected={"authInfo": {"authenticatedUsers": IsType("array")}}, + raw_res=True, + msg="authenticatedUsers should be an array", + ) + + +def test_connectionStatus_authInfo_has_authenticatedUserRoles(collection): + """Test connectionStatus returns authInfo.authenticatedUserRoles as an array.""" + result = execute_admin_command(collection, {"connectionStatus": 1}) + assertResult( + result, + expected={"authInfo": {"authenticatedUserRoles": IsType("array")}}, + raw_res=True, + msg="authenticatedUserRoles should be an array", + ) + + +def test_connectionStatus_succeeds_on_any_database(collection): + """Test connectionStatus succeeds regardless of database context.""" + result = execute_admin_command(collection, {"connectionStatus": 1}) + assertSuccessPartial(result, {"ok": 1.0}, msg="Should succeed on admin db") diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_edge_cases.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_edge_cases.py new file mode 100644 index 00000000..f1c268f6 --- /dev/null +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_edge_cases.py @@ -0,0 +1,26 @@ +"""Tests for connectionStatus command edge cases.""" + +import pytest + +from documentdb_tests.framework.assertions import assertResult, assertSuccessPartial +from documentdb_tests.framework.executor import execute_admin_command +from documentdb_tests.framework.property_checks import IsType + +pytestmark = pytest.mark.admin + + +def test_connectionStatus_immediately_after_connect(collection): + """Test connectionStatus works immediately after connection.""" + result = execute_admin_command(collection, {"connectionStatus": 1}) + assertSuccessPartial(result, {"ok": 1.0}, msg="Should succeed immediately") + + +def test_connectionStatus_user_with_no_roles(collection): + """Test connectionStatus for connection without explicit roles returns arrays.""" + result = execute_admin_command(collection, {"connectionStatus": 1}) + assertResult( + result, + expected={"authInfo": {"authenticatedUserRoles": IsType("array")}}, + raw_res=True, + msg="authenticatedUserRoles should be array even with no roles", + ) diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_show_privileges.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_show_privileges.py new file mode 100644 index 00000000..1eee1f2c --- /dev/null +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_show_privileges.py @@ -0,0 +1,84 @@ +"""Tests for connectionStatus showPrivileges parameter.""" + +from __future__ import annotations + +from dataclasses import dataclass +from typing import Any + +import pytest +from bson import Decimal128, Int64 + +from documentdb_tests.framework.assertions import assertResult +from documentdb_tests.framework.executor import execute_admin_command +from documentdb_tests.framework.parametrize import pytest_params +from documentdb_tests.framework.property_checks import Exists, NotExists +from documentdb_tests.framework.test_case import BaseTestCase + +pytestmark = pytest.mark.admin + + +@dataclass(frozen=True) +class ShowPrivTruthyTest(BaseTestCase): + show_priv: Any = None + + +@dataclass(frozen=True) +class ShowPrivFalsyTest(BaseTestCase): + show_priv: Any = None + + +TRUTHY_TESTS: list[ShowPrivTruthyTest] = [ + ShowPrivTruthyTest("true", show_priv=True, msg="true should show privileges"), + ShowPrivTruthyTest("int_1", show_priv=1, msg="int 1 (truthy) should show privileges"), + ShowPrivTruthyTest("double_1", show_priv=1.0, msg="double 1.0 (truthy) should show"), + ShowPrivTruthyTest("long_1", show_priv=Int64(1), msg="long 1 (truthy) should show"), + ShowPrivTruthyTest("decimal128_1", show_priv=Decimal128("1"), msg="decimal128 1 should show"), +] + +FALSY_TESTS: list[ShowPrivFalsyTest] = [ + ShowPrivFalsyTest("false", show_priv=False, msg="false should hide privileges"), + ShowPrivFalsyTest("int_0", show_priv=0, msg="int 0 (falsy) should hide privileges"), + ShowPrivFalsyTest("double_0", show_priv=0.0, msg="double 0.0 (falsy) should hide"), + ShowPrivFalsyTest("long_0", show_priv=Int64(0), msg="long 0 (falsy) should hide"), + ShowPrivFalsyTest("decimal128_0", show_priv=Decimal128("0"), msg="decimal128 0 should hide"), + ShowPrivFalsyTest("null", show_priv=None, msg="null (falsy) should hide privileges"), +] + + +@pytest.mark.parametrize("test", pytest_params(TRUTHY_TESTS)) +def test_connectionStatus_show_privileges_truthy(collection, test): + """Test connectionStatus showPrivileges truthy values return privileges.""" + result = execute_admin_command( + collection, {"connectionStatus": 1, "showPrivileges": test.show_priv} + ) + assertResult( + result, + expected={"authInfo": {"authenticatedUserPrivileges": Exists()}}, + raw_res=True, + msg=test.msg, + ) + + +@pytest.mark.parametrize("test", pytest_params(FALSY_TESTS)) +def test_connectionStatus_show_privileges_falsy(collection, test): + """Test connectionStatus showPrivileges falsy values hide privileges.""" + result = execute_admin_command( + collection, {"connectionStatus": 1, "showPrivileges": test.show_priv} + ) + assertResult( + result, + expected={"authInfo": {"authenticatedUserPrivileges": NotExists()}}, + raw_res=True, + msg=test.msg, + ) + + +def test_connectionStatus_omit_showPrivileges(collection): + """Test omitting showPrivileges behaves same as showPrivileges: false.""" + result = execute_admin_command(collection, {"connectionStatus": 1}) + assertResult( + result, + expected={"authInfo": {"authenticatedUserPrivileges": NotExists()}}, + raw_res=True, + msg="Omitting showPrivileges should not return privileges", + ) From b6d7d9f85adc15bff3f36e4fd9998c969238cbd1 Mon Sep 17 00:00:00 2001 From: PatersonProjects Date: Mon, 25 May 2026 12:05:36 -0700 Subject: [PATCH 2/4] Removed duplicates, modified tests to use BaseTestCase child class, added missing coverage, reorganized tests for clarity Signed-off-by: PatersonProjects --- .../commands/connectionStatus/__init__.py | 0 ...st_connectionStatus_argument_validation.py | 12 +-- .../test_connectionStatus_auth_users.py | 58 ----------- .../test_connectionStatus_core_behavior.py | 51 ---------- .../test_connectionStatus_edge_cases.py | 26 ----- .../test_connectionStatus_errors.py | 99 +++++++++++++++++++ ...st_connectionStatus_response_validation.py | 85 ++++++++++++++++ .../test_connectionStatus_show_privileges.py | 68 ++++++------- .../tests/system/diagnostic/utils/__init__.py | 0 .../diagnostic/utils/diagnostic_test_case.py | 30 ++++++ 10 files changed, 250 insertions(+), 179 deletions(-) create mode 100644 documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/__init__.py delete mode 100644 documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_auth_users.py delete mode 100644 documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_core_behavior.py delete mode 100644 documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_edge_cases.py create mode 100644 documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_errors.py create mode 100644 documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_response_validation.py create mode 100644 documentdb_tests/compatibility/tests/system/diagnostic/utils/__init__.py create mode 100644 documentdb_tests/compatibility/tests/system/diagnostic/utils/diagnostic_test_case.py diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/__init__.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_argument_validation.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_argument_validation.py index 6fa28627..cc4547eb 100644 --- a/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_argument_validation.py +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_argument_validation.py @@ -9,8 +9,7 @@ import pytest from bson import Binary, Decimal128, Int64, MaxKey, MinKey, ObjectId, Regex, Timestamp -from documentdb_tests.framework.assertions import assertFailureCode, assertSuccessPartial -from documentdb_tests.framework.error_codes import UNRECOGNIZED_COMMAND_FIELD_ERROR +from documentdb_tests.framework.assertions import assertSuccessPartial from documentdb_tests.framework.executor import execute_admin_command from documentdb_tests.framework.parametrize import pytest_params from documentdb_tests.framework.test_case import BaseTestCase @@ -23,7 +22,6 @@ class ConnStatusArgTest(BaseTestCase): value: Any = None -# connectionStatus ignores the command field value — all types should succeed ARG_TYPE_TESTS: list[ConnStatusArgTest] = [ ConnStatusArgTest("int_1", value=1, msg="int should succeed"), ConnStatusArgTest("int_0", value=0, msg="int 0 should succeed"), @@ -53,11 +51,3 @@ def test_connectionStatus_accepts_any_type(collection, test): """Test connectionStatus accepts all BSON types for command field value.""" result = execute_admin_command(collection, {"connectionStatus": test.value}) assertSuccessPartial(result, {"ok": 1.0}, msg=test.msg) - - -def test_connectionStatus_unrecognized_field(collection): - """Test connectionStatus with unrecognized extra field returns error.""" - result = execute_admin_command(collection, {"connectionStatus": 1, "foo": 1}) - assertFailureCode( - result, UNRECOGNIZED_COMMAND_FIELD_ERROR, msg="Unrecognized field should error" - ) diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_auth_users.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_auth_users.py deleted file mode 100644 index af2b89e1..00000000 --- a/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_auth_users.py +++ /dev/null @@ -1,58 +0,0 @@ -"""Tests for connectionStatus authenticated users and roles. - -Note: Many auth-related tests require creating users with specific roles -and authenticating as them. These tests cover what's testable without -special RBAC setup (unauthenticated/default connection behavior). -""" - -import pytest - -from documentdb_tests.framework.assertions import assertResult -from documentdb_tests.framework.executor import execute_admin_command -from documentdb_tests.framework.property_checks import Exists, IsType - -pytestmark = pytest.mark.admin - - -def test_connectionStatus_authenticatedUsers_is_array(collection): - """Test authenticatedUsers is an array.""" - result = execute_admin_command(collection, {"connectionStatus": 1}) - assertResult( - result, - expected={"authInfo": {"authenticatedUsers": IsType("array")}}, - raw_res=True, - msg="authenticatedUsers should be array", - ) - - -def test_connectionStatus_authenticatedUserRoles_is_array(collection): - """Test authenticatedUserRoles is an array.""" - result = execute_admin_command(collection, {"connectionStatus": 1}) - assertResult( - result, - expected={"authInfo": {"authenticatedUserRoles": IsType("array")}}, - raw_res=True, - msg="authenticatedUserRoles should be array", - ) - - -def test_connectionStatus_showPrivileges_returns_privileges_array(collection): - """Test showPrivileges: true returns authenticatedUserPrivileges as array.""" - result = execute_admin_command(collection, {"connectionStatus": 1, "showPrivileges": True}) - assertResult( - result, - expected={"authInfo": {"authenticatedUserPrivileges": IsType("array")}}, - raw_res=True, - msg="authenticatedUserPrivileges should be array", - ) - - -def test_connectionStatus_authInfo_exists(collection): - """Test authInfo document is always present.""" - result = execute_admin_command(collection, {"connectionStatus": 1}) - assertResult( - result, - expected={"authInfo": Exists()}, - raw_res=True, - msg="authInfo should always exist", - ) diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_core_behavior.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_core_behavior.py deleted file mode 100644 index c89fbca5..00000000 --- a/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_core_behavior.py +++ /dev/null @@ -1,51 +0,0 @@ -"""Tests for connectionStatus command core behavior and response structure.""" - -import pytest - -from documentdb_tests.framework.assertions import assertResult, assertSuccessPartial -from documentdb_tests.framework.executor import execute_admin_command -from documentdb_tests.framework.property_checks import Exists, IsType - -pytestmark = pytest.mark.admin - - -def test_connectionStatus_returns_ok(collection): - """Test connectionStatus returns ok: 1.""" - result = execute_admin_command(collection, {"connectionStatus": 1}) - assertSuccessPartial(result, {"ok": 1.0}, msg="Should return ok: 1") - - -def test_connectionStatus_returns_authInfo(collection): - """Test connectionStatus returns authInfo document.""" - result = execute_admin_command(collection, {"connectionStatus": 1}) - assertResult( - result, expected={"authInfo": Exists()}, raw_res=True, msg="Should return authInfo" - ) - - -def test_connectionStatus_authInfo_has_authenticatedUsers(collection): - """Test connectionStatus returns authInfo.authenticatedUsers as an array.""" - result = execute_admin_command(collection, {"connectionStatus": 1}) - assertResult( - result, - expected={"authInfo": {"authenticatedUsers": IsType("array")}}, - raw_res=True, - msg="authenticatedUsers should be an array", - ) - - -def test_connectionStatus_authInfo_has_authenticatedUserRoles(collection): - """Test connectionStatus returns authInfo.authenticatedUserRoles as an array.""" - result = execute_admin_command(collection, {"connectionStatus": 1}) - assertResult( - result, - expected={"authInfo": {"authenticatedUserRoles": IsType("array")}}, - raw_res=True, - msg="authenticatedUserRoles should be an array", - ) - - -def test_connectionStatus_succeeds_on_any_database(collection): - """Test connectionStatus succeeds regardless of database context.""" - result = execute_admin_command(collection, {"connectionStatus": 1}) - assertSuccessPartial(result, {"ok": 1.0}, msg="Should succeed on admin db") diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_edge_cases.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_edge_cases.py deleted file mode 100644 index f1c268f6..00000000 --- a/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_edge_cases.py +++ /dev/null @@ -1,26 +0,0 @@ -"""Tests for connectionStatus command edge cases.""" - -import pytest - -from documentdb_tests.framework.assertions import assertResult, assertSuccessPartial -from documentdb_tests.framework.executor import execute_admin_command -from documentdb_tests.framework.property_checks import IsType - -pytestmark = pytest.mark.admin - - -def test_connectionStatus_immediately_after_connect(collection): - """Test connectionStatus works immediately after connection.""" - result = execute_admin_command(collection, {"connectionStatus": 1}) - assertSuccessPartial(result, {"ok": 1.0}, msg="Should succeed immediately") - - -def test_connectionStatus_user_with_no_roles(collection): - """Test connectionStatus for connection without explicit roles returns arrays.""" - result = execute_admin_command(collection, {"connectionStatus": 1}) - assertResult( - result, - expected={"authInfo": {"authenticatedUserRoles": IsType("array")}}, - raw_res=True, - msg="authenticatedUserRoles should be array even with no roles", - ) diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_errors.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_errors.py new file mode 100644 index 00000000..19aceb4b --- /dev/null +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_errors.py @@ -0,0 +1,99 @@ +"""Tests for connectionStatus command error conditions. + +Validates that invalid usages of connectionStatus produce appropriate errors. +""" + +from datetime import datetime, timezone + +import pytest +from bson import MaxKey, MinKey, ObjectId + +from documentdb_tests.compatibility.tests.system.diagnostic.utils.diagnostic_test_case import ( + DiagnosticErrorTest, +) +from documentdb_tests.framework.assertions import assertFailureCode +from documentdb_tests.framework.error_codes import ( + TYPE_MISMATCH_ERROR, + UNRECOGNIZED_COMMAND_FIELD_ERROR, +) +from documentdb_tests.framework.executor import execute_admin_command, execute_command +from documentdb_tests.framework.parametrize import pytest_params + +pytestmark = pytest.mark.admin + + +ERROR_TESTS: list[DiagnosticErrorTest] = [ + DiagnosticErrorTest( + id="unrecognized_field", + command={"connectionStatus": 1, "foo": 1}, + error_code=UNRECOGNIZED_COMMAND_FIELD_ERROR, + msg="Unrecognized field should error", + ), + DiagnosticErrorTest( + id="showPrivileges_string_type_mismatch", + command={"connectionStatus": 1, "showPrivileges": "yes"}, + error_code=TYPE_MISMATCH_ERROR, + msg="showPrivileges string should be rejected as wrong type", + ), + DiagnosticErrorTest( + id="showPrivileges_empty_string_type_mismatch", + command={"connectionStatus": 1, "showPrivileges": ""}, + error_code=TYPE_MISMATCH_ERROR, + msg="showPrivileges empty string should be rejected as wrong type", + ), + DiagnosticErrorTest( + id="showPrivileges_string_false_type_mismatch", + command={"connectionStatus": 1, "showPrivileges": "false"}, + error_code=TYPE_MISMATCH_ERROR, + msg="showPrivileges string 'false' should be rejected as wrong type", + ), + DiagnosticErrorTest( + id="showPrivileges_array_type_mismatch", + command={"connectionStatus": 1, "showPrivileges": [1]}, + error_code=TYPE_MISMATCH_ERROR, + msg="showPrivileges array should be rejected as wrong type", + ), + DiagnosticErrorTest( + id="showPrivileges_object_type_mismatch", + command={"connectionStatus": 1, "showPrivileges": {"a": 1}}, + error_code=TYPE_MISMATCH_ERROR, + msg="showPrivileges object should be rejected as wrong type", + ), + DiagnosticErrorTest( + id="showPrivileges_date_type_mismatch", + command={ + "connectionStatus": 1, + "showPrivileges": datetime(2024, 1, 1, tzinfo=timezone.utc), + }, + error_code=TYPE_MISMATCH_ERROR, + msg="showPrivileges date should be rejected as wrong type", + ), + DiagnosticErrorTest( + id="showPrivileges_objectId_type_mismatch", + command={"connectionStatus": 1, "showPrivileges": ObjectId()}, + error_code=TYPE_MISMATCH_ERROR, + msg="showPrivileges objectId should be rejected as wrong type", + ), + DiagnosticErrorTest( + id="showPrivileges_minKey_type_mismatch", + command={"connectionStatus": 1, "showPrivileges": MinKey()}, + error_code=TYPE_MISMATCH_ERROR, + msg="showPrivileges minKey should be rejected as wrong type", + ), + DiagnosticErrorTest( + id="showPrivileges_maxKey_type_mismatch", + command={"connectionStatus": 1, "showPrivileges": MaxKey()}, + error_code=TYPE_MISMATCH_ERROR, + msg="showPrivileges maxKey should be rejected as wrong type", + ), +] + + +@pytest.mark.parametrize("test", pytest_params(ERROR_TESTS)) +def test_connectionStatus_error_conditions(collection, test): + """Verifies connectionStatus rejects invalid usages with appropriate error codes.""" + if test.use_admin: + result = execute_admin_command(collection, test.command) + else: + result = execute_command(collection, test.command) + assertFailureCode(result, test.error_code, msg=test.msg) diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_response_validation.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_response_validation.py new file mode 100644 index 00000000..a3679b44 --- /dev/null +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_response_validation.py @@ -0,0 +1,85 @@ +"""Tests for connectionStatus response structure validation. + +Validates response fields, types, and auth-related properties. +Note: Many auth-related tests require creating users with specific roles +and authenticating as them. These tests cover what's testable without +special RBAC setup (unauthenticated/default connection behavior). +""" + +import pytest + +from documentdb_tests.compatibility.tests.system.diagnostic.utils.diagnostic_test_case import ( + DiagnosticPropertyTest, +) +from documentdb_tests.framework.assertions import assertProperties, assertResult +from documentdb_tests.framework.executor import execute_admin_command, execute_command +from documentdb_tests.framework.parametrize import pytest_params +from documentdb_tests.framework.property_checks import Eq, Exists, IsType, Len + +pytestmark = pytest.mark.admin + + +RESPONSE_PROPERTY_TESTS: list[DiagnosticPropertyTest] = [ + DiagnosticPropertyTest( + id="authenticatedUsers_is_array", + checks={"authInfo": {"authenticatedUsers": IsType("array")}}, + msg="authenticatedUsers should be array", + ), + DiagnosticPropertyTest( + id="authenticatedUserRoles_is_array", + checks={"authInfo": {"authenticatedUserRoles": IsType("array")}}, + msg="authenticatedUserRoles should be array", + ), + DiagnosticPropertyTest( + id="authInfo_exists", + checks={"authInfo": Exists()}, + msg="authInfo should always exist", + ), + DiagnosticPropertyTest( + id="unauthenticated_users_empty", + checks={"authInfo": {"authenticatedUsers": Len(0)}}, + msg="without auth, authenticatedUsers should be empty", + ), + DiagnosticPropertyTest( + id="unauthenticated_roles_empty", + checks={"authInfo": {"authenticatedUserRoles": Len(0)}}, + msg="without auth, authenticatedUserRoles should be empty", + ), + DiagnosticPropertyTest( + id="uuid_is_binData", + checks={"uuid": IsType("binData")}, + msg="uuid should be a binData (UUID) field", + ), +] + + +@pytest.mark.parametrize("test", pytest_params(RESPONSE_PROPERTY_TESTS)) +def test_connectionStatus_response_properties(collection, test): + """Verifies connectionStatus response fields and types.""" + result = execute_admin_command(collection, {"connectionStatus": 1}) + assertProperties(result, test.checks, msg=test.msg, raw_res=True) + + +def test_connectionStatus_succeeds_on_nonexistent_database(collection): + """Test connectionStatus succeeds on a non-existent database.""" + other_col = collection.database.client["nonexistent_db_for_connstatus_test"]["dummy"] + result = execute_command(other_col, {"connectionStatus": 1}) + assertProperties( + result, + {"ok": Exists(), "authInfo": Exists()}, + msg="connectionStatus should succeed on non-existent database", + raw_res=True, + ) + + +def test_connectionStatus_same_result_across_databases(collection): + """Test connectionStatus returns same authInfo on admin vs other database.""" + admin_result = execute_admin_command(collection, {"connectionStatus": 1}) + other_col = collection.database.client["nonexistent_db_for_connstatus_test"]["dummy"] + other_result = execute_command(other_col, {"connectionStatus": 1}) + assertResult( + other_result, + expected={"authInfo": Eq(admin_result["authInfo"])}, + msg="authInfo should be identical across databases", + raw_res=True, + ) diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_show_privileges.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_show_privileges.py index 1eee1f2c..a0bef282 100644 --- a/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_show_privileges.py +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_show_privileges.py @@ -8,40 +8,46 @@ import pytest from bson import Decimal128, Int64 -from documentdb_tests.framework.assertions import assertResult +from documentdb_tests.compatibility.tests.system.diagnostic.utils.diagnostic_test_case import ( + DiagnosticPropertyTest, +) +from documentdb_tests.framework.assertions import assertProperties from documentdb_tests.framework.executor import execute_admin_command from documentdb_tests.framework.parametrize import pytest_params -from documentdb_tests.framework.property_checks import Exists, NotExists +from documentdb_tests.framework.property_checks import IsType, NotExists from documentdb_tests.framework.test_case import BaseTestCase pytestmark = pytest.mark.admin @dataclass(frozen=True) -class ShowPrivTruthyTest(BaseTestCase): +class ShowPrivTest(BaseTestCase): show_priv: Any = None -@dataclass(frozen=True) -class ShowPrivFalsyTest(BaseTestCase): - show_priv: Any = None - +TRUTHY_TESTS: list[ShowPrivTest] = [ + ShowPrivTest("true", show_priv=True, msg="true should show privileges"), + ShowPrivTest("int_1", show_priv=1, msg="int 1 (truthy) should show privileges"), + ShowPrivTest("double_1", show_priv=1.0, msg="double 1.0 (truthy) should show"), + ShowPrivTest("long_1", show_priv=Int64(1), msg="long 1 (truthy) should show"), + ShowPrivTest("decimal128_1", show_priv=Decimal128("1"), msg="decimal128 1 should show"), +] -TRUTHY_TESTS: list[ShowPrivTruthyTest] = [ - ShowPrivTruthyTest("true", show_priv=True, msg="true should show privileges"), - ShowPrivTruthyTest("int_1", show_priv=1, msg="int 1 (truthy) should show privileges"), - ShowPrivTruthyTest("double_1", show_priv=1.0, msg="double 1.0 (truthy) should show"), - ShowPrivTruthyTest("long_1", show_priv=Int64(1), msg="long 1 (truthy) should show"), - ShowPrivTruthyTest("decimal128_1", show_priv=Decimal128("1"), msg="decimal128 1 should show"), +FALSY_TESTS: list[ShowPrivTest] = [ + ShowPrivTest("false", show_priv=False, msg="false should hide privileges"), + ShowPrivTest("int_0", show_priv=0, msg="int 0 (falsy) should hide privileges"), + ShowPrivTest("double_0", show_priv=0.0, msg="double 0.0 (falsy) should hide"), + ShowPrivTest("long_0", show_priv=Int64(0), msg="long 0 (falsy) should hide"), + ShowPrivTest("decimal128_0", show_priv=Decimal128("0"), msg="decimal128 0 should hide"), + ShowPrivTest("null", show_priv=None, msg="null (falsy) should hide privileges"), ] -FALSY_TESTS: list[ShowPrivFalsyTest] = [ - ShowPrivFalsyTest("false", show_priv=False, msg="false should hide privileges"), - ShowPrivFalsyTest("int_0", show_priv=0, msg="int 0 (falsy) should hide privileges"), - ShowPrivFalsyTest("double_0", show_priv=0.0, msg="double 0.0 (falsy) should hide"), - ShowPrivFalsyTest("long_0", show_priv=Int64(0), msg="long 0 (falsy) should hide"), - ShowPrivFalsyTest("decimal128_0", show_priv=Decimal128("0"), msg="decimal128 0 should hide"), - ShowPrivFalsyTest("null", show_priv=None, msg="null (falsy) should hide privileges"), +OMIT_TESTS: list[DiagnosticPropertyTest] = [ + DiagnosticPropertyTest( + id="omit_showPrivileges", + checks={"authInfo": {"authenticatedUserPrivileges": NotExists()}}, + msg="Omitting showPrivileges should not return privileges", + ), ] @@ -51,11 +57,11 @@ def test_connectionStatus_show_privileges_truthy(collection, test): result = execute_admin_command( collection, {"connectionStatus": 1, "showPrivileges": test.show_priv} ) - assertResult( + assertProperties( result, - expected={"authInfo": {"authenticatedUserPrivileges": Exists()}}, - raw_res=True, + {"authInfo": {"authenticatedUserPrivileges": IsType("array")}}, msg=test.msg, + raw_res=True, ) @@ -65,20 +71,16 @@ def test_connectionStatus_show_privileges_falsy(collection, test): result = execute_admin_command( collection, {"connectionStatus": 1, "showPrivileges": test.show_priv} ) - assertResult( + assertProperties( result, - expected={"authInfo": {"authenticatedUserPrivileges": NotExists()}}, - raw_res=True, + {"authInfo": {"authenticatedUserPrivileges": NotExists()}}, msg=test.msg, + raw_res=True, ) -def test_connectionStatus_omit_showPrivileges(collection): +@pytest.mark.parametrize("test", pytest_params(OMIT_TESTS)) +def test_connectionStatus_omit_showPrivileges(collection, test): """Test omitting showPrivileges behaves same as showPrivileges: false.""" result = execute_admin_command(collection, {"connectionStatus": 1}) - assertResult( - result, - expected={"authInfo": {"authenticatedUserPrivileges": NotExists()}}, - raw_res=True, - msg="Omitting showPrivileges should not return privileges", - ) + assertProperties(result, test.checks, msg=test.msg, raw_res=True) diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/utils/__init__.py b/documentdb_tests/compatibility/tests/system/diagnostic/utils/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/utils/diagnostic_test_case.py b/documentdb_tests/compatibility/tests/system/diagnostic/utils/diagnostic_test_case.py new file mode 100644 index 00000000..10b620e8 --- /dev/null +++ b/documentdb_tests/compatibility/tests/system/diagnostic/utils/diagnostic_test_case.py @@ -0,0 +1,30 @@ +"""Shared test cases for diagnostic command tests.""" + +from dataclasses import dataclass, field +from typing import Any, Dict, Optional + +from documentdb_tests.framework.test_case import BaseTestCase + + +@dataclass(frozen=True) +class DiagnosticErrorTest(BaseTestCase): + """Test case for diagnostic command error conditions. + + Attributes: + command: The command document to execute. + use_admin: If True, execute against the admin database. + """ + + command: Optional[Dict[str, Any]] = None + use_admin: bool = True + + +@dataclass(frozen=True) +class DiagnosticPropertyTest(BaseTestCase): + """Test case for diagnostic command response property checks. + + Attributes: + checks: Mapping of dotted field paths to property check objects. + """ + + checks: Dict[str, Any] = field(default_factory=dict) From e5da9d4111c29bb0355f4848f339cdb0bbcd4182 Mon Sep 17 00:00:00 2001 From: PatersonProjects Date: Mon, 25 May 2026 14:50:08 -0700 Subject: [PATCH 3/4] Docstring edits Signed-off-by: PatersonProjects --- ...st_connectionStatus_argument_validation.py | 9 +++++++-- .../test_connectionStatus_errors.py | 8 ++++++-- ...st_connectionStatus_response_validation.py | 20 ++++++++++++------- .../test_connectionStatus_show_privileges.py | 15 ++++++++++---- .../test_smoke_connectionStatus.py | 4 ++-- 5 files changed, 39 insertions(+), 17 deletions(-) diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_argument_validation.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_argument_validation.py index cc4547eb..116b7096 100644 --- a/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_argument_validation.py +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_argument_validation.py @@ -1,4 +1,9 @@ -"""Tests for connectionStatus command argument validation.""" +"""Tests for connectionStatus command argument validation. + +Verifies that connectionStatus accepts all 18 BSON types (int, double, long, +decimal128, string, bool, date, null, object, array, binData, objectId, regex, +timestamp, minKey, maxKey) as the command field value and returns ok: 1 for each. +""" from __future__ import annotations @@ -48,6 +53,6 @@ class ConnStatusArgTest(BaseTestCase): @pytest.mark.parametrize("test", pytest_params(ARG_TYPE_TESTS)) def test_connectionStatus_accepts_any_type(collection, test): - """Test connectionStatus accepts all BSON types for command field value.""" + """Verify connectionStatus succeeds when the command field value is a given BSON type.""" result = execute_admin_command(collection, {"connectionStatus": test.value}) assertSuccessPartial(result, {"ok": 1.0}, msg=test.msg) diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_errors.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_errors.py index 19aceb4b..a14bad18 100644 --- a/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_errors.py +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_errors.py @@ -1,6 +1,10 @@ """Tests for connectionStatus command error conditions. -Validates that invalid usages of connectionStatus produce appropriate errors. +Verifies that connectionStatus rejects invalid inputs with the correct error +codes. Covers unrecognized fields (UNRECOGNIZED_COMMAND_FIELD_ERROR) and +showPrivileges type-mismatch errors (TYPE_MISMATCH_ERROR) for non-boolean, +non-numeric BSON types: string, empty string, "false" string, array, object, +date, objectId, minKey, and maxKey. """ from datetime import datetime, timezone @@ -91,7 +95,7 @@ @pytest.mark.parametrize("test", pytest_params(ERROR_TESTS)) def test_connectionStatus_error_conditions(collection, test): - """Verifies connectionStatus rejects invalid usages with appropriate error codes.""" + """Verify connectionStatus returns the expected error code for an invalid input.""" if test.use_admin: result = execute_admin_command(collection, test.command) else: diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_response_validation.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_response_validation.py index a3679b44..cb9c2e5e 100644 --- a/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_response_validation.py +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_response_validation.py @@ -1,9 +1,15 @@ """Tests for connectionStatus response structure validation. -Validates response fields, types, and auth-related properties. -Note: Many auth-related tests require creating users with specific roles -and authenticating as them. These tests cover what's testable without -special RBAC setup (unauthenticated/default connection behavior). +Validates the shape of the connectionStatus response on an unauthenticated +connection: authInfo exists, authenticatedUsers and authenticatedUserRoles +are arrays (and empty without auth), and the uuid field is binData. + +Also verifies cross-database behavior: the command succeeds when run against +a non-existent database and returns identical authInfo regardless of which +database it is executed on. + +Note: Sub-document field validation (user, db, role entries) requires +creating users with specific roles and is not covered here. """ import pytest @@ -55,13 +61,13 @@ @pytest.mark.parametrize("test", pytest_params(RESPONSE_PROPERTY_TESTS)) def test_connectionStatus_response_properties(collection, test): - """Verifies connectionStatus response fields and types.""" + """Verify a response field exists and has the expected type.""" result = execute_admin_command(collection, {"connectionStatus": 1}) assertProperties(result, test.checks, msg=test.msg, raw_res=True) def test_connectionStatus_succeeds_on_nonexistent_database(collection): - """Test connectionStatus succeeds on a non-existent database.""" + """Verify connectionStatus returns ok and authInfo when run on a non-existent database.""" other_col = collection.database.client["nonexistent_db_for_connstatus_test"]["dummy"] result = execute_command(other_col, {"connectionStatus": 1}) assertProperties( @@ -73,7 +79,7 @@ def test_connectionStatus_succeeds_on_nonexistent_database(collection): def test_connectionStatus_same_result_across_databases(collection): - """Test connectionStatus returns same authInfo on admin vs other database.""" + """Verify authInfo is identical whether run on admin or a different database.""" admin_result = execute_admin_command(collection, {"connectionStatus": 1}) other_col = collection.database.client["nonexistent_db_for_connstatus_test"]["dummy"] other_result = execute_command(other_col, {"connectionStatus": 1}) diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_show_privileges.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_show_privileges.py index a0bef282..12e08c67 100644 --- a/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_show_privileges.py +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_show_privileges.py @@ -1,4 +1,11 @@ -"""Tests for connectionStatus showPrivileges parameter.""" +"""Tests for connectionStatus showPrivileges parameter. + +Verifies the truthy/falsy/omit behavior of the showPrivileges field. +Truthy values (true, int 1, double 1.0, long 1, decimal128 1) should cause +authenticatedUserPrivileges to appear as an array. Falsy values (false, +int 0, double 0.0, long 0, decimal128 0, null) and omitting the field +entirely should exclude authenticatedUserPrivileges from the response. +""" from __future__ import annotations @@ -53,7 +60,7 @@ class ShowPrivTest(BaseTestCase): @pytest.mark.parametrize("test", pytest_params(TRUTHY_TESTS)) def test_connectionStatus_show_privileges_truthy(collection, test): - """Test connectionStatus showPrivileges truthy values return privileges.""" + """Verify a truthy showPrivileges value includes authenticatedUserPrivileges as an array.""" result = execute_admin_command( collection, {"connectionStatus": 1, "showPrivileges": test.show_priv} ) @@ -67,7 +74,7 @@ def test_connectionStatus_show_privileges_truthy(collection, test): @pytest.mark.parametrize("test", pytest_params(FALSY_TESTS)) def test_connectionStatus_show_privileges_falsy(collection, test): - """Test connectionStatus showPrivileges falsy values hide privileges.""" + """Verify a falsy showPrivileges value excludes authenticatedUserPrivileges.""" result = execute_admin_command( collection, {"connectionStatus": 1, "showPrivileges": test.show_priv} ) @@ -81,6 +88,6 @@ def test_connectionStatus_show_privileges_falsy(collection, test): @pytest.mark.parametrize("test", pytest_params(OMIT_TESTS)) def test_connectionStatus_omit_showPrivileges(collection, test): - """Test omitting showPrivileges behaves same as showPrivileges: false.""" + """Verify omitting showPrivileges excludes authenticatedUserPrivileges (same as false).""" result = execute_admin_command(collection, {"connectionStatus": 1}) assertProperties(result, test.checks, msg=test.msg, raw_res=True) diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_smoke_connectionStatus.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_smoke_connectionStatus.py index 612a9388..2cd7fc2a 100644 --- a/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_smoke_connectionStatus.py +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_smoke_connectionStatus.py @@ -1,7 +1,7 @@ """ Smoke test for connectionStatus command. -Tests basic connectionStatus command functionality. +Verifies the command executes successfully and returns ok: 1. """ import pytest @@ -13,7 +13,7 @@ def test_smoke_connectionStatus(collection): - """Test basic connectionStatus command behavior.""" + """Verify connectionStatus executes successfully and returns ok: 1.""" result = execute_admin_command(collection, {"connectionStatus": 1}) expected = {"ok": 1.0} From 8d21cae351a9b88ac4f4b258d209728e7256f5cf Mon Sep 17 00:00:00 2001 From: PatersonProjects Date: Tue, 26 May 2026 14:05:14 -0700 Subject: [PATCH 4/4] Addressed PR Comments Signed-off-by: PatersonProjects --- ...st_connectionStatus_argument_validation.py | 10 +++--- .../test_connectionStatus_errors.py | 31 ++++++++++++++++--- .../test_connectionStatus_show_privileges.py | 4 +-- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_argument_validation.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_argument_validation.py index 116b7096..8dcb35b9 100644 --- a/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_argument_validation.py +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_argument_validation.py @@ -1,18 +1,15 @@ """Tests for connectionStatus command argument validation. -Verifies that connectionStatus accepts all 18 BSON types (int, double, long, -decimal128, string, bool, date, null, object, array, binData, objectId, regex, -timestamp, minKey, maxKey) as the command field value and returns ok: 1 for each. +Verifies that connectionStatus accepts all BSON types as the command field +value and returns ok: 1 for each. """ -from __future__ import annotations - from dataclasses import dataclass from datetime import datetime, timezone from typing import Any import pytest -from bson import Binary, Decimal128, Int64, MaxKey, MinKey, ObjectId, Regex, Timestamp +from bson import Binary, Code, Decimal128, Int64, MaxKey, MinKey, ObjectId, Regex, Timestamp from documentdb_tests.framework.assertions import assertSuccessPartial from documentdb_tests.framework.executor import execute_admin_command @@ -48,6 +45,7 @@ class ConnStatusArgTest(BaseTestCase): ConnStatusArgTest("timestamp", value=Timestamp(0, 0), msg="timestamp should succeed"), ConnStatusArgTest("minKey", value=MinKey(), msg="minKey should succeed"), ConnStatusArgTest("maxKey", value=MaxKey(), msg="maxKey should succeed"), + ConnStatusArgTest("code", value=Code("function(){}"), msg="code should succeed"), ] diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_errors.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_errors.py index a14bad18..2e2af06e 100644 --- a/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_errors.py +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_errors.py @@ -2,15 +2,14 @@ Verifies that connectionStatus rejects invalid inputs with the correct error codes. Covers unrecognized fields (UNRECOGNIZED_COMMAND_FIELD_ERROR) and -showPrivileges type-mismatch errors (TYPE_MISMATCH_ERROR) for non-boolean, -non-numeric BSON types: string, empty string, "false" string, array, object, -date, objectId, minKey, and maxKey. +showPrivileges type-mismatch errors (TYPE_MISMATCH_ERROR) for all non-boolean, +non-numeric BSON types. """ from datetime import datetime, timezone import pytest -from bson import MaxKey, MinKey, ObjectId +from bson import Binary, Code, MaxKey, MinKey, ObjectId, Regex, Timestamp from documentdb_tests.compatibility.tests.system.diagnostic.utils.diagnostic_test_case import ( DiagnosticErrorTest, @@ -90,6 +89,30 @@ error_code=TYPE_MISMATCH_ERROR, msg="showPrivileges maxKey should be rejected as wrong type", ), + DiagnosticErrorTest( + id="showPrivileges_binData_type_mismatch", + command={"connectionStatus": 1, "showPrivileges": Binary(b"")}, + error_code=TYPE_MISMATCH_ERROR, + msg="showPrivileges binData should be rejected as wrong type", + ), + DiagnosticErrorTest( + id="showPrivileges_regex_type_mismatch", + command={"connectionStatus": 1, "showPrivileges": Regex("test")}, + error_code=TYPE_MISMATCH_ERROR, + msg="showPrivileges regex should be rejected as wrong type", + ), + DiagnosticErrorTest( + id="showPrivileges_timestamp_type_mismatch", + command={"connectionStatus": 1, "showPrivileges": Timestamp(0, 0)}, + error_code=TYPE_MISMATCH_ERROR, + msg="showPrivileges timestamp should be rejected as wrong type", + ), + DiagnosticErrorTest( + id="showPrivileges_code_type_mismatch", + command={"connectionStatus": 1, "showPrivileges": Code("function(){}")}, + error_code=TYPE_MISMATCH_ERROR, + msg="showPrivileges code should be rejected as wrong type", + ), ] diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_show_privileges.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_show_privileges.py index 12e08c67..6440ac7a 100644 --- a/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_show_privileges.py +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/connectionStatus/test_connectionStatus_show_privileges.py @@ -7,8 +7,6 @@ entirely should exclude authenticatedUserPrivileges from the response. """ -from __future__ import annotations - from dataclasses import dataclass from typing import Any @@ -38,6 +36,8 @@ class ShowPrivTest(BaseTestCase): ShowPrivTest("double_1", show_priv=1.0, msg="double 1.0 (truthy) should show"), ShowPrivTest("long_1", show_priv=Int64(1), msg="long 1 (truthy) should show"), ShowPrivTest("decimal128_1", show_priv=Decimal128("1"), msg="decimal128 1 should show"), + ShowPrivTest("int_neg1", show_priv=-1, msg="int -1 (truthy) should show privileges"), + ShowPrivTest("double_neg1", show_priv=-1.0, msg="double -1.0 (truthy) should show"), ] FALSY_TESTS: list[ShowPrivTest] = [