# Manual Integration Tests
## Overview
This directory contains **manual integration tests** that validate the MCP server's three-phase security system
against a **live SQL Server database**. These tests are **excluded from automated CI/CD pipelines**
and must be run manually for production validation.
## π¨ **Important: Manual Testing Only**
These tests are **intentionally excluded** from:
- β
`npm test` (unit tests only)
- β
`npm run precommit`
- β
`npm run prepush`
- β
CI/CD workflows
- β
Automated testing pipelines
**Why Manual?** These tests require:
- Live SQL Server database connection
- Specific environment configuration
- Manual security validation
- Production-like setup verification
## Test Structure
### π **Test Files**
| File | Phase | Description | Tests |
| ---------------------------------- | -------------- | ------------------------------------- | -------- |
| `phase1-readonly-security.test.js` | π **Phase 1** | Maximum Security (Read-Only) | 20 tests |
| `phase2-dml-operations.test.js` | β οΈ **Phase 2** | DML Operations (INSERT/UPDATE/DELETE) | 10 tests |
| `phase3-ddl-operations.test.js` | π οΈ **Phase 3** | DDL Operations (CREATE/ALTER/DROP) | 10 tests |
#### Total: 40 comprehensive integration tests
### π **Security Phase Validation**
#### **Phase 1: Maximum Security (Default)**
- Validates read-only mode enforcement
- Tests that all write operations are blocked
- Verifies SELECT queries work correctly
- Ensures DDL and DML operations are rejected
#### **Phase 2: DML Operations Allowed**
- Validates selective write permissions
- Tests INSERT, UPDATE, DELETE operations
- Ensures DDL operations still blocked
- Verifies data persistence and cleanup
#### **Phase 3: Full Development Mode**
- Validates complete database access
- Tests CREATE, ALTER, DROP operations
- Verifies all DML operations work
- Ensures proper cleanup and rollback
## Prerequisites
### ποΈ **Database Requirements**
1. **SQL Server Instance**: Running and accessible
2. **Test Database**: `WarpMcpTest` (created automatically if missing)
3. **Sample Data**: Northwind-style test data (Products, Categories tables)
4. **User Permissions**:
- **Phase 1**: SELECT permissions
- **Phase 2**: SELECT, INSERT, UPDATE, DELETE permissions
- **Phase 3**: Full database permissions (DDL)
### π§ **Environment Setup**
1. **SSL Certificate**: Must be configured for `SQL_SERVER_TRUST_CERT=true`
2. **Connection Settings**: Valid credentials in `.env` file
3. **Network Access**: SQL Server accessible on configured host/port
## Running Tests
### π **Quick Start**
```bash
# Run all three phases sequentially
npm run test:integration:manual
# Note: Individual phases are now run together within the above command
# Phase 1: Read-only security tests
# Phase 2: DML operations tests
# Phase 3: DDL operations tests
```
### π **Manual Execution**
```bash
# Phase 1: Read-Only Security (20 tests)
node test/integration/manual/phase1-readonly-security.test.js
# Phase 2: DML Operations (10 tests)
node test/integration/manual/phase2-dml-operations.test.js
# Phase 3: DDL Operations (10 tests)
node test/integration/manual/phase3-ddl-operations.test.js
```
## Test Output
### β
**Successful Output Example**
```bash
π Starting Phase 1: Direct MCP Server Test (Read-Only Mode)
========================================================
π§ Environment Variables Set:
SQL_SERVER_READ_ONLY: true
SQL_SERVER_ALLOW_DESTRUCTIVE_OPERATIONS: false
SQL_SERVER_ALLOW_SCHEMA_CHANGES: false
π Server Configuration Loaded:
readOnlyMode: true
allowDestructiveOperations: false
allowSchemaChanges: false
π 1. DATABASE CONNECTIVITY AND BASIC OPERATIONS
===============================================
π§ͺ Testing: Database connection should work
β
PASSED: connection_test
π§ͺ Testing: List databases should work
β
PASSED: list_databases
... [18 more tests] ...
π― PHASE 1: DIRECT MCP SERVER TEST SUMMARY
========================================
β
Tests Passed: 20
β Tests Failed: 0
π Total Tests: 20
π Success Rate: 100.0%
π Phase 1 Assessment:
β
PHASE 1 COMPLETE - Maximum security validated!
```
### β **Failure Analysis**
When tests fail, detailed error information is provided:
```bash
β FAILED: insert_blocked_test - Query blocked by safety policy: Read-only mode is enabled. Only SELECT queries are allowed.
```
## Test Configuration
### π§ **Environment Variables**
Each test phase automatically configures the required environment variables:
**Phase 1 (Read-Only):**
```bash
SQL_SERVER_READ_ONLY=true
SQL_SERVER_ALLOW_DESTRUCTIVE_OPERATIONS=false
SQL_SERVER_ALLOW_SCHEMA_CHANGES=false
```
**Phase 2 (DML Allowed):**
```bash
SQL_SERVER_READ_ONLY=false
SQL_SERVER_ALLOW_DESTRUCTIVE_OPERATIONS=true
SQL_SERVER_ALLOW_SCHEMA_CHANGES=false
```
**Phase 3 (Full Access):**
```bash
SQL_SERVER_READ_ONLY=false
SQL_SERVER_ALLOW_DESTRUCTIVE_OPERATIONS=true
SQL_SERVER_ALLOW_SCHEMA_CHANGES=true
```
### π **Configuration Reloading**
Each test automatically:
1. Sets the required environment variables
2. Calls `serverConfig.reload()` to refresh configuration
3. Verifies the configuration was loaded correctly
4. Creates a fresh MCP server instance with new settings
## Troubleshooting
### π **Common Issues**
#### **Connection Failures**
```bash
β Failed to connect to SQL Server after 3 attempts
```
**Solutions:**
- Verify SQL Server is running
- Check `.env` file configuration
- Ensure SSL certificate trust settings
- Validate network connectivity
#### **Permission Errors**
```bash
β Permission denied for operation
```
**Solutions:**
- Verify database user permissions
- Check security phase requirements
- Ensure test database exists
- Validate user access to required objects
#### **Configuration Issues**
```bash
β Configuration not loaded correctly
```
**Solutions:**
- Verify `.env` file exists and is readable
- Check environment variable precedence
- Ensure `serverConfig.reload()` is working
- Validate configuration object structure
### π **Debug Mode**
Enable detailed logging by setting:
```bash
SQL_SERVER_DEBUG=true
```
## Production Validation
### β
**Validation Checklist**
Before deploying to production, ensure:
- [ ] **Phase 1**: 20/20 tests pass (Maximum security)
- [ ] **Phase 2**: 10/10 tests pass (Selective permissions)
- [ ] **Phase 3**: 10/10 tests pass (Full development mode)
- [ ] **SSL/TLS**: Certificate validation works correctly
- [ ] **Configuration**: Environment variables load properly
- [ ] **Security**: Boundaries enforced across all phases
- [ ] **Performance**: Query execution within acceptable limits
- [ ] **Cleanup**: Test data properly removed after execution
### π₯ **Production Readiness**
A **100% success rate** across all 40 tests indicates:
- β
**Security system is bulletproof**
- β
**Database connectivity is stable**
- β
**Configuration management is robust**
- β
**Error handling is comprehensive**
- β
**Performance monitoring is functional**
- β
**Production deployment is safe**
## Maintenance
### π **Updating Tests**
When adding new MCP tools or security features:
1. **Add test cases** to the appropriate phase file
2. **Update test counts** in this README
3. **Verify exclusion** from automated test runs
4. **Test manually** to ensure functionality
5. **Update documentation** as needed
### π **Test Metrics**
Current test coverage:
- **Database Operations**: All 15 MCP tools tested
- **Security Boundaries**: All three phases validated
- **Error Scenarios**: Connection, permission, validation errors
- **Configuration**: Environment variables, SSL/TLS, authentication
- **Performance**: Query execution and monitoring
---
## π― **Summary**
These manual integration tests provide **comprehensive validation** of the MCP server's security system
and production readiness. The **40-test suite** ensures that all three security phases work correctly
and that the system is ready for enterprise deployment.
**Run these tests before any production deployment** to validate security boundaries and system functionality.