mcp-security-framework 1.1.0__py3-none-any.whl → 1.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mcp_security_framework/__init__.py +26 -15
- mcp_security_framework/cli/__init__.py +1 -1
- mcp_security_framework/cli/cert_cli.py +233 -197
- mcp_security_framework/cli/security_cli.py +324 -234
- mcp_security_framework/constants.py +21 -27
- mcp_security_framework/core/auth_manager.py +41 -22
- mcp_security_framework/core/cert_manager.py +210 -147
- mcp_security_framework/core/permission_manager.py +9 -9
- mcp_security_framework/core/rate_limiter.py +2 -2
- mcp_security_framework/core/security_manager.py +284 -229
- mcp_security_framework/examples/__init__.py +6 -0
- mcp_security_framework/examples/comprehensive_example.py +349 -279
- mcp_security_framework/examples/django_example.py +247 -206
- mcp_security_framework/examples/fastapi_example.py +315 -283
- mcp_security_framework/examples/flask_example.py +274 -203
- mcp_security_framework/examples/gateway_example.py +304 -237
- mcp_security_framework/examples/microservice_example.py +258 -189
- mcp_security_framework/examples/standalone_example.py +255 -230
- mcp_security_framework/examples/test_all_examples.py +151 -135
- mcp_security_framework/middleware/__init__.py +46 -55
- mcp_security_framework/middleware/auth_middleware.py +62 -63
- mcp_security_framework/middleware/fastapi_auth_middleware.py +119 -118
- mcp_security_framework/middleware/fastapi_middleware.py +156 -148
- mcp_security_framework/middleware/flask_auth_middleware.py +160 -147
- mcp_security_framework/middleware/flask_middleware.py +183 -157
- mcp_security_framework/middleware/mtls_middleware.py +106 -117
- mcp_security_framework/middleware/rate_limit_middleware.py +105 -101
- mcp_security_framework/middleware/security_middleware.py +109 -124
- mcp_security_framework/schemas/config.py +2 -1
- mcp_security_framework/schemas/models.py +18 -6
- mcp_security_framework/utils/cert_utils.py +14 -8
- mcp_security_framework/utils/datetime_compat.py +116 -0
- {mcp_security_framework-1.1.0.dist-info → mcp_security_framework-1.1.1.dist-info}/METADATA +2 -1
- mcp_security_framework-1.1.1.dist-info/RECORD +84 -0
- tests/conftest.py +63 -66
- tests/test_cli/test_cert_cli.py +184 -146
- tests/test_cli/test_security_cli.py +274 -247
- tests/test_core/test_cert_manager.py +24 -10
- tests/test_core/test_security_manager.py +2 -2
- tests/test_examples/test_comprehensive_example.py +190 -137
- tests/test_examples/test_fastapi_example.py +124 -101
- tests/test_examples/test_flask_example.py +124 -101
- tests/test_examples/test_standalone_example.py +73 -80
- tests/test_integration/test_auth_flow.py +213 -197
- tests/test_integration/test_certificate_flow.py +180 -149
- tests/test_integration/test_fastapi_integration.py +108 -111
- tests/test_integration/test_flask_integration.py +141 -140
- tests/test_integration/test_standalone_integration.py +290 -259
- tests/test_middleware/test_fastapi_auth_middleware.py +195 -174
- tests/test_middleware/test_fastapi_middleware.py +147 -132
- tests/test_middleware/test_flask_auth_middleware.py +260 -202
- tests/test_middleware/test_flask_middleware.py +201 -179
- tests/test_middleware/test_security_middleware.py +145 -130
- tests/test_utils/test_datetime_compat.py +147 -0
- mcp_security_framework-1.1.0.dist-info/RECORD +0 -82
- {mcp_security_framework-1.1.0.dist-info → mcp_security_framework-1.1.1.dist-info}/WHEEL +0 -0
- {mcp_security_framework-1.1.0.dist-info → mcp_security_framework-1.1.1.dist-info}/entry_points.txt +0 -0
- {mcp_security_framework-1.1.0.dist-info → mcp_security_framework-1.1.1.dist-info}/top_level.txt +0 -0
@@ -98,7 +98,8 @@ class TestCertificateManager:
|
|
98
98
|
"""Test initialization with missing CA certificate."""
|
99
99
|
config = CertificateConfig(
|
100
100
|
enabled=True,
|
101
|
-
ca_cert_path="/nonexistent/ca.crt",
|
101
|
+
ca_cert_path="/nonexistent/ca.crt",
|
102
|
+
ca_key_path=self.ca_key_path,
|
102
103
|
)
|
103
104
|
|
104
105
|
with pytest.raises(CertificateConfigurationError) as exc_info:
|
@@ -110,7 +111,8 @@ class TestCertificateManager:
|
|
110
111
|
"""Test initialization with missing CA key."""
|
111
112
|
config = CertificateConfig(
|
112
113
|
enabled=True,
|
113
|
-
ca_cert_path=self.ca_cert_path,
|
114
|
+
ca_cert_path=self.ca_cert_path,
|
115
|
+
ca_key_path="/nonexistent/ca.key",
|
114
116
|
)
|
115
117
|
|
116
118
|
with pytest.raises(CertificateConfigurationError) as exc_info:
|
@@ -139,9 +141,9 @@ class TestCertificateManager:
|
|
139
141
|
mock_cert = Mock()
|
140
142
|
mock_cert.serial_number = 123456789
|
141
143
|
mock_cert.not_valid_before_utc = datetime.now(timezone.utc)
|
142
|
-
mock_cert.not_valid_after_utc = datetime.now(
|
143
|
-
|
144
|
-
)
|
144
|
+
mock_cert.not_valid_after_utc = datetime.now(
|
145
|
+
timezone.utc
|
146
|
+
) + timedelta(days=3650)
|
145
147
|
mock_cert.public_bytes.return_value = b"-----BEGIN CERTIFICATE-----\nMOCK CERT\n-----END CERTIFICATE-----"
|
146
148
|
|
147
149
|
mock_private_key = Mock()
|
@@ -239,7 +241,9 @@ class TestCertificateManager:
|
|
239
241
|
# Mock the certificate building process
|
240
242
|
mock_cert = Mock()
|
241
243
|
mock_cert.serial_number = 987654321
|
242
|
-
mock_cert.not_valid_before_utc = datetime.now(
|
244
|
+
mock_cert.not_valid_before_utc = datetime.now(
|
245
|
+
timezone.utc
|
246
|
+
)
|
243
247
|
mock_cert.not_valid_after_utc = datetime.now(
|
244
248
|
timezone.utc
|
245
249
|
) + timedelta(days=365)
|
@@ -340,7 +344,9 @@ class TestCertificateManager:
|
|
340
344
|
# Mock the certificate building process
|
341
345
|
mock_cert = Mock()
|
342
346
|
mock_cert.serial_number = 555666777
|
343
|
-
mock_cert.not_valid_before_utc = datetime.now(
|
347
|
+
mock_cert.not_valid_before_utc = datetime.now(
|
348
|
+
timezone.utc
|
349
|
+
)
|
344
350
|
mock_cert.not_valid_after_utc = datetime.now(
|
345
351
|
timezone.utc
|
346
352
|
) + timedelta(days=365)
|
@@ -600,7 +606,11 @@ class TestCertificateManager:
|
|
600
606
|
)
|
601
607
|
|
602
608
|
assert isinstance(cert_info, CertificateInfo)
|
603
|
-
assert cert_info.subject == {
|
609
|
+
assert cert_info.subject == {
|
610
|
+
"CN": "test.client.com",
|
611
|
+
"C": "test.client.com",
|
612
|
+
"O": "test.client.com",
|
613
|
+
}
|
604
614
|
assert cert_info.issuer == {"CN": "Test Root CA"}
|
605
615
|
assert cert_info.serial_number == "123456789"
|
606
616
|
assert cert_info.roles == ["user"]
|
@@ -651,14 +661,18 @@ class TestCertificateManager:
|
|
651
661
|
def test_validate_configuration_missing_ca_cert_path(self):
|
652
662
|
"""Test configuration validation with missing CA certificate path."""
|
653
663
|
with pytest.raises(ValidationError) as exc_info:
|
654
|
-
CertificateConfig(
|
664
|
+
CertificateConfig(
|
665
|
+
enabled=True, ca_cert_path="", ca_key_path=self.ca_key_path
|
666
|
+
)
|
655
667
|
|
656
668
|
assert "CA certificate and key paths are required" in str(exc_info.value)
|
657
669
|
|
658
670
|
def test_validate_configuration_missing_ca_key_path(self):
|
659
671
|
"""Test configuration validation with missing CA key path."""
|
660
672
|
with pytest.raises(ValidationError) as exc_info:
|
661
|
-
CertificateConfig(
|
673
|
+
CertificateConfig(
|
674
|
+
enabled=True, ca_cert_path=self.ca_cert_path, ca_key_path=""
|
675
|
+
)
|
662
676
|
|
663
677
|
assert "CA certificate and key paths are required" in str(exc_info.value)
|
664
678
|
|
@@ -772,11 +772,11 @@ class TestSecurityManager:
|
|
772
772
|
# Test factory methods
|
773
773
|
fastapi_middleware = security_manager.create_fastapi_middleware()
|
774
774
|
assert fastapi_middleware is not None
|
775
|
-
assert hasattr(fastapi_middleware,
|
775
|
+
assert hasattr(fastapi_middleware, "__call__")
|
776
776
|
|
777
777
|
flask_middleware = security_manager.create_flask_middleware()
|
778
778
|
assert flask_middleware is not None
|
779
|
-
assert hasattr(flask_middleware,
|
779
|
+
assert hasattr(flask_middleware, "__call__")
|
780
780
|
|
781
781
|
# Django middleware should raise ImportError since it's not implemented
|
782
782
|
with pytest.raises((ImportError, SecurityConfigurationError)):
|