fix: format and lint
CI / Format (push) Successful in 48s
CI / Test (push) Failing after 7m9s
CI / Check (push) Successful in 12m6s
CI / Clippy (push) Successful in 12m10s

This commit is contained in:
Guillaume GRABÉ
2026-06-08 23:51:29 +02:00
parent 6400518beb
commit 1302ce412c
27 changed files with 563 additions and 395 deletions
+70 -61
View File
@@ -8,7 +8,9 @@ use charybdis::charybdis::entities::entity::{Metadata, Spec};
use charybdis::charybdis::entities::Entity;
use charybdis::database::{ensure_schema, EntityRepository};
use charybdis::plugins::ResourceHandler;
use charybdis_defectdojo::{DefectDojoClient, DefectDojoConfig, EngagementConfig, OwnerResolutionConfig};
use charybdis_defectdojo::{
DefectDojoClient, DefectDojoConfig, EngagementConfig, OwnerResolutionConfig,
};
use serde_json::json;
use sqlx::PgPool;
use std::collections::HashMap;
@@ -17,9 +19,11 @@ use wiremock::matchers::{method, path, query_param};
use wiremock::{Mock, MockServer, ResponseTemplate};
async fn setup_db() -> PgPool {
let url = std::env::var("DATABASE_URL")
.expect("DATABASE_URL must be set for integration tests");
let pool = PgPool::connect(&url).await.expect("Failed to connect to test database");
let url =
std::env::var("DATABASE_URL").expect("DATABASE_URL must be set for integration tests");
let pool = PgPool::connect(&url)
.await
.expect("Failed to connect to test database");
ensure_schema(&pool).await.expect("Failed to create schema");
// Clean up from previous test runs
@@ -118,13 +122,11 @@ async fn test_product_creation_on_component_create() {
config.owner_resolution.assign_all_members = false;
let client = DefectDojoClient::new(mock_server.uri(), "test-token".to_string()).unwrap();
let engagement_handler = Arc::new(
charybdis_defectdojo::handlers::EngagementHandler::new(
client.clone(),
repository.clone(),
HashMap::new(),
),
);
let engagement_handler = Arc::new(charybdis_defectdojo::handlers::EngagementHandler::new(
client.clone(),
repository.clone(),
HashMap::new(),
));
let handler = charybdis_defectdojo::handlers::ProductHandler::new(
client,
@@ -136,7 +138,10 @@ async fn test_product_creation_on_component_create() {
// Create the entity in the database first (returns entity with real UUID)
let entity = make_component_entity("", "payment-api", "team-payments");
let entity = repository.create(&entity).await.expect("Failed to create entity");
let entity = repository
.create(&entity)
.await
.expect("Failed to create entity");
// Trigger handler
let result = handler.handle_create(&entity).await;
@@ -178,13 +183,11 @@ async fn test_product_update_with_existing_product_id() {
let config = make_config(&mock_server.uri());
let client = DefectDojoClient::new(mock_server.uri(), "test-token".to_string()).unwrap();
let engagement_handler = Arc::new(
charybdis_defectdojo::handlers::EngagementHandler::new(
client.clone(),
repository.clone(),
HashMap::new(),
),
);
let engagement_handler = Arc::new(charybdis_defectdojo::handlers::EngagementHandler::new(
client.clone(),
repository.clone(),
HashMap::new(),
));
let handler = charybdis_defectdojo::handlers::ProductHandler::new(
client,
@@ -196,11 +199,13 @@ async fn test_product_update_with_existing_product_id() {
// Create entity with existing product-id annotation
let mut entity = make_component_entity("", "payment-api", "team-payments");
entity.annotations.insert(
"defectdojo.com/product-id".to_string(),
"42".to_string(),
);
let entity = repository.create(&entity).await.expect("Failed to create entity");
entity
.annotations
.insert("defectdojo.com/product-id".to_string(), "42".to_string());
let entity = repository
.create(&entity)
.await
.expect("Failed to create entity");
// Trigger update handler
let result = handler.handle_update(&entity).await;
@@ -228,13 +233,11 @@ async fn test_product_deletion() {
let config = make_config(&mock_server.uri());
let client = DefectDojoClient::new(mock_server.uri(), "test-token".to_string()).unwrap();
let engagement_handler = Arc::new(
charybdis_defectdojo::handlers::EngagementHandler::new(
client.clone(),
repository.clone(),
HashMap::new(),
),
);
let engagement_handler = Arc::new(charybdis_defectdojo::handlers::EngagementHandler::new(
client.clone(),
repository.clone(),
HashMap::new(),
));
let handler = charybdis_defectdojo::handlers::ProductHandler::new(
client,
@@ -246,11 +249,13 @@ async fn test_product_deletion() {
// Entity with product-id annotation
let mut entity = make_component_entity("", "payment-api", "team-payments");
entity.annotations.insert(
"defectdojo.com/product-id".to_string(),
"42".to_string(),
);
let entity = repository.create(&entity).await.expect("Failed to create entity");
entity
.annotations
.insert("defectdojo.com/product-id".to_string(), "42".to_string());
let entity = repository
.create(&entity)
.await
.expect("Failed to create entity");
// Trigger delete handler
let result = handler.handle_delete(&entity).await;
@@ -423,7 +428,10 @@ async fn test_owner_resolution_assigns_product_members() {
member_of: vec!["backend-team".to_string()],
})),
};
alice.annotations.insert("keycloak.com/email".to_string(), "alice@example.com".to_string());
alice.annotations.insert(
"keycloak.com/email".to_string(),
"alice@example.com".to_string(),
);
repository.create(&alice).await.unwrap();
// Create User "bob" with keycloak email annotation
@@ -448,18 +456,19 @@ async fn test_owner_resolution_assigns_product_members() {
member_of: vec!["backend-team".to_string()],
})),
};
bob.annotations.insert("keycloak.com/email".to_string(), "bob@example.com".to_string());
bob.annotations.insert(
"keycloak.com/email".to_string(),
"bob@example.com".to_string(),
);
repository.create(&bob).await.unwrap();
// Create handlers
let client = DefectDojoClient::new(mock_server.uri(), "test-token".to_string()).unwrap();
let engagement_handler = Arc::new(
charybdis_defectdojo::handlers::EngagementHandler::new(
client.clone(),
repository.clone(),
HashMap::new(),
),
);
let engagement_handler = Arc::new(charybdis_defectdojo::handlers::EngagementHandler::new(
client.clone(),
repository.clone(),
HashMap::new(),
));
let handler = charybdis_defectdojo::handlers::ProductHandler::new(
client,
@@ -489,7 +498,9 @@ async fn test_owner_resolution_assigns_product_members() {
);
// Owner member IDs should be set
assert!(
updated.annotations.contains_key("defectdojo.com/owner-member-ids"),
updated
.annotations
.contains_key("defectdojo.com/owner-member-ids"),
"Expected owner-member-ids annotation"
);
}
@@ -529,13 +540,11 @@ async fn test_product_creation_without_engagement() {
config.default_engagement.auto_create = false;
let client = DefectDojoClient::new(mock_server.uri(), "test-token".to_string()).unwrap();
let engagement_handler = Arc::new(
charybdis_defectdojo::handlers::EngagementHandler::new(
client.clone(),
repository.clone(),
HashMap::new(),
),
);
let engagement_handler = Arc::new(charybdis_defectdojo::handlers::EngagementHandler::new(
client.clone(),
repository.clone(),
HashMap::new(),
));
let handler = charybdis_defectdojo::handlers::ProductHandler::new(
client,
@@ -557,7 +566,9 @@ async fn test_product_creation_without_engagement() {
updated.annotations.get("defectdojo.com/product-id"),
Some(&"55".to_string())
);
assert!(!updated.annotations.contains_key("defectdojo.com/engagement-id"));
assert!(!updated
.annotations
.contains_key("defectdojo.com/engagement-id"));
}
// ──────────────────────────────────────────────────────────────
@@ -583,13 +594,11 @@ async fn test_product_creation_handles_api_error() {
let config = make_config(&mock_server.uri());
let client = DefectDojoClient::new(mock_server.uri(), "test-token".to_string()).unwrap();
let engagement_handler = Arc::new(
charybdis_defectdojo::handlers::EngagementHandler::new(
client.clone(),
repository.clone(),
HashMap::new(),
),
);
let engagement_handler = Arc::new(charybdis_defectdojo::handlers::EngagementHandler::new(
client.clone(),
repository.clone(),
HashMap::new(),
));
let handler = charybdis_defectdojo::handlers::ProductHandler::new(
client,