Commit Graph

1454 Commits (master)

Author SHA1 Message Date
Michael Chisholm 5589480980 Improved the exception class hierarchy:
- Removed all plain python base classes (e.g. ValueError, TypeError)
- Renamed InvalidPropertyConfigurationError -> PropertyPresenceError,
  since incorrect values could be considered a property config error, and
  I really just wanted this class to apply to presence (co-)constraint
  violations.
- Added ObjectConfigurationError as a superclass of InvalidValueError,
  PropertyPresenceError, and any other exception that could be raised
  during _STIXBase object init, which is when the spec compliance
  checks happen.  This class is intended to represent general spec
  violations.
- Did some class reordering in exceptions.py, so all the
  ObjectConfigurationError subclasses were together.

Changed how property "cleaning" errors were handled:
- Previous docs said they should all be ValueErrors, but that would require
  extra exception check-and-replace complexity in the property
  implementations, so that requirement is removed.  Doc is changed to just
  say that cleaning problems should cause exceptions to be raised.
  _STIXBase._check_property() now handles most exception types, not just
  ValueError.
- Decided to try chaining the original clean error to the InvalidValueError,
  in case the extra diagnostics would be helpful in the future.  This is
  done via 'six' adapter function and only works on python3.
- A small amount of testing was removed, since it was looking at custom
  exception properties which became unavailable once the exception was
  replaced with InvalidValueError.

Did another pass through unit tests to fix breakage caused by the changed
exception class hierarchy.

Removed unnecessary observable extension handling code from
parse_observable(), since it was all duplicated in ExtensionsProperty.
The redundant code in parse_observable() had different exception behavior
than ExtensionsProperty, which makes the API inconsistent and unit tests
more complicated.  (Problems in ExtensionsProperty get replaced with
InvalidValueError, but extensions problems handled directly in
parse_observable() don't get the same replacement, and so the exception
type is different.)

Redid the workbench monkeypatching.  The old way was impossible to make
work, and had caused ugly ripple effect hackage in other parts of the
codebase.  Now, it replaces the global object maps with factory functions
which behave the same way when called, as real classes.  Had to fix up a
few unit tests to get them all passing with this monkeypatching in place.
Also remove all the xfail markings in the workbench test suite, since all
tests now pass.

Since workbench monkeypatching isn't currently affecting any unit tests,
tox.ini was simplified to remove the special-casing for running the
workbench tests.

Removed the v20 workbench test suite, since the workbench currently only
works with the latest stix object version.
2019-07-19 14:50:11 -04:00
Desai, Kartikey H 4660d5ea28 Update SCO specs per WD 05 specs 2019-07-17 15:48:09 -04:00
Michael Chisholm cd0c4984fa Fix most unit tests to pass again. Awaiting feedback regarding
possible library bugs, before I fix the remaining unit tests.
2019-07-16 16:10:25 -04:00
Michael Chisholm 1b7abaf228 WIP: updating objects to be compliant with stix2.1 WD05. This
includes SDO/SRO class updates, but no unit test updates.  The
class updates broke unit tests, so that still needs to be
addressed.
2019-07-14 15:34:31 -04:00
Emmanuelle Vargas-Gonzalez b1fa177f07
Merge pull request #275 from khdesai/stix21master
Stix21master, add infrastructure, grouping to the working branch
2019-07-10 10:35:57 -04:00
Desai, Kartikey H b464a9cc0a Remove certain human message assertions from test suites 2019-07-09 13:34:19 -04:00
Desai, Kartikey H ae35d2ab01 Add and update tests to conform code to WD04 SDO specs 2019-07-02 13:17:43 -04:00
Desai, Kartikey H ffbf5fa34c Fix JSON encoding issue within tests 2019-07-01 15:41:44 -04:00
Desai, Kartikey H c98fcafb1a Update tests to address conformance to WD04 specs 2019-07-01 15:26:30 -04:00
Desai, Kartikey H ef408e1971 preliminary changes to make stix2 code conform to WD 04 specs 2019-07-01 11:52:55 -04:00
chrisr3d b204b9fdda Merge branch 'master' of github.com:oasis-open/cti-python-stix2 2019-07-01 08:51:26 +02:00
Chris Lenk 244d8c969a
Merge pull request #274 from chrisr3d/master
Avoid issues using parse on bundles
2019-06-28 12:49:17 -04:00
Chris Lenk 953a91ba8e
Merge pull request #273 from chisholm/update_course_of_action
Update course of action for stix2.1 (again)
2019-06-28 12:32:14 -04:00
Chris Lenk 266516ebbc
Merge pull request #272 from chisholm/malware_analysis
Add stix2.1 malware-analysis SDO
2019-06-28 09:57:47 -04:00
chrisr3d 6aff018695
fix: Avoid issues with custom objects
- Custom objects type is dict, which makes it fail
  when the attribute 'id' is called
2019-06-27 17:19:05 +02:00
Michael Chisholm e779cacf3e Update course of action tests, to include tests with the
action_reference property.  Also, stylistic changes to hopefully
let it do more testing with less code.
2019-06-26 21:01:41 -04:00
Michael Chisholm de93a2ee32 Fix stix2.1 course-of-action SDO class properties action_reference
and action_bin to have the correct types.
2019-06-26 19:54:28 -04:00
Michael Chisholm c6132537b8 Changes from add-trailing-comma hook 2019-06-26 17:17:16 -04:00
Michael Chisholm 68f93f4110 Oops, forgot to add the malware-analysis test suite... 2019-06-26 17:10:04 -04:00
Michael Chisholm 5c92db9861 Add stix2.1 malware-analysis SDO 2019-06-26 17:06:26 -04:00
Chris Lenk b8c5bec101 Merge branch 'master' into stix2.1 2019-06-26 12:22:40 -04:00
Chris Lenk 7e989dd13d Merge branch 'chisholm-update_observed_data' into stix2.1 2019-06-26 11:22:12 -04:00
Chris Lenk 28ac284b84 Remove unnecessary ObservedData constraint
first_observed and last_observed are both required, so this co-constraint was removed from WD04.
2019-06-26 11:18:47 -04:00
chrisr3d 565acc7618 Merge branch 'master' of github.com:oasis-open/cti-python-stix2 2019-06-25 09:06:50 +02:00
Michael Chisholm 58ff89f112 Update observed-data SDO class, adding the new stix2.1 property
"object_refs".  Added a couple tests for it.
2019-06-21 15:44:04 -04:00
Chris Lenk 49501029dd
Merge pull request #269 from chisholm/update_id_properties
Update id properties
2019-06-21 15:40:35 -04:00
Michael Chisholm 23d5bef2ec Change all uses of multi-STIX-version properties (i.e. those
with a spec_version constructor argument) in STIX-version-specific
contexts, to explicitly specify the STIX version.
2019-06-21 14:29:08 -04:00
Michael Chisholm 9cc1e6e8c1 Change location of DEFAULT_VERSION definition, to be before
the imports.  This ensures the attribute will be defined even if
there are import loops.
2019-06-21 14:26:48 -04:00
Michael Chisholm 8bb6c79f1d Change import order to satisfy style checkers... 2019-06-21 14:25:36 -04:00
Michael Chisholm f9578313a0 Change stix2.DEFAULT_VERSION to "2.1" on the stix2.1 branch. 2019-06-21 13:20:37 -04:00
Michael Chisholm ea98a53fae Change all hard-coded spec_version defaults in property classes
to stix2.DEFAULT_VERSION.
2019-06-21 13:18:51 -04:00
Michael Chisholm d61b543266 Style changes to satisfy the 'style' tox check 2019-06-14 18:10:38 -04:00
Michael Chisholm a150b0f4aa Change all uses of IDProperty and ReferenceProperty to specify
a particular spec_version.
2019-06-14 17:58:51 -04:00
Michael Chisholm da5978d317 Factored out more of the STIX identifier validity checking,
partly inspired by PR #263.  This resulted in some error message
format changes (an improvement, I think), which caused some
unit test breakage.  Removed those asserts from the unit tests,
since tests shouldn't be testing human-targeted error messages.
2019-06-13 18:37:21 -04:00
Michael Chisholm ed106f23ff Update IDProperty and ReferenceProperty to support both stix 2.0
and 2.1 rules regarding identifiers.  Change relevant property
tests to specify which spec version to use, and modify tests
according to the specs.
2019-06-12 20:19:47 -04:00
Chris Lenk 5b6a0dc087
Merge pull request #268 from chisholm/update_course_of_action
Update stix2.1 course-of-action support to the latest spec.
2019-06-12 17:09:31 -04:00
Michael Chisholm 4f593e6d16 Changes from the add-trailing-comma pre-commit hook 2019-06-12 14:49:34 -04:00
Michael Chisholm caa1d45ae2 Update stix2.1 course-of-action support to the latest spec. 2019-06-11 18:10:02 -04:00
Chris Lenk a6fa3ff1d7 Slightly change bundle error message 2019-05-22 11:05:01 -04:00
Chris Lenk 51b2db4fba
Merge pull request #264 from khdesai/stix2_issue_257
Stix2 issue 257: make accessing bundles easier
2019-05-22 09:59:42 -04:00
Desai, Kartikey H ce86db2a12 Fixes #257 2019-05-20 15:36:35 -05:00
Desai, Kartikey H 86790a736f Fixes #257 2019-05-20 15:29:01 -05:00
Desai, Kartikey H 45d3020518 Fixes #257 2019-05-17 14:21:35 -05:00
Desai, Kartikey H a61344a8aa Add get_obj function to bundle.py to make accessing bundles easier 2019-05-14 13:48:54 -04:00
Chris Lenk 67f6663e5e
Merge pull request #262 from khdesai/master
Fixes #175 - Add documentation for _valid_refs
2019-05-13 10:36:30 -04:00
Kartikey Desai 1bf12221a0 Update _valid_refs doc and add test to v20 test suite 2019-05-13 09:18:50 -04:00
Kartikey Desai 8946308527 Updated documentation for _valid_refs 2019-05-10 12:30:52 -04:00
Desai, Kartikey H 3a33dbe2fa Merge branch 'stix2_issue_175' of https://github.com/khdesai/cti-python-stix2 2019-05-10 11:56:43 -04:00
Kartikey Desai 989f17e673 Add documentation for _valid_refs 2019-05-10 11:54:59 -04:00
Desai, Kartikey H f79b3c9876 Add functionality to _valid_refs to accept actual cyber observable objects instead of just strings with their types 2019-05-10 10:22:45 -04:00