# QSSH Test Suite
Comprehensive test coverage for the Quantum Secure Shell (QSSH) implementation.
## Test Structure
### Unit Tests
#### `key_parsing_tests.rs`
- PEM private key parsing
- Public key format parsing
- Base64 encoding/decoding
- Multi-line PEM handling
- Invalid format handling
#### `unit_tests.rs`
- **Crypto Module Tests**
- Symmetric encryption/decryption
- Session key derivation
- Key exchange signatures
- Shared secret computation
- **Message Serialization Tests**
- Protocol message encoding/decoding
- Authentication messages
- Transport framing
- **Configuration Tests**
- Client/server configuration
- Port forwarding setup
- **Error Handling Tests**
- Invalid key sizes
- Signature verification failures
- Protocol errors
### Integration Tests
#### `integration_full.rs`
- Full client-server connection flow
- Authentication with authorized_keys
- Command execution
- Key rotation
- Concurrent connections
- Graceful disconnection
- Port forwarding
- Protocol version negotiation
- Algorithm negotiation
#### `shell_tests.rs`
- PTY creation and management
- Command execution
- I/O redirection
- Environment variables
- Exit code handling
- Signal handling
- Pipeline execution
- Working directory changes
- Concurrent shell sessions
- Special character handling
#### `handshake_tests.rs`
- Complete handshake flow
- Key exchange verification
- Authentication methods
- Session establishment
#### `crypto_tests.rs`
- Post-quantum algorithms (Falcon, SPHINCS+, Kyber)
- Hybrid encryption modes
- Key generation and verification
- Performance benchmarks
## Running Tests
### Run all tests
```bash
cargo test
```
### Run specific test file
```bash
cargo test --test key_parsing_tests
cargo test --test unit_tests
cargo test --test integration_full
cargo test --test shell_tests
```
### Run with verbose output
```bash
cargo test -- --nocapture
```
### Run tests in release mode
```bash
cargo test --release
```
### Run benchmarks
```bash
cargo bench
```
### Generate test coverage
```bash
cargo tarpaulin --out Html
```
## Test Coverage Goals
- **Unit Test Coverage**: >80%
- **Integration Test Coverage**: >60%
- **Critical Path Coverage**: 100%
## Key Test Scenarios
### Authentication Tests
1. Valid key authentication ✓
2. Invalid key rejection ✓
3. Expired key handling ✓
4. Multiple authorized keys ✓
5. Key rotation during session ✓
### Crypto Tests
1. Falcon-512 key exchange ✓
2. SPHINCS+ signatures ✓
3. AES-256-GCM encryption ✓
4. SHA3-256 hashing ✓
5. Session key derivation ✓
### Protocol Tests
1. Version negotiation ✓
2. Algorithm selection ✓
3. Message framing ✓
4. Error handling ✓
5. Disconnection flow ✓
### Shell Tests
1. PTY allocation ✓
2. Command execution ✓
3. Signal handling ✓
4. I/O redirection ✓
5. Terminal emulation ✓
## Continuous Integration
Tests are automatically run on:
- Every push to main/develop branches
- Every pull request
- Multiple OS platforms (Linux, macOS)
- Multiple Rust versions (stable, nightly)
See `.github/workflows/ci.yml` for CI configuration.
## Security Testing
### Fuzzing
```bash
cargo fuzz run protocol_fuzzer
```
### Security Audit
```bash
cargo audit
```
### Static Analysis
```bash
cargo clippy -- -D warnings
```
## Performance Testing
### Benchmarks
Located in `benches/` directory:
- Handshake performance
- Encryption throughput
- Key generation speed
- Message serialization
Run with:
```bash
cargo bench
```
## Test Data
Test keys and certificates are located in `tests/data/`:
- Sample PEM keys
- Authorized_keys files
- Test configurations
⚠️ **WARNING**: Never use test keys in production!
## Adding New Tests
1. Create test file in appropriate directory
2. Add test module to `tests/mod.rs` if needed
3. Follow naming convention: `test_<feature>_<scenario>`
4. Include both positive and negative test cases
5. Document test purpose and expected behavior
6. Ensure cleanup of test resources
## Known Issues
- PTY tests may fail in containerized environments
- Some integration tests require network access
- Shell tests are Unix-only
## Contributing
When adding new features:
1. Write unit tests first (TDD)
2. Add integration tests for user-facing functionality
3. Update this README with new test coverage
4. Ensure all tests pass before submitting PR