nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: oasis-open/cti-python-stix2
Pull request #63 (2017-10-04 14:38:01)

Fix timestamp constant
Minor fix...

Noticed that in pattern expressions timestamp constants are prefixed by 't'


Patch:
diff --git a/stix2/patterns.py b/stix2/patterns.py
index 7858146..03b7657 100644
--- a/stix2/patterns.py
+++ b/stix2/patterns.py
@@ -24,7 +24,7 @@ class TimestampConstant(_Constant):
         self.value = value
 
     def __str__(self):
-        return "'%s'" % escape_quotes_and_backslashes(self.value)
+        return "t'%s'" % escape_quotes_and_backslashes(self.value)
 
 
 class IntegerConstant(_Constant):


Test patch:
diff --git a/stix2/test/test_pattern_expressions.py b/stix2/test/test_pattern_expressions.py
index e806aa6..0db1083 100644
--- a/stix2/test/test_pattern_expressions.py
+++ b/stix2/test/test_pattern_expressions.py
@@ -170,3 +170,8 @@ def test_set_op():
     exp = stix2.ObservationExpression(stix2.IsSubsetComparisonExpression("network-traffic:dst_ref.value",
                                                                          "2001:0db8:dead:beef:0000:0000:0000:0000/64"))
     assert str(exp) == "[network-traffic:dst_ref.value ISSUBSET '2001:0db8:dead:beef:0000:0000:0000:0000/64']"
+
+
+def test_timestamp():
+    ts = stix2.TimestampConstant('2014-01-13T07:03:17Z')
+    assert str(ts) == "t'2014-01-13T07:03:17Z'"
Repository: oasis-open/cti-python-stix2
Pull request #195 (2018-06-20 20:26:55)

Correct "image_weight" to "image_width".
Can you review this, @emmanvg and @clenk . Want to get a second set of eyes on this. Without the change to `stix2/v20/observables.py`, the test will fail. Once we merge this in, we'll need to make the same change in `stix2/v21/observables.py` in the `stix2.1` branch.


Patch:
diff --git a/stix2/v20/observables.py b/stix2/v20/observables.py
index 098c7dd..659929b 100644
--- a/stix2/v20/observables.py
+++ b/stix2/v20/observables.py
@@ -302,7 +302,7 @@ class RasterImageExt(_Extension):
     _properties = OrderedDict()
     _properties.update([
         ('image_height', IntegerProperty()),
-        ('image_weight', IntegerProperty()),
+        ('image_width', IntegerProperty()),
         ('bits_per_pixel', IntegerProperty()),
         ('image_compression_algorithm', StringProperty()),
         ('exif_tags', DictionaryProperty()),


Test patch:
diff --git a/stix2/test/test_observed_data.py b/stix2/test/test_observed_data.py
index 30c3cab..11c74ca 100644
--- a/stix2/test/test_observed_data.py
+++ b/stix2/test/test_observed_data.py
@@ -765,6 +765,51 @@ def test_file_example_with_RasterImageExt_Object():
     assert f.extensions["raster-image-ext"].exif_tags["XResolution"] == 4928
 
 
+RASTER_IMAGE_EXT = """{
+"type": "observed-data",
+"id": "observed-data--b67d30ff-02ac-498a-92f9-32f845f448cf",
+"created": "2016-04-06T19:58:16.000Z",
+"modified": "2016-04-06T19:58:16.000Z",
+"first_observed": "2015-12-21T19:00:00Z",
+"last_observed": "2015-12-21T19:00:00Z",
+"number_observed": 1,
+"objects": {
+  "0": {
+    "type": "file",
+    "name": "picture.jpg",
+    "hashes": {
+      "SHA-256": "35a01331e9ad96f751278b891b6ea09699806faedfa237d40513d92ad1b7100f"
+    },
+    "extensions": {
+      "raster-image-ext": {
+        "image_height": 768,
+        "image_width": 1024,
+        "bits_per_pixel": 72,
+        "image_compression_algorithm": "JPEG",
+        "exif_tags": {
+          "Make": "Nikon",
+          "Model": "D7000",
+          "XResolution": 4928,
+          "YResolution": 3264
+        }
+      }
+    }
+  }
+}
+}
+"""
+
+
+def test_raster_image_ext_parse():
+    obj = stix2.parse(RASTER_IMAGE_EXT)
+    assert obj.objects["0"].extensions['raster-image-ext'].image_width == 1024
+
+
+def test_raster_images_ext_create():
+    ext = stix2.RasterImageExt(image_width=1024)
+    assert "image_width" in str(ext)
+
+
 def test_file_example_with_WindowsPEBinaryExt():
     f = stix2.File(name="qwerty.dll",
                    extensions={
Repository: oasis-open/cti-python-stix2
Pull request #356 (2020-02-27 21:50:09)

Add the "sample_ref" property to malware-analysis SDOs
From https://github.com/oasis-tcs/cti-stix2/issues/210
Fixes half of #339 .


Patch:
diff --git a/stix2/v21/sdo.py b/stix2/v21/sdo.py
index 1d97261..2bc02cc 100644
--- a/stix2/v21/sdo.py
+++ b/stix2/v21/sdo.py
@@ -526,6 +526,7 @@ class MalwareAnalysis(STIXDomainObject):
         ('analysis_ended', TimestampProperty()),
         ('av_result', StringProperty()),
         ('analysis_sco_refs', ListProperty(ReferenceProperty(valid_types="SCO", spec_version='2.1'))),
+        ('sample_ref', ReferenceProperty(valid_types="SCO", spec_version="2.1")),
     ])
 
     def _check_object_constraints(self):


Test patch:
diff --git a/stix2/test/v21/test_malware_analysis.py b/stix2/test/v21/test_malware_analysis.py
index bfb4ff4..b5e65aa 100644
--- a/stix2/test/v21/test_malware_analysis.py
+++ b/stix2/test/v21/test_malware_analysis.py
@@ -38,7 +38,8 @@ MALWARE_ANALYSIS_JSON = """{
     "analysis_sco_refs": [
         "file--fc27e371-6c88-4c5c-868a-4dda0e60b167",
         "url--6f7a74cd-8eb2-4b88-a4da-aa878e50ac2e"
-    ]
+    ],
+    "sample_ref": "email-addr--499a32d7-74c1-4276-ace9-725ac933e243"
 }"""
Repository: oasis-open/cti-python-stix2
Pull request #357 (2020-02-27 22:34:11)

Update malware-analysis SDO's av_result property
From https://github.com/oasis-tcs/cti-stix2/issues/213
Fixes half of #339 .

Replace the `av_result` property with `result` and `result_name` properties.



Patch:
diff --git a/stix2/v21/sdo.py b/stix2/v21/sdo.py
index 1d97261..2e3cb13 100644
--- a/stix2/v21/sdo.py
+++ b/stix2/v21/sdo.py
@@ -524,14 +524,15 @@ class MalwareAnalysis(STIXDomainObject):
         ('submitted', TimestampProperty()),
         ('analysis_started', TimestampProperty()),
         ('analysis_ended', TimestampProperty()),
-        ('av_result', StringProperty()),
+        ('result_name', StringProperty()),
+        ('result', StringProperty()),
         ('analysis_sco_refs', ListProperty(ReferenceProperty(valid_types="SCO", spec_version='2.1'))),
     ])
 
     def _check_object_constraints(self):
         super(MalwareAnalysis, self)._check_object_constraints()
 
-        self._check_at_least_one_property(["av_result", "analysis_sco_refs"])
+        self._check_at_least_one_property(["result", "analysis_sco_refs"])
 
 
 class Note(STIXDomainObject):


Test patch:
diff --git a/stix2/test/v21/test_malware_analysis.py b/stix2/test/v21/test_malware_analysis.py
index bfb4ff4..94301f2 100644
--- a/stix2/test/v21/test_malware_analysis.py
+++ b/stix2/test/v21/test_malware_analysis.py
@@ -34,7 +34,8 @@ MALWARE_ANALYSIS_JSON = """{
     "submitted": "2018-11-23T06:45:55.747Z",
     "analysis_started": "2018-11-29T07:30:03.895Z",
     "analysis_ended": "2018-11-29T08:30:03.895Z",
-    "av_result": "malicious",
+    "result_name": "MegaRansom",
+    "result": "malicious",
     "analysis_sco_refs": [
         "file--fc27e371-6c88-4c5c-868a-4dda0e60b167",
         "url--6f7a74cd-8eb2-4b88-a4da-aa878e50ac2e"
Repository: oasis-open/cti-python-stix2
Pull request #553 (2022-08-01 14:02:33)

Test harness update


Patch:
diff --git a/setup.py b/setup.py
index f383ebd..bf01b13 100644
--- a/setup.py
+++ b/setup.py
@@ -40,14 +40,14 @@ setup(
         'Topic :: Security',
         'License :: OSI Approved :: BSD License',
         'Programming Language :: Python :: 3',
-        'Programming Language :: Python :: 3.6',
         'Programming Language :: Python :: 3.7',
         'Programming Language :: Python :: 3.8',
         'Programming Language :: Python :: 3.9',
+        'Programming Language :: Python :: 3.10',
     ],
     keywords='stix stix2 json cti cyber threat intelligence',
     packages=find_packages(exclude=['*.test', '*.test.*']),
-    python_requires='>=3.6',
+    python_requires='>=3.7',
     install_requires=[
         'pytz',
         'requests',
diff --git a/tox.ini b/tox.ini
index 90f5cfc..2697458 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,5 +1,5 @@
 [tox]
-envlist = py36,py37,py38,py39,packaging,pre-commit-check
+envlist = py37,py38,py39,py310,packaging,pre-commit-check
 
 [testenv]
 deps =
@@ -32,7 +32,7 @@ commands =
 
 [gh-actions]
 python =
-  3.6: py36
   3.7: py37
   3.8: py38
   3.9: py39, packaging, pre-commit-check
+  3.10: py310


Test patch:
diff --git a/.github/workflows/python-ci-tests.yml b/.github/workflows/python-ci-tests.yml
index dc9ccc0..211aa4c 100644
--- a/.github/workflows/python-ci-tests.yml
+++ b/.github/workflows/python-ci-tests.yml
@@ -9,7 +9,7 @@ jobs:
     runs-on: ubuntu-latest
     strategy:
       matrix:
-        python-version: [3.6, 3.7, 3.8, 3.9]
+        python-version: [3.7, 3.8, 3.9, '3.10']
 
     name: Python ${{ matrix.python-version }} Build
     steps:
Repository: oasis-open/cti-stix-validator
Pull request #60 (2018-06-14 13:43:03)

Fix bug when no 'files' option provided to library


Patch:
diff --git a/stix2validator/util.py b/stix2validator/util.py
index eab52cb..8a9ce11 100644
--- a/stix2validator/util.py
+++ b/stix2validator/util.py
@@ -251,6 +251,10 @@ def parse_args(cmd_args, is_script=False):
     )
 
     args = parser.parse_args(cmd_args)
+
+    if not is_script:
+        args.files = ""
+
     return ValidationOptions(args)
 
 


Test patch:
diff --git a/stix2validator/test/util_tests.py b/stix2validator/test/util_tests.py
index 079587f..4bce298 100644
--- a/stix2validator/test/util_tests.py
+++ b/stix2validator/test/util_tests.py
@@ -1,4 +1,5 @@
-from .. import parse_args
+from .. import parse_args, validate_string
+from .indicator_tests import VALID_INDICATOR
 
 
 def test_parse_args():
@@ -34,3 +35,12 @@ def test_parse_args():
     assert options.no_cache is True
     assert options.refresh_cache is True
     assert options.clear_cache is True
+
+
+def test_parse_args_no_files():
+    args = []
+    options = parse_args(args)
+    assert options.files == ""
+
+    results = validate_string(VALID_INDICATOR, options)
+    assert results.is_valid
Repository: oasis-open/cti-stix-validator
Pull request #168 (2021-04-28 22:26:57)

Fix bug with patternless indicators


Patch:
diff --git a/stix2validator/v21/musts.py b/stix2validator/v21/musts.py
index 5d7a247..86a24f5 100644
--- a/stix2validator/v21/musts.py
+++ b/stix2validator/v21/musts.py
@@ -410,7 +410,7 @@ def patterns(instance, options):
     objects and properties referenced by the pattern are valid.
     """
     if (instance['type'] != 'indicator' or instance.get('pattern_type', '') != 'stix' or
-            isinstance(instance.get('pattern', ''), str) is False):
+            isinstance(instance.get('pattern', None), str) is False):
         return
 
     pattern = instance['pattern']


Test patch:
diff --git a/stix2validator/test/v21/indicator_tests.py b/stix2validator/test/v21/indicator_tests.py
index 59d4db2..36205d4 100644
--- a/stix2validator/test/v21/indicator_tests.py
+++ b/stix2validator/test/v21/indicator_tests.py
@@ -301,6 +301,12 @@ class IndicatorTestCases(ValidatorTest):
         self.assertFalseWithOptions(indicator)
         self.check_ignore(indicator, 'indicator-pattern-types')
 
+    def test_indicator_no_pattern(self):
+        indicator = copy.deepcopy(self.valid_indicator)
+        del indicator["pattern"]
+
+        self.assertFalseWithOptions(indicator)
+
     def test_indicator_no_pattern_type(self):
         indicator = copy.deepcopy(self.valid_indicator)
         del indicator["pattern_type"]
Repository: oasis-open/cti-stix-validator
Pull request #178 (2021-06-26 03:29:19)

Fix timestamp comparisons for CS03
Two sets of timestamp properties were change to allow both properties in the set to have the exact same timestamp:
- Sighting: first_seen and last_seen
- Network Traffic: start and end


Patch:
diff --git a/stix2validator/v21/enums.py b/stix2validator/v21/enums.py
index 16615fb..f2aac4e 100644
--- a/stix2validator/v21/enums.py
+++ b/stix2validator/v21/enums.py
@@ -2041,7 +2041,7 @@ TIMESTAMP_COMPARE = {
         ('stop_time', 'gt', 'start_time'),
     ],
     "sighting": [
-        ('last_seen', 'gt', 'first_seen'),
+        ('last_seen', 'ge', 'first_seen'),
     ],
     'threat-actor': [
         ('last_seen', 'ge', 'first_seen')
@@ -2051,7 +2051,7 @@ TIMESTAMP_COMPARE = {
 # Mapping of STIX Object timestamp properties with a comparison requirement
 TIMESTAMP_COMPARE_OBSERVABLE = {
     "network-traffic": [
-        ('end', 'gt', 'start'),
+        ('end', 'ge', 'start'),
     ],
 }
 


Test patch:
diff --git a/stix2validator/test/v21/network_traffic_tests.py b/stix2validator/test/v21/network_traffic_tests.py
index e38b45b..669a71d 100644
--- a/stix2validator/test/v21/network_traffic_tests.py
+++ b/stix2validator/test/v21/network_traffic_tests.py
@@ -119,11 +119,11 @@ class ObservedDataTestCases(ValidatorTest):
     def test_invalid_start_end_time(self):
         net_traffic = copy.deepcopy(self.valid_net_traffic)
         net_traffic['start'] = "2016-04-06T20:06:37.000Z"
-        net_traffic['end'] = "2016-04-06T20:06:37.000Z"
-        self.assertFalseWithOptions(net_traffic)
-
         net_traffic['end'] = "2016-01-01T00:00:00.000Z"
         self.assertFalseWithOptions(net_traffic)
 
+        net_traffic['end'] = "2016-04-06T20:06:37.000Z"
+        self.assertTrueWithOptions(net_traffic)
+
         net_traffic['end'] = "2016-05-07T20:06:37.000Z"
         self.assertTrueWithOptions(net_traffic)
diff --git a/stix2validator/test/v21/sighting_tests.py b/stix2validator/test/v21/sighting_tests.py
index 65cb77f..7f39f76 100644
--- a/stix2validator/test/v21/sighting_tests.py
+++ b/stix2validator/test/v21/sighting_tests.py
@@ -44,11 +44,11 @@ class IdentityTestCases(ValidatorTest):
     def test_invalid_seen_time(self):
         sighting = copy.deepcopy(self.valid_sighting)
         sighting['first_seen'] = "2016-04-06T20:06:37.000Z"
-        sighting['last_seen'] = "2016-04-06T20:06:37.000Z"
-        self.assertFalseWithOptions(sighting)
-
         sighting['last_seen'] = "2016-01-01T00:00:00.000Z"
         self.assertFalseWithOptions(sighting)
 
+        sighting['last_seen'] = "2016-04-06T20:06:37.000Z"
+        self.assertTrueWithOptions(sighting)
+
         sighting['last_seen'] = "2016-05-07T20:06:37.000Z"
         self.assertTrueWithOptions(sighting)