You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
3.1 KiB
3.1 KiB
MFA Testing Summary
Frontend Testing
Current State
- Jest is configured in package.json but dependencies are not properly installed in the Docker container
- Created a sample test file:
/home/webapp/dify/web/app/components/header/account-setting/mfa-page.test.tsx - The test file demonstrates how to test the MFA component with proper mocking
Test Coverage
The test file covers:
- Loading state display
- Enable/Disable button rendering based on MFA status
- Setup modal opening
- Successful MFA setup flow
- Error handling during setup
- MFA disable functionality
To Run Frontend Tests
When dependencies are properly installed:
npm test -- mfa-page.test.tsx
Backend Testing
Current State
- Pytest is installed and working in the API container
- Test file exists at:
/home/webapp/dify/api/tests/unit_tests/controllers/console/auth/test_mfa.py - Some tests have mock configuration issues due to the application's initialization complexity
Test Coverage
The test file covers:
- MFA setup initialization
- Setup completion with valid/invalid tokens
- MFA disable with password verification
- MFA status retrieval
- MFA verification during login
- Error cases (missing parameters, wrong credentials)
Working Tests
test_mfa_verify_missing_parameters- PASSED
To Run Backend Tests
docker exec docker-api-1 python -m pytest tests/unit_tests/controllers/console/auth/test_mfa.py -v -o addopts=
Manual Testing Scenarios
Based on the implementation, here are the key scenarios to test manually:
1. MFA Setup Flow
- Navigate to Account page
- Click MFA button
- Verify QR code displays
- Scan QR code with authenticator app
- Enter TOTP code
- Verify backup codes are displayed
- Confirm MFA is enabled
2. MFA Login Flow
- Log out
- Log in with email/password
- Verify MFA prompt appears
- Enter TOTP code
- Verify successful login
3. MFA Disable Flow
- Navigate to Account page with MFA enabled
- Click disable MFA
- Enter account password
- Verify MFA is disabled
4. Backup Code Usage
- During login, use backup code instead of TOTP
- Verify backup code works only once
5. Error Cases
- Try invalid TOTP during setup
- Try wrong password during disable
- Try expired TOTP code
- Try reused backup code
6. UI/UX Verification
- Verify Japanese translations work (no "operation.cancel" errors)
- Verify modal displays correctly (no z-index issues)
- Verify loading states during API calls
- Verify error messages display properly
Known Issues
- Frontend test environment requires proper npm dependency installation
- Backend tests have complex mocking requirements due to Flask app initialization
- Coverage tools (pytest-cov) not installed in Docker container
Recommendations
- Install test dependencies in Docker containers during build
- Add test commands to Makefile for easier execution
- Consider using Flask test client fixtures for better test isolation
- Add integration tests that test the full MFA flow end-to-end