Skip to content

Commit fbcf543

Browse files
committed
Merge branch 'master' of github.com:oasis-open/cti-stix-validator
2 parents d9dc9e1 + 83245cc commit fbcf543

File tree

11 files changed

+99
-21
lines changed

11 files changed

+99
-21
lines changed

.github/workflows/python-ci-tests.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ jobs:
3939
run: |
4040
tox
4141
- name: Upload coverage information to Codecov
42-
uses: codecov/codecov-action@v3
42+
uses: codecov/codecov-action@v4.2.0
4343
with:
44+
token: ${{ secrets.CODECOV_TOKEN }}
4445
fail_ci_if_error: false # optional (default = false)
4546
verbose: true # optional (default = false)

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ repos:
66
exclude: ^stix2validator/(v20|v21)/assets/.*.csv$
77
- id: check-merge-conflict
88
- repo: https://github.com/PyCQA/flake8
9-
rev: 5.0.4
9+
rev: 7.3.0
1010
hooks:
1111
- id: flake8
1212
name: Check project styling

.readthedocs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ version: 2
88
build:
99
os: ubuntu-22.04
1010
tools:
11-
python: "3.12"
11+
python: "3.14"
1212

1313
# Build documentation in the "docs/" directory with Sphinx
1414
sphinx:

README.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,9 @@ repositories/maintainers-guide#additionalMaintainers>`_.
144144
.. Initial Maintainers: Greg Back & Ivan Kirillov & Chris Lenk
145145
146146
* `Emily Ratliff <mailto:emily.ratliff@ibm.com>`__; GitHub ID: `https://github.com/ejratl <https://github.com/ejratl>`_; WWW: `IBM <http://www.ibm.com/>`__
147-
* `Jason Keirstead <mailto:Jason.Keirstead@ca.ibm.com>`__; GitHub ID: `https://github.com/JasonKeirstead <https://github.com/JasonKeirstead>`_; WWW: `IBM <http://www.ibm.com/>`__
148147
* `Rich Piazza <mailto:rpiazza@mitre.org>`_; GitHub ID: `https://github.com/rpiazza <https://github.com/rpiazza>`_; WWW: `MITRE <http://www.mitre.org/>`_
148+
* `Alexandre Dulaunoy <mailto:alexandre.dulaunoy@circl.lu>`__; GitHub ID: https://github.com/adulau; WWW: `CIRCL <http://www.circl.lu/>`__
149+
* `Christian Studer <mailto:christian.studer@circl.lu>`__; GitHub ID: https://github.com/chrisr3d; WWW: `CIRCL <http://www.circl.lu/>`__
149150

150151

151152
.. _aboutOpenRepos:

docs/best-practices.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ Mandatory Checks - STIX 2.1
9999
| | RFC 5646 language code | language code. |
100100
+---------------------------------+----------------------------------------+----------------------------------------+
101101
| software_language | the 'language' property of software | The 'languages' property of object |
102-
| | objects is a valid ISO 639-2 language | '<identifier>' contains an invalid |
103-
| | code | code ('<lang>'). |
102+
| | objects is a valid RFC 5646 language | '<identifier>' contains an invalid |
103+
| | code (ISO 639-2 accepted with warning) | code ('<lang>'). |
104104
+---------------------------------+----------------------------------------+----------------------------------------+
105105
| patterns | that the syntax of the pattern of an | '<object>' is not a valid observable |
106106
| | indicator is valid, and that objects | type name |

pinning-schema.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ Output confirms the schema 2.1 correct commit is pinned:
1212
Entering 'stix2validator/schemas-2.0'
1313
stix2validator/schemas-2.0 b155093705ab4934ee29e7ba4dc99ed053cd4e7f
1414
Entering 'stix2validator/schemas-2.1'
15-
stix2validator/schemas-2.1 4d010b385b83e53ea322357783ff3be3da5820fb
15+
stix2validator/schemas-2.1 c4f8d589acf2bdb3783655c89e0ffb6e150006ae
1616

17-
Push from local to my repo (fork of Oasis) which then feeds the change to the PR on Oasis. I've updated the comments in the PR to confirm.
17+
Push from local to my repo (fork of Oasis) which then feeds the change to the PR on Oasis. I've updated the comments in the PR to confirm.

stix2validator/test/v21/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ def assertTrueWithOptions(self, instance, **kwargs):
3333
else:
3434
options = ValidationOptions(strict=True, **kwargs)
3535
results = validate_parsed_json(instance, options)
36-
print_results(results)
3736
self.assertTrue(results.is_valid)
3837

3938
def assertFalseWithOptions(self, instance, **kwargs):

stix2validator/test/v21/observed_data_tests.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,9 +643,41 @@ def test_software_language(self):
643643
}
644644
self.assertFalseWithOptions(observed_data)
645645

646-
observed_data['languages'][0] = 'eng'
646+
# Test with RFC 5646 language code (preferred)
647+
observed_data['languages'][0] = 'en'
647648
self.assertTrueWithOptions(observed_data)
648649

650+
def test_software_language_iso639_compatibility(self):
651+
"""Test that ISO 639-2 codes are accepted with warnings for backward compatibility"""
652+
import io
653+
import logging
654+
655+
# Capture log output
656+
log_capture = io.StringIO()
657+
handler = logging.StreamHandler(log_capture)
658+
handler.setLevel(logging.WARNING)
659+
logger = logging.getLogger('stix2validator.v21.musts')
660+
logger.addHandler(handler)
661+
logger.setLevel(logging.WARNING)
662+
663+
observed_data = {
664+
"type": "software",
665+
"id": "software--ff1e0780-358c-5808-a8c7-d0fca4ef6ef4",
666+
"name": "word",
667+
"languages": ["eng"] # ISO 639-2 code
668+
}
669+
670+
# Should be valid (backward compatibility)
671+
self.assertTrueWithOptions(observed_data)
672+
673+
# Should generate a warning
674+
log_output = log_capture.getvalue()
675+
self.assertIn("ISO 639-2 language code", log_output)
676+
self.assertIn("RFC 5646 language codes are preferred", log_output)
677+
678+
# Clean up
679+
logger.removeHandler(handler)
680+
649681
def test_software_cpe(self):
650682
observed_data = {
651683
"type": "software",

stix2validator/v21/musts.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -411,16 +411,30 @@ def language(instance):
411411

412412
@cyber_observable_check("2.1")
413413
def software_language(instance):
414-
"""Ensure the 'language' property of software objects is a valid ISO 639-2
415-
language code.
414+
"""Ensure the 'language' property of software objects is a valid RFC 5646
415+
language code. ISO 639-2 codes are accepted for backward compatibility
416+
but will generate warnings.
416417
"""
417418
if ('type' in instance and instance['type'] == 'software' and
418419
'languages' in instance):
419420
for lang in instance['languages']:
420-
if lang not in enums.SOFTWARE_LANG_CODES:
421+
if lang in enums.LANG_CODES:
422+
# Valid RFC 5646 language code
423+
continue
424+
elif lang in enums.SOFTWARE_LANG_CODES:
425+
# ISO 639-2 code - accept but warn
426+
import logging
427+
logger = logging.getLogger(__name__)
428+
logger.warning("The 'languages' property of object '%s' "
429+
"contains an ISO 639-2 language code ('%s'). "
430+
"RFC 5646 language codes are preferred for STIX 2.1. "
431+
"Consider updating to RFC 5646 format."
432+
% (instance['id'], lang))
433+
else:
434+
# Invalid language code
421435
yield JSONError("The 'languages' property of object '%s' "
422-
"contains an invalid ISO 639-2 language "
423-
" code ('%s')."
436+
"contains an invalid language code ('%s'). "
437+
"Expected RFC 5646 language code."
424438
% (instance['id'], lang), instance['id'])
425439

426440

0 commit comments

Comments
 (0)