From b9d4f4745e03e61047d47a51fea25da3b1cfbd79 Mon Sep 17 00:00:00 2001 From: Stephen Russett Date: Tue, 19 Feb 2019 19:22:55 -0500 Subject: [PATCH] Feature/unit testing (#89) * update names of mock methods * fix naming of json annotations for proper updates * Updates to support proper sequence generation * add printing of object and json outputs for manual review and update test description * adds support for IdentitySDO * add identity SDO testing support * Add random label generator * Add support for Campaign SDO * remove tabs * Add course of action, intrusion set tests + fixes to related SDOs + cleanup * add Malware, ObservedData + Artifact + Fix for hashes pluralization * remove old imports * Fix misnamed method * Add Autonomous System COO * Add DirectoryCOO * Add Domain Name COO * Add Email Address COO * removing inner Set from headers to conform to spec, even though its a issue The spec dictates this is a "Dictionary" field. But a dictionary cannot have duplicate fields. https://github.com/oasis-tcs/cti-stix2/issues/138 * Add Email Message COO + MimePartType which is used in email message * Fix bad business rule for email message * add comment * fix bad naming of jsonpropertydescription * Add dupluralizeDictionary values for better method naming * reorder methods to match the ordering in the spec * Add support for File Coo * Cleanup on COO Extension serializer and deserializer for better output * Remove unneeded Annotations as the MimePartType only exists as a sub object and has not "typing" * Add Valid annotation to getBodyMultipart so the MimePartTypeObj is validated against the EmailMessage validation * cleanup + fix file coo issues * add missing GenericValdiation extends on COO inner types * Remove valid anotation as it will be handled by the GenericValidation interface of MimePartTypeObj * convert list mocking to use fromStrings() method provided by mockneat * remove old code for better Mimes dictionary * adjust default range for sector generation in identites * change custom props to generate with prepend * fix regression with threat actor sdo * Add IVP4 COO supporte * Add IPV6 COO support * Add Mac Address COO + MacAddress generation support on IVP4 and IPV6 COO * fix types * Add Mutex and NetworkTraffic COO * Fix type in method name * Add Process COO support * Remove regex until better working pattern can be created * Add Software COO * Add URL coo * fix vocab placement * Add UserAccount COO and cleanup * Add user account coo to Observed Object generator * fix vocab annotation placement * cleanup todo * Add Windows Registry Key Coo support * Fix network traffic annotations for range * fix regex pattern annotaiton placement * Cleanup to fix bugs * Cleanup + Add depluralize dictionary support * Add X509 cert COO support * Add TheatActor, Report, Tool, Vulnerability SDO support plus cleanup * Add alias/aliases dictionary for depluralization of methods * Fix annotation for vocab on labels * Fix business rule that was using incorrect methods (isEmpty vs isPresent) * Add jsonassert * Update attack pattern with use of objectmapper and json assert * Update for using ObjectMapper for serialization/deserialization within specs * cleanup imports * remove unneeded imports from groovy.json * Remove unneeded Style annotation * Add custom properties support onto the Bundle object * Add mock bundle support * Remove old tests that are not needed * remove old json files from tests * refactor and add readme context for test resources * refactor mockDatagenerator groovy trait location * Add custom props support to Marking Objects and Granular Marking Objects * fix javadoc * Add Granular Marking, Object Marking, Statement and TLP support + updated all SDOs with CreatedByRef + Updated Report and Bundle to generate Object Markings * remove markovs are they are way too slow! * rename method for clearner usage * Add Markings Definition support + JsontypeName support for TLP and Statement Markings * refactor vocabularies into clearner packages * update deps and add missing imports for refactor of vocabs packages * Add Relationship and Sighting SROs support. Added to Bundle and Report + Add individual Spec tests * Add missing JsonFormat for created field to insure date format * fix spacing * Convert groovy to test scope * fix missing brackets on method call * up tests runs count to better catching of issues * Update pom.xml --- pom.xml | 6 +++--- src/main/java/io/digitalstate/stix/common/StixModified.java | 2 +- .../java/io/digitalstate/stix/coo/objects/ProcessCoo.java | 4 +++- src/test/groovy/stix/sdo/ObservedDataSpec.groovy | 2 +- src/test/groovy/stix/sdo/ReportSpec.groovy | 2 +- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 4ed4f8a..3c8338d 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ io.digitalstate.stix stix - v0.6 + v0.6.1 jar STIX 2 @@ -65,7 +65,6 @@ 2.4.0 - org.hibernate.validator hibernate-validator @@ -125,6 +124,7 @@ org.codehaus.groovy groovy-all 2.4.15 + test net.bytebuddy @@ -174,7 +174,7 @@ - compile + compileTests diff --git a/src/main/java/io/digitalstate/stix/common/StixModified.java b/src/main/java/io/digitalstate/stix/common/StixModified.java index e8e0c85..fabdb3f 100644 --- a/src/main/java/io/digitalstate/stix/common/StixModified.java +++ b/src/main/java/io/digitalstate/stix/common/StixModified.java @@ -19,7 +19,7 @@ public interface StixModified { @NotNull @JsonProperty("modified") @JsonPropertyDescription("The modified property represents the time that this particular version of the object was created. The timstamp value MUST be precise to the nearest millisecond.") - @JsonFormat(pattern = StixDataFormats.TIMESTAMP_PATTERN, timezone = "UTC") + @JsonFormat(pattern = StixDataFormats.TIMESTAMP_PATTERN, timezone = "UTC") @Value.Default @Redactable default Instant getModified(){ diff --git a/src/main/java/io/digitalstate/stix/coo/objects/ProcessCoo.java b/src/main/java/io/digitalstate/stix/coo/objects/ProcessCoo.java index 7582aee..d07f49c 100644 --- a/src/main/java/io/digitalstate/stix/coo/objects/ProcessCoo.java +++ b/src/main/java/io/digitalstate/stix/coo/objects/ProcessCoo.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import io.digitalstate.stix.coo.CyberObservableObject; +import io.digitalstate.stix.helpers.StixDataFormats; import io.digitalstate.stix.validation.contraints.businessrule.BusinessRule; import io.digitalstate.stix.validation.contraints.defaulttypevalue.DefaultTypeValue; import io.digitalstate.stix.validation.groups.DefaultValuesProcessor; @@ -35,7 +36,7 @@ @JsonPropertyOrder({ "type", "extensions", "is_hidden", "pid", "name", "created", "cwd", "arguments", "command_line", "environment_variables", "opened_connection_refs", "creator_user_ref", "binary_ref", "parent_ref", "child_refs" }) -@BusinessRule(ifExp = "true", thenExp = "getExtensions().isEmpty() == false || isHidden().isPresent() == true || getPid().isPresent() == true || getName().isPresent() == true || getCreated().isPresent() == true || getCwd().isPresent() == true || getArguments().isEmpty() == false || getCommandLine().isPresent() == true || getEnvironmentVariables().isEmpty() == false || getOpenedConnectionRefs().isEmpty() == false || getCreatorUserRef().isPresent() == true || getBinaryRef().isPresent() == true || getParentRef().isPresent() == true || getChildRefs().isEmpty == false", errorMessage = "A Process Object MUST contain at least one property (other than type) from this object (or one of its extensions).") +@BusinessRule(ifExp = "true", thenExp = "getExtensions().isEmpty() == false || isHidden().isPresent() == true || getPid().isPresent() == true || getName().isPresent() == true || getCreated().isPresent() == true || getCwd().isPresent() == true || getArguments().isEmpty() == false || getCommandLine().isPresent() == true || getEnvironmentVariables().isEmpty() == false || getOpenedConnectionRefs().isEmpty() == false || getCreatorUserRef().isPresent() == true || getBinaryRef().isPresent() == true || getParentRef().isPresent() == true || getChildRefs().isEmpty() == false", errorMessage = "A Process Object MUST contain at least one property (other than type) from this object (or one of its extensions).") public interface ProcessCoo extends CyberObservableObject { @JsonProperty("is_hidden") @@ -53,6 +54,7 @@ public interface ProcessCoo extends CyberObservableObject { @JsonProperty("created") @JsonPropertyDescription("Specifies the date/time at which the process was created.") + @JsonFormat(shape=JsonFormat.Shape.STRING, pattern = StixDataFormats.TIMESTAMP_PATTERN, timezone = "UTC") Optional getCreated(); @JsonProperty("cwd") diff --git a/src/test/groovy/stix/sdo/ObservedDataSpec.groovy b/src/test/groovy/stix/sdo/ObservedDataSpec.groovy index 005ea4a..f403295 100644 --- a/src/test/groovy/stix/sdo/ObservedDataSpec.groovy +++ b/src/test/groovy/stix/sdo/ObservedDataSpec.groovy @@ -43,6 +43,6 @@ class ObservedDataSpec extends Specification implements StixMockDataGenerator { JSONAssert.assertEquals(originalJsonString, newJsonString, JSONCompareMode.NON_EXTENSIBLE) where: - i << (1..1000) // More tests are run because of the large variation of probabilities and number of combinations + i << (1..5000) // More tests are run because of the large variation of probabilities and number of combinations } } diff --git a/src/test/groovy/stix/sdo/ReportSpec.groovy b/src/test/groovy/stix/sdo/ReportSpec.groovy index b0abd6b..4d4c907 100644 --- a/src/test/groovy/stix/sdo/ReportSpec.groovy +++ b/src/test/groovy/stix/sdo/ReportSpec.groovy @@ -43,6 +43,6 @@ class ReportSpec extends Specification implements StixMockDataGenerator { JSONAssert.assertEquals(originalJsonString, newJsonString, JSONCompareMode.NON_EXTENSIBLE) where: - i << (1..100) // More tests are run because of the large variation of probabilities and number of combinations + i << (1..500) // More tests are run because of the large variation of probabilities and number of combinations } }