This directory contains comprehensive unit and integration tests for the MySQL handshake process.
- Basic connection parameter validation
- Constructor argument validation
- Authentication state management
- Error handling scenarios
- Handshake packet decoding/encoding
- OK packet parsing
- Error packet parsing
- Client capability flags
- Binary protocol validation
- Full handshake flow with real MySQL server
- Authentication success/failure scenarios
- Concurrent connections
- Reconnection handling
- Timeout scenarios
The integration tests can be configured using environment variables:
export MYSQL_HOST=localhost
export MYSQL_PORT=3306
export MYSQL_USERNAME=root
export MYSQL_PASSWORD=password
export MYSQL_DATABASE=testIf environment variables are not set, the tests use these defaults:
- Host:
localhost - Port:
3306 - Username:
root - Password:
password - Database:
test
dotnet testdotnet test --filter "Category!=Integration"dotnet test --filter "Category=Integration"dotnet test --filter "ClassName=HandshakeTest"For automated testing with MySQL in your pipeline:
version: '3.8'
services:
mysql:
image: mysql:8.0
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: test
ports:
- "3306:3306"
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
timeout: 20s
retries: 10jobs:
test:
runs-on: ubuntu-latest
services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: test
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: '6.0.x'
- name: Run tests
run: dotnet test
env:
MYSQL_HOST: localhost
MYSQL_PORT: 3306
MYSQL_USERNAME: root
MYSQL_PASSWORD: password
MYSQL_DATABASE: testThe tests cover:
- ✅ Server handshake packet reception
- ✅ Client handshake response generation
- ✅ Authentication response calculation (SHA1 + salt)
- ✅ OK packet handling (authentication success)
- ✅ Error packet handling (authentication failure)
- ✅ Connection state tracking
- ✅ Multiple concurrent connections
- ✅ Connection cleanup and disconnection
- ✅ Reconnection scenarios
- ✅ Invalid credentials
- ✅ Invalid host/port
- ✅ Network timeouts
- ✅ Missing MySQL server
- ✅ Empty passwords
- ✅ Special characters in passwords
- ✅ Long usernames/passwords
- ✅ Connection parameter validation
-
MySQL Connection Refused
- Ensure MySQL server is running
- Check host and port configuration
- Verify firewall settings
-
Authentication Failed
- Verify username/password
- Check MySQL user permissions
- Ensure MySQL authentication plugin compatibility
-
Tests Skipped
- Integration tests are automatically skipped if MySQL is not available
- Unit tests should always run regardless of MySQL availability
Enable verbose logging by setting:
export MYSQL_DEBUG=trueTests automatically clean up connections, but if you need to reset:
-- Connect to MySQL and run:
SHOW PROCESSLIST;
KILL <connection_id>; -- for any stuck connections