integration test

This commit is contained in:
koenieee
2025-09-30 14:27:14 +02:00
parent 3023e30158
commit 666b7e85a3
4 changed files with 69 additions and 9 deletions
+1 -1
View File
@@ -16,7 +16,7 @@ fi
echo ""
echo "🔍 Running clippy analysis..."
if cargo clippy -- -D warnings; then
if cargo clippy --all-targets --all-features --workspace -- -D warnings; then
echo "✅ No clippy warnings found"
else
echo "❌ Clippy warnings found. Fix the issues and try again."
+12
View File
@@ -131,6 +131,8 @@ fi
# Test configuration validation
print_section "Configuration Validation Tests"
VALIDATION_ERRORS=0
echo "Testing with valid configurations:"
for config in test_configs/valid/*.conf; do
if [ -f "$config" ]; then
@@ -139,6 +141,7 @@ for config in test_configs/valid/*.conf; do
echo -e " ${GREEN}✓ Valid${NC}"
else
echo -e " ${RED}✗ Failed validation${NC}"
((VALIDATION_ERRORS++))
fi
fi
done
@@ -149,12 +152,21 @@ for config in test_configs/invalid/*; do
echo " - $(basename "$config")"
if cargo run --quiet -- --config "$config" --no-reload >/dev/null 2>&1; then
echo -e " ${RED}✗ Should have failed${NC}"
((VALIDATION_ERRORS++))
else
echo -e " ${GREEN}✓ Correctly rejected${NC}"
fi
fi
done
# Check if any validation tests failed
if [ $VALIDATION_ERRORS -gt 0 ]; then
echo -e "\n${RED}❌ Configuration validation tests failed: $VALIDATION_ERRORS error(s)${NC}"
exit 1
else
echo -e "\n${GREEN}✓ All configuration validation tests passed${NC}"
fi
# Performance check
print_section "Performance Check"
echo "Testing performance with multiple config files..."
+54 -6
View File
@@ -138,14 +138,14 @@ impl WebServerHandler for NginxHandler {
{
Ok(output) => Ok(output.status.success()),
Err(_e) => {
// If nginx command fails (not installed), just check if file exists and looks like nginx config
// If nginx command fails (not installed), use more strict validation
let content = std::fs::read_to_string(&config.path)?;
// Basic content validation - check for nginx-like directives
let content_lower = content.to_lowercase();
let is_valid =
content_lower.contains("server") || content_lower.contains("location");
// More strict validation: check for proper nginx structure
let is_valid = validate_nginx_structure(&content);
eprintln!(
"DEBUG: Fallback validation for {:?}: content contains server/location: {}",
"DEBUG: Fallback validation for {:?}: proper nginx structure: {}",
config.path.file_name(),
is_valid
);
@@ -201,3 +201,51 @@ impl Default for NginxHandler {
Self::new()
}
}
/// Validate nginx configuration structure more strictly
fn validate_nginx_structure(content: &str) -> bool {
// Remove comments and empty lines for validation
let lines: Vec<&str> = content
.lines()
.map(|line| line.trim())
.filter(|line| !line.is_empty() && !line.starts_with('#'))
.collect();
if lines.is_empty() {
return false;
}
// Must have at least one server block or events block
let has_server_block = lines
.iter()
.any(|line| line.starts_with("server") && line.contains('{'));
let has_events_block = lines
.iter()
.any(|line| line.starts_with("events") && line.contains('{'));
let has_http_block = lines
.iter()
.any(|line| line.starts_with("http") && line.contains('{'));
// Must have proper brace matching
let open_braces = content.matches('{').count();
let close_braces = content.matches('}').count();
let balanced_braces = open_braces == close_braces && open_braces > 0;
// Must have at least some nginx-like directives with semicolons (excluding blocks)
let has_directives = lines.iter().any(|line| {
line.ends_with(';')
&& (line.contains("listen")
|| line.contains("server_name")
|| line.contains("root")
|| line.contains("index")
|| line.contains("allow")
|| line.contains("deny")
|| line.contains("return")
|| line.contains("proxy_pass"))
});
// Valid nginx config needs proper structure
balanced_braces
&& (has_server_block || has_events_block || has_http_block)
&& (has_directives || has_events_block || has_http_block)
}
+2 -2
View File
@@ -160,8 +160,8 @@ fn test_cli_args_error_handling_flow() {
#[test]
fn test_cli_args_pattern_and_hostname_combinations() {
let patterns = vec!["*.conf", "*.nginx", "*.config", "site-*.conf"];
let hostnames = vec![
let patterns = ["*.conf", "*.nginx", "*.config", "site-*.conf"];
let hostnames = [
"google.com",
"example.com",
"test.local",