Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

test: exercise real MCP provider credential encrypter (#43422)

Asuka Minatofd27ee420930
diff --git a/api/tests/unit_tests/core/entities/test_entities_mcp_provider.py b/api/tests/unit_tests/core/entities/test_entities_mcp_provider.py
index f7a4ac7e37e..ae6db615395 100644
--- a/api/tests/unit_tests/core/entities/test_entities_mcp_provider.py
+++ b/api/tests/unit_tests/core/entities/test_entities_mcp_provider.py
@@ -1,5 +1,5 @@
from datetime import UTC, datetime
-from unittest.mock import Mock, patch
+from unittest.mock import patch
import pytest
@@ -409,32 +409,28 @@ def test_decrypt_dict_returns_original_data_when_no_encrypted_fields() -> None:
assert result is input_data
-def test_decrypt_dict_only_decrypts_top_level_string_values() -> None:
- # Arrange
+def test_decrypt_dict_only_decrypts_top_level_string_values(monkeypatch: pytest.MonkeyPatch) -> None:
entity = _build_mcp_provider_entity()
- decryptor = Mock()
- decryptor.decrypt.return_value = {"api_key": "plain-key"}
-
- def _fake_create_provider_encrypter(*, tenant_id: str, config: list, cache):
- assert tenant_id == "tenant-1"
- assert any(item.name == "api_key" for item in config)
- return decryptor, None
-
- with patch("core.tools.utils.encryption.create_provider_encrypter", side_effect=_fake_create_provider_encrypter):
- # Act
- result = entity._decrypt_dict(
- {
- "api_key": "encrypted-key",
- "nested": {"client_id": "unchanged"},
- "empty": "",
- "count": 2,
- }
- )
+ decrypted: list[tuple[str, str]] = []
+
+ def decrypt_token(tenant_id: str, token: str) -> str:
+ decrypted.append((tenant_id, token))
+ return "plain-key"
+
+ monkeypatch.setattr("core.helper.provider_encryption.encrypter.decrypt_token", decrypt_token)
+ result = entity._decrypt_dict(
+ {
+ "api_key": "encrypted-key",
+ "nested": {"client_id": "unchanged"},
+ "empty": "",
+ "count": 2,
+ }
+ )
- # Assert
- decryptor.decrypt.assert_called_once_with({"api_key": "encrypted-key"})
+ assert decrypted == [("tenant-1", "encrypted-key")]
assert result["api_key"] == "plain-key"
assert result["nested"] == {"client_id": "unchanged"}
+ assert result["empty"] == ""
assert result["count"] == 2