provisioning-platform/prov-ecosystem/crates/syntaxis-integration/tests/e2e_integration.rs

455 lines
16 KiB
Rust

//! End-to-End integration tests for the Syntaxis ecosystem integration system
#[cfg(test)]
mod e2e_tests {
use serde_json::json;
use syntaxis_integration::{SyntaxisClient, TaskEventBuilder};
/// Helper function to create test client
fn create_test_client() -> SyntaxisClient {
let base_url =
std::env::var("SYNTAXIS_URL").unwrap_or_else(|_| "http://localhost:3030".to_string());
let mut client = SyntaxisClient::new(base_url);
if let Ok(token) = std::env::var("SYNTAXIS_TOKEN") {
client = client.with_token(token);
}
client
}
#[tokio::test]
#[ignore] // Run with: cargo test e2e_create_and_emit_task -- --ignored --test-threads=1
async fn e2e_create_and_emit_task() {
let client = create_test_client();
// Build event
let task_id = "e2e-test-001";
let description = "E2E Test Task";
let event = TaskEventBuilder::new(task_id.to_string(), description.to_string())
.source("test")
.event_type("test_event")
.task_type("validation")
.metadata(json!({
"test": true,
"timestamp": chrono::Utc::now().to_rfc3339()
}))
.phase("devel")
.build();
// Emit event
let emit_result = client.emit_event(event.clone()).await;
assert!(emit_result.is_ok(), "Failed to emit event");
// Create task from event
let create_result = client
.create_task(syntaxis_integration::client::CreateTaskRequest {
description: event.description.clone(),
task_name: Some(task_id.to_string()),
task_type: "validation".to_string(),
task_priority: Some("high".to_string()),
phase: Some("devel".to_string()),
task_deps: vec![],
note: Some("E2E test task".to_string()),
})
.await;
assert!(create_result.is_ok(), "Failed to create task");
assert!(
!create_result.unwrap().id.is_empty(),
"Task ID should not be empty"
);
}
#[tokio::test]
#[ignore]
async fn e2e_validation_workflow() {
let client = create_test_client();
// Simulate validation failure event
let failure_event = TaskEventBuilder::new(
"validation-failure-001".to_string(),
"Validation FAILED: Security rule not met".to_string(),
)
.source("valida")
.event_type("validation_failure")
.task_type("validation")
.metadata(json!({
"rule_id": "rule-001",
"rule_name": "Database Encryption",
"category": "security",
"severity": "error",
"error": "Missing encryption configuration"
}))
.build();
// Emit failure event
let emit_result = client.emit_event(failure_event.clone()).await;
assert!(emit_result.is_ok());
// Create failure task
let task_result = client
.create_task(syntaxis_integration::client::CreateTaskRequest {
description: "Database encryption validation failed".to_string(),
task_name: Some("valida-rule-001".to_string()),
task_type: "validation".to_string(),
task_priority: Some("high".to_string()),
phase: Some("devel".to_string()),
task_deps: vec![],
note: Some("Fix database encryption settings".to_string()),
})
.await;
let task_id = task_result.unwrap().id;
assert!(!task_id.is_empty());
// Simulate validation success event after remediation
let success_event = TaskEventBuilder::new(
"validation-success-001".to_string(),
"Validation PASSED: Security rule met".to_string(),
)
.source("valida")
.event_type("validation_success")
.task_type("validation")
.metadata(json!({
"rule_id": "rule-001",
"rule_name": "Database Encryption",
"category": "security",
"passed": true
}))
.build();
let emit_success = client.emit_event(success_event).await;
assert!(emit_success.is_ok());
}
#[tokio::test]
#[ignore]
async fn e2e_security_vulnerability_workflow() {
let client = create_test_client();
// Emit CVE finding event
let cve_event = TaskEventBuilder::new(
"audit-cve-CVE-2023-12345".to_string(),
"Security Alert [CRITICAL]: CVE-2023-12345 - Buffer overflow in openssl".to_string(),
)
.source("audit")
.event_type("cve_finding")
.task_type("security")
.metadata(json!({
"cve_id": "CVE-2023-12345",
"severity": "Critical",
"package": "openssl",
"installed_version": "1.1.1",
"fixed_version": "1.1.1w",
"source": "trivy"
}))
.phase("devel")
.build();
let emit_result = client.emit_event(cve_event.clone()).await;
assert!(emit_result.is_ok());
// Create security task
let task_result = client
.create_task(syntaxis_integration::client::CreateTaskRequest {
description: "CVE-2023-12345 vulnerability found in openssl".to_string(),
task_name: Some("CVE-2023-12345".to_string()),
task_type: "security".to_string(),
task_priority: Some("critical".to_string()),
phase: Some("devel".to_string()),
task_deps: vec![],
note: Some("Update openssl to version 1.1.1w or later".to_string()),
})
.await;
let task_id = task_result.unwrap().id;
assert!(!task_id.is_empty());
// Emit SBOM scan event
let sbom_event = TaskEventBuilder::new(
"audit-sbom-scan-001".to_string(),
"Compliance Scan [SBOM]: Security Audit - Found 3 vulnerabilities".to_string(),
)
.source("audit")
.event_type("sbom_scan")
.task_type("compliance")
.metadata(json!({
"report_title": "Security Audit",
"vulnerabilities": 3,
"scan_duration": 45.2,
"timestamp": chrono::Utc::now().to_rfc3339()
}))
.build();
let sbom_result = client.emit_event(sbom_event).await;
assert!(sbom_result.is_ok());
}
#[tokio::test]
#[ignore]
async fn e2e_gitops_deployment_workflow() {
let client = create_test_client();
// Emit git push event
let push_event = TaskEventBuilder::new(
"gitops-git-push-001".to_string(),
"GitOps event [push]: Deployment triggered".to_string(),
)
.source("gitops")
.event_type("push")
.task_type("deployment")
.metadata(json!({
"repository": "myapp",
"branch": "main",
"commit": "abc123def456",
"author": "developer",
"message": "Fix critical security issue"
}))
.phase("deploy")
.build();
let emit_result = client.emit_event(push_event.clone()).await;
assert!(emit_result.is_ok());
// Create deployment task
let task_result = client
.create_task(syntaxis_integration::client::CreateTaskRequest {
description: "Deploy main branch to production".to_string(),
task_name: Some("deploy-myapp-main".to_string()),
task_type: "deployment".to_string(),
task_priority: Some("high".to_string()),
phase: Some("deploy".to_string()),
task_deps: vec![],
note: Some("Commit: abc123def456 - Fix critical security issue".to_string()),
})
.await;
let task_id = task_result.unwrap().id;
assert!(!task_id.is_empty());
// Emit PR event
let pr_event = TaskEventBuilder::new(
"gitops-git-pull_request-001".to_string(),
"GitOps event [pull_request]: Code review required".to_string(),
)
.source("gitops")
.event_type("pull_request")
.task_type("review")
.metadata(json!({
"repository": "myapp",
"pr_number": 123,
"title": "Add security improvements",
"author": "developer"
}))
.phase("build")
.build();
let pr_result = client.emit_event(pr_event).await;
assert!(pr_result.is_ok());
}
#[tokio::test]
#[ignore]
async fn e2e_batch_task_creation() {
let client = create_test_client();
// Create multiple tasks in sequence
let task_configs = vec![
("task-batch-001", "Batch test task 1", "validation"),
("task-batch-002", "Batch test task 2", "security"),
("task-batch-003", "Batch test task 3", "deployment"),
];
let mut created_tasks = vec![];
for (name, desc, task_type) in task_configs {
let result = client
.create_task(syntaxis_integration::client::CreateTaskRequest {
description: desc.to_string(),
task_name: Some(name.to_string()),
task_type: task_type.to_string(),
task_priority: Some("medium".to_string()),
phase: Some("devel".to_string()),
task_deps: vec![],
note: None,
})
.await;
if let Ok(task) = result {
created_tasks.push(task.id);
}
}
assert_eq!(created_tasks.len(), 3, "All batch tasks should be created");
}
#[tokio::test]
#[ignore]
async fn e2e_task_action_execution() {
let client = create_test_client();
// Create a task
let task_result = client
.create_task(syntaxis_integration::client::CreateTaskRequest {
description: "Test task for action execution".to_string(),
task_name: Some("task-with-actions".to_string()),
task_type: "validation".to_string(),
task_priority: Some("high".to_string()),
phase: Some("devel".to_string()),
task_deps: vec![],
note: Some("This task will have actions executed".to_string()),
})
.await;
let task_id = task_result.unwrap().id;
assert!(!task_id.is_empty());
// Emit action execution event
let action_event = TaskEventBuilder::new(
format!("action-{}", task_id),
"Task action executed successfully".to_string(),
)
.source("system")
.event_type("action_executed")
.task_type("validation")
.metadata(json!({
"task_id": task_id,
"action_type": "validate",
"status": "completed",
"duration_seconds": 5.2
}))
.build();
let action_result = client.emit_event(action_event).await;
assert!(action_result.is_ok());
}
#[tokio::test]
#[ignore]
async fn e2e_integration_health_check() {
let client = create_test_client();
// Try to connect and check if service is healthy
let event = TaskEventBuilder::new(
"health-check-001".to_string(),
"Health check event".to_string(),
)
.source("system")
.event_type("health_check")
.task_type("alert")
.build();
let result = client.emit_event(event).await;
// Check should succeed if Syntaxis is running
match result {
Ok(_) => println!("✓ Syntaxis integration is healthy"),
Err(e) => println!("✗ Syntaxis integration health check failed: {}", e),
}
// Don't assert failure if Syntaxis is not running - this is expected in CI
}
#[tokio::test]
#[ignore]
async fn e2e_complete_ecosystem_workflow() {
let client = create_test_client();
println!("Starting E2E ecosystem workflow test...");
// Step 1: Emit validation event
println!("Step 1: Validating configuration...");
let validation_event = TaskEventBuilder::new(
"workflow-validate-001".to_string(),
"Configuration validation in progress".to_string(),
)
.source("valida")
.event_type("validation_failure")
.task_type("validation")
.metadata(json!({"rule_id": "rule-001", "error": "Missing configuration"}))
.build();
assert!(client.emit_event(validation_event).await.is_ok());
// Step 2: Create validation task
println!("Step 2: Creating validation task...");
let val_task = client
.create_task(syntaxis_integration::client::CreateTaskRequest {
description: "Fix missing configuration".to_string(),
task_name: Some("validation-task".to_string()),
task_type: "validation".to_string(),
task_priority: Some("high".to_string()),
phase: Some("devel".to_string()),
task_deps: vec![],
note: None,
})
.await;
assert!(val_task.is_ok());
// Step 3: Emit security scan event
println!("Step 3: Running security scan...");
let security_event = TaskEventBuilder::new(
"workflow-cve-001".to_string(),
"Security vulnerability detected".to_string(),
)
.source("audit")
.event_type("cve_finding")
.task_type("security")
.metadata(json!({"cve_id": "CVE-2024-001"}))
.build();
assert!(client.emit_event(security_event).await.is_ok());
// Step 4: Create security task
println!("Step 4: Creating security task...");
let sec_task = client
.create_task(syntaxis_integration::client::CreateTaskRequest {
description: "Fix security vulnerability".to_string(),
task_name: Some("security-task".to_string()),
task_type: "security".to_string(),
task_priority: Some("critical".to_string()),
phase: Some("devel".to_string()),
task_deps: vec![],
note: None,
})
.await;
assert!(sec_task.is_ok());
// Step 5: Emit deployment event
println!("Step 5: Triggering deployment...");
let deployment_event = TaskEventBuilder::new(
"workflow-deploy-001".to_string(),
"Deployment in progress".to_string(),
)
.source("gitops")
.event_type("push")
.task_type("deployment")
.metadata(json!({"repository": "app", "branch": "main"}))
.build();
assert!(client.emit_event(deployment_event).await.is_ok());
// Step 6: Create deployment task
println!("Step 6: Creating deployment task...");
let deploy_task = client
.create_task(syntaxis_integration::client::CreateTaskRequest {
description: "Deploy application".to_string(),
task_name: Some("deployment-task".to_string()),
task_type: "deployment".to_string(),
task_priority: Some("high".to_string()),
phase: Some("deploy".to_string()),
task_deps: vec![],
note: None,
})
.await;
assert!(deploy_task.is_ok());
println!("✓ E2E ecosystem workflow test completed successfully!");
}
}