-
Notifications
You must be signed in to change notification settings - Fork 3
feat: add test 6.1.26 #214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
peinjoh
wants to merge
7
commits into
main
Choose a base branch
from
feat/99-test-6-1-26
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
453e149
feat: add test 6.1.26
peinjoh 17dcf02
fix: correct comments
peinjoh 5928a4a
fix: clippy
peinjoh d1ce2f9
format: fmt
peinjoh 9d557af
fix: remove comments
peinjoh 2eeb350
fix: remove regex, improve implementation
peinjoh 3f33475
fix: improve comments and rename Other to CsafBaseOther
peinjoh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| use crate::csaf_traits::{CsafTrait, CsafVersion, DocumentCategory, DocumentTrait}; | ||
| use crate::validation::ValidationError; | ||
|
|
||
| /// 6.1.26 Prohibited Document Category Name | ||
| pub fn test_6_1_26_prohibited_document_category(doc: &impl CsafTrait) -> Result<(), Vec<ValidationError>> { | ||
| let version = doc.get_document().get_csaf_version(); | ||
| let doc_category = doc.get_document().get_category(); | ||
|
|
||
| // skip test for known profiles and categories | ||
| if doc_category.is_known_profile(version) { | ||
| return Ok(()); | ||
| } | ||
|
|
||
| // throw error, as only known profiles are allowed to start with "csaf_" | ||
| if doc_category.starts_with_csaf_underscore() { | ||
| return Err(vec![test_6_1_27_6_err_generator_starts_with_csaf( | ||
| &doc_category, | ||
| version, | ||
| )]); | ||
| } | ||
|
|
||
| // throw error if document category is too similar to known categories | ||
| // this is done by comparing normalized versions of the categories | ||
| for normalized_known_category in DocumentCategory::known_profiles_normalized(version) { | ||
| if doc_category.normalize() == normalized_known_category.0 { | ||
| return Err(vec![test_6_1_27_6_err_generator_too_similar( | ||
| &doc_category, | ||
| &normalized_known_category.1, | ||
| )]); | ||
| } | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| fn test_6_1_27_6_err_generator_starts_with_csaf( | ||
| doc_category: &DocumentCategory, | ||
| version: &CsafVersion, | ||
| ) -> ValidationError { | ||
| ValidationError { | ||
| message: format!( | ||
| "Document category '{}' is prohibited. Only the following values are allowed to starting with 'csaf_' are allowed: {}", | ||
| doc_category, | ||
| DocumentCategory::known_profile_concat(version) | ||
| ), | ||
| instance_path: "/document/category".to_string(), | ||
| } | ||
| } | ||
|
|
||
| fn test_6_1_27_6_err_generator_too_similar( | ||
| doc_category: &DocumentCategory, | ||
| known_category: &DocumentCategory, | ||
| ) -> ValidationError { | ||
| ValidationError { | ||
| message: format!( | ||
| "Document category '{}' is prohibited. It is too similar to the known category: {}", | ||
| doc_category, known_category | ||
| ), | ||
| instance_path: "/document/category".to_string(), | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use crate::csaf_traits::DocumentCategory; | ||
| use crate::test_helper::{run_csaf20_tests, run_csaf21_tests}; | ||
| use crate::validations::test_6_1_26::{ | ||
| test_6_1_26_prohibited_document_category, test_6_1_27_6_err_generator_too_similar, | ||
| }; | ||
| use std::collections::HashMap; | ||
|
|
||
| #[test] | ||
| fn test_test_6_1_26() { | ||
| let errors = HashMap::from([ | ||
| ( | ||
| "01", | ||
| vec![test_6_1_27_6_err_generator_too_similar( | ||
| &DocumentCategory::from_string("Security_Incident_Response"), | ||
| &DocumentCategory::CsafSecurityIncidentResponse, | ||
| )], | ||
| ), | ||
| ( | ||
| "02", | ||
| vec![test_6_1_27_6_err_generator_too_similar( | ||
| &DocumentCategory::from_string("Deprecated Security Advisory"), | ||
| &DocumentCategory::CsafDeprecatedSecurityAdvisory, | ||
| )], | ||
| ), | ||
| ( | ||
| "03", | ||
| vec![test_6_1_27_6_err_generator_too_similar( | ||
| &DocumentCategory::from_string("withdrawn"), | ||
| &DocumentCategory::CsafWithdrawn, | ||
| )], | ||
| ), | ||
| ( | ||
| "04", | ||
| vec![test_6_1_27_6_err_generator_too_similar( | ||
| &DocumentCategory::from_string("superseded"), | ||
| &DocumentCategory::CsafSuperseded, | ||
| )], | ||
| ), | ||
| ]); | ||
| run_csaf20_tests("26", test_6_1_26_prohibited_document_category, errors.clone()); | ||
| run_csaf21_tests("26", test_6_1_26_prohibited_document_category, errors); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we do a
to_lowerhere? I would expect it to match if the casing is different.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would argue that that is explicitly not the case. Test 6.1.26 and the profile tests (6.1.27.x) that make heavy use of this mention an explicit list of document category strings to be checked against. Example from 6.1.26 from CSAF 2.0:
In the context of 6.1.26,
csaf_vExshould hit the "leading csaf_ substring without being known document category" error andCsaf_vexandCsaf_Vexshould hit the "document category too similar to 'csaf_vex'" error.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tschmidtb51 will discussing this with @tziemek, we came up on two cases that we are unsure how to handle:
First, if the category string is
csafvex, there isn't a reserved prefixcsaf_, so we would lowercase it for the case-insensitive comparison, remove all whitespace, hyphen and underscore, of which there are none, so the value for the comparison iscsafvex.This would be compared to
csaf_vex, which when applied the same steps, gives the value for the comparisonvex.The comparison would be
csafvexvsvex, which would not match, and socsafvexwould be a valid value.We could circumvent this by removing all remove all whitespace, hyphen and underscores first, then checking for the
csaf(without the appended_) prefix, then lowercasing.But for this, we would need to look a
csafprefix instead of acsaf_prefix.Second, we are unsure if how casing should be handled when the case-insensitive characters are all correct, i.e.
Csaf_vex,Csaf_Vex,csaf_Vex. In chapter 4.1, the following is given:The value of /document/category SHALL NOT be equal to any value that is intended to only be used by another profile nor to the (case insensitive) name of any other profile from the standard.Does the "(case insensitive)" apply to the "any value that is intended to only be used by another profile" here too?