@@ -167,6 +167,7 @@ def adjust_tests_and_groups(self) -> None:
167
167
the model from the list of unit tests. Also, preemptively skips all manual tests, as well as
168
168
tests for experimental/deprecated detections and Correlation type detections.
169
169
"""
170
+
170
171
# Since ManualTest and UnitTest are not differentiable without looking at the manual_test
171
172
# tag, Pydantic builds all tests as UnitTest objects. If we see the manual_test flag, we
172
173
# convert these to ManualTest
@@ -789,6 +790,45 @@ def search_observables_exist_validate(self):
789
790
# Found everything
790
791
return self
791
792
793
+ @field_validator ("tests" , mode = "before" )
794
+ def ensure_yml_test_is_unittest (cls , v :list [dict ]):
795
+ """The typing for the tests field allows it to be one of
796
+ a number of different types of tests. However, ONLY
797
+ UnitTest should be allowed to be defined in the YML
798
+ file. If part of the UnitTest defined in the YML
799
+ is incorrect, such as the attack_data file, then
800
+ it will FAIL to be instantiated as a UnitTest and
801
+ may instead be instantiated as a different type of
802
+ test, such as IntegrationTest (since that requires
803
+ less fields) which is incorrect. Ensure that any
804
+ raw data read from the YML can actually construct
805
+ a valid UnitTest and, if not, return errors right
806
+ away instead of letting Pydantic try to construct
807
+ it into a different type of test
808
+
809
+ Args:
810
+ v (list[dict]): list of dicts read from the yml.
811
+ Each one SHOULD be a valid UnitTest. If we cannot
812
+ construct a valid unitTest from it, a ValueError should be raised
813
+
814
+ Returns:
815
+ _type_: The input of the function, assuming no
816
+ ValueError is raised.
817
+ """
818
+ valueErrors :list [ValueError ] = []
819
+ for unitTest in v :
820
+ #This raises a ValueError on a failed UnitTest.
821
+ try :
822
+ UnitTest .model_validate (unitTest )
823
+ except ValueError as e :
824
+ valueErrors .append (e )
825
+ if len (valueErrors ):
826
+ raise ValueError (valueErrors )
827
+ # All of these can be constructred as UnitTests with no
828
+ # Exceptions, so let the normal flow continue
829
+ return v
830
+
831
+
792
832
@field_validator ("tests" )
793
833
def tests_validate (
794
834
cls ,
0 commit comments