Skip to content

Commit

Permalink
Feature/unit testing (#89)
Browse files Browse the repository at this point in the history
* 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<String> 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.  oasis-tcs/cti-stix2#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
  • Loading branch information
StephenOTT authored Feb 20, 2019
1 parent 8f7a602 commit b9d4f47
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>io.digitalstate.stix</groupId>
<artifactId>stix</artifactId>
<version>v0.6</version>
<version>v0.6.1</version>
<packaging>jar</packaging>

<name>STIX 2</name>
Expand Down Expand Up @@ -65,7 +65,6 @@
<version>2.4.0</version>
</dependency>


<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
Expand Down Expand Up @@ -125,6 +124,7 @@
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.15</version>
<scope>test</scope>
</dependency>
<dependency> <!-- enables mocking of classes (in addition to interfaces) -->
<groupId>net.bytebuddy</groupId>
Expand Down Expand Up @@ -174,7 +174,7 @@
<executions>
<execution>
<goals>
<goal>compile</goal>
<!--<goal>compile</goal>-->
<goal>compileTests</goal>
</goals>
</execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")
Expand All @@ -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<Instant> getCreated();

@JsonProperty("cwd")
Expand Down
2 changes: 1 addition & 1 deletion src/test/groovy/stix/sdo/ObservedDataSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
2 changes: 1 addition & 1 deletion src/test/groovy/stix/sdo/ReportSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit b9d4f47

Please sign in to comment.