use crate::csaf::types::csaf_document_category::CsafDocumentCategory;
use crate::csaf_traits::{CsafTrait, DocumentTrait, NoteTrait};
use crate::schema::csaf2_1::schema::NoteCategory;
use crate::validation::ValidationError;
use crate::validations::utils::document_category_test_config::DocumentCategoryTestConfig;
fn create_missing_note_error(doc_category: CsafDocumentCategory) -> ValidationError {
ValidationError {
message: format!(
"Document with category '{doc_category}' must have at least one document note with category 'description', 'details', 'general' or 'summary'"
),
instance_path: "/document/notes".to_string(),
}
}
const PROFILE_TEST_CONFIG: DocumentCategoryTestConfig = DocumentCategoryTestConfig::new().shared(&[
CsafDocumentCategory::CsafInformationalAdvisory,
CsafDocumentCategory::CsafSecurityIncidentResponse,
]);
pub fn test_6_1_27_01_document_notes(doc: &impl CsafTrait) -> Result<(), Vec<ValidationError>> {
let doc_category = doc.get_document().get_category();
if !PROFILE_TEST_CONFIG.matches_category_with_csaf_version(doc.get_document().get_csaf_version(), &doc_category) {
return Ok(()); }
let mut found_valid_note = false;
if let Some(notes) = doc.get_document().get_notes() {
for note in notes {
let category = note.get_category();
if category == NoteCategory::Description
|| category == NoteCategory::Details
|| category == NoteCategory::General
|| category == NoteCategory::Summary
{
found_valid_note = true;
break;
}
}
}
if !found_valid_note {
return Err(vec![create_missing_note_error(doc_category)]);
}
Ok(())
}
crate::test_validation::impl_validator!(ValidatorForTest6_1_27_1, test_6_1_27_01_document_notes);
#[cfg(test)]
mod tests {
use super::*;
use crate::csaf2_0::testcases::TESTS_2_0;
use crate::csaf2_1::testcases::TESTS_2_1;
#[test]
fn test_test_6_1_27_01() {
let case_security_incident_response_no_valid_note = Err(vec![create_missing_note_error(
CsafDocumentCategory::CsafSecurityIncidentResponse,
)]);
TESTS_2_0
.test_6_1_27_1
.expect(case_security_incident_response_no_valid_note.clone());
TESTS_2_1
.test_6_1_27_1
.expect(case_security_incident_response_no_valid_note);
}
}