Skip to content

test: add comprehensive unit tests for encrypter module#22102

Merged
crazywoola merged 1 commit into
langgenius:mainfrom
farion1231:test/add-encrypter-unit-tests
Jul 10, 2025
Merged

test: add comprehensive unit tests for encrypter module#22102
crazywoola merged 1 commit into
langgenius:mainfrom
farion1231:test/add-encrypter-unit-tests

Conversation

@farion1231

@farion1231 farion1231 commented Jul 9, 2025

Copy link
Copy Markdown
Contributor

Description

Add comprehensive unit tests for core.helper.encrypter module.

Core Functionality Tests

  • Token obfuscation with various input scenarios
  • Encryption and decryption operations
  • Batch decryption performance optimization
  • Error handling for invalid inputs

Security-Focused Tests

  • Cross-tenant isolation: Ensures tokens encrypted for one tenant cannot be accessed by another
  • Tampered ciphertext detection: Verifies the system rejects modified encrypted data
  • Encryption randomness: Confirms same plaintext produces different ciphertext (prevents pattern analysis)
  • RSA size limits: Tests behavior with oversized inputs

Edge Cases

  • Empty tokens and special characters (null bytes, emoji, Unicode)
  • Base64 encoding/decoding edge cases
  • Database and key management error scenarios

The extensive test coverage is intentional given the critical nature of encryption functionality in the system.

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods

- Add tests for token obfuscation with various lengths and special characters
- Add encryption/decryption tests with proper mocking
- Add batch decryption optimization tests
- Add security-focused tests including cross-tenant isolation and tampered ciphertext detection
- Add edge case tests for empty tokens, special characters, and RSA size limits
- Achieve high test coverage for all public functions in encrypter module
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 9, 2025
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jul 10, 2025
@crazywoola crazywoola merged commit 881a151 into langgenius:main Jul 10, 2025
6 checks passed
@farion1231 farion1231 deleted the test/add-encrypter-unit-tests branch July 10, 2025 03:21
Scorpion1221 added a commit to yybht155/dify that referenced this pull request Jul 16, 2025
* commit '390e4cc0bf203a979e13694ed99ec9fda6b42cc8': (143 commits)
  chore(version): bump to 1.6.0 (langgenius#22136)
  chore: fix schema editor can not hover item (langgenius#22155)
  fix: add the default value to the dark icon (langgenius#22149)
  feat: support ping method for MCP server (langgenius#22144)
  fix: mcp server card button display (langgenius#22141)
  feat: add support for dark icons in provider and tool entities (langgenius#22081)
  update worklow events logs. (langgenius#19871)
  chore: translate i18n files (langgenius#22132)
  feat: the frontend part of mcp (langgenius#22131)
  feat: add MCP support (langgenius#20716)
  Fix: Resolve issue with json_output (langgenius#22053)
  Chore: rm useless import and vars (langgenius#22108)
  feat: add redis fallback mechanism langgenius#21043 (langgenius#21044)
  optimize: batch embedding and qdrant write_consistency_factor parameter (langgenius#21776)
  chore: Update theme vars (langgenius#22113)
  feat(question-classifier): add drag-and-drop sorting for topics list (langgenius#22066)
  test: add comprehensive unit tests for encrypter module (langgenius#22102)
  fix: allow update plugin install settings (langgenius#22111)
  fix(Drawer): add overflow hidden to ensure copy button is always clickable (langgenius#21992) (langgenius#22103)
  Update clean_document_task.py (langgenius#22090)
  ...

# Conflicts:
#	api/core/helper/code_executor/template_transformer.py
#	api/pyproject.toml
#	api/uv.lock
tutkun pushed a commit to tutkun/dify that referenced this pull request Aug 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants