Skip to content

Commit

Permalink
Updated testing suite
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveMcGrath committed Aug 21, 2024
1 parent e2ce9ac commit 25712ef
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 34 deletions.
22 changes: 22 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,25 @@ readme = {file = ["README.md"], content-type = "text/markdown"}
[tool.setuptools.packages.find]
include = ["tenb2jira*"]

[tool.ruff]
target-version = "py312"
exclude = [
".nova",
".github",
".git",
".pytest_cache",
"__pycache__"
]

[tool.ruff.lint]
select = ["E4", "E7", "E9", "F", "B"]
fixable = [ "ALL" ]
unfixable = [ "B" ]

[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["E402"]
"**/{tests,docs,tools}/*" = ["E402"]

[tool.flake8]
max-line-length = 88
count = true
11 changes: 7 additions & 4 deletions tenb2jira/jira/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,15 @@ def __repr__(self):

@property
def attr(self):
if self.attribute:
return self.attribute
if self.static_value:
return self.attribute
"""
Return the appropriate value (either platform_id, static_value, or
attribute) depending on how the field was configured.
"""
if self.platform_id:
return self.platform_id
if self.static_value:
return self.static_value
return self.attribute

def fetch_field_id(self, api) -> bool:
"""
Expand Down
16 changes: 11 additions & 5 deletions tenb2jira/jira/jira.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any
from typing import Any, Dict
import time
import logging
from box import Box
Expand All @@ -24,12 +24,18 @@ class Jira:
project: dict

@property
def field_by_name_map(self):
return {f.name:f for f in self.fields}
def field_by_name_map(self) -> Dict[str, Field]:
"""
Returns the fields in a dictionary with the field name as the key
"""
return {f.name: f for f in self.fields}

@property
def field_by_id_map(self):
return {f.id:f for f in self.fields}
def field_by_id_map(self) -> Dict[str, Field]:
"""
Returns the fields in a dictionary with the field id as the key
"""
return {f.id: f for f in self.fields}

def __init__(self, config: dict):
self.config = config
Expand Down
2 changes: 1 addition & 1 deletion tenb2jira/jira/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self, issue_def: "Task", is_open: bool = True):
self.is_open = is_open

def __repr__(self):
return f'Task("{self.jql}", {len(self.fields)})'
return f'Task("{self.jql_stmt}", {len(self.fields)})'

@property
def jql_stmt(self):
Expand Down
10 changes: 8 additions & 2 deletions tenb2jira/processor.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import Optional
import logging
from concurrent.futures import ThreadPoolExecutor
from pathlib import Path
Expand Down Expand Up @@ -29,8 +30,13 @@ class Processor:
plugin_id: str
closed_map: list[str]

def __init__(self, config: dict, ignore_last_run: bool = False):
dburi = f'sqlite:///{config["mapping_database"].get("path")}'
def __init__(self,
config: dict,
ignore_last_run: bool = False,
dburi: Optional[str] = None,
):
if not dburi:
dburi = f'sqlite:///{config["mapping_database"].get("path")}'

# For situations where we will need to ignore the last_run variable,
# This will pull it from the config, forcing the integration to use
Expand Down
2 changes: 1 addition & 1 deletion tenb2jira/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = '2.0.9'
version = '2.0.10'
43 changes: 40 additions & 3 deletions tests/jira/test_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,43 @@ def field_config():
}


def test_field_repr(field_config):
f = Field(config=field_config,
platform='tvm',
platform_map={'tvm': 'Test Platform'}
)
assert repr(f) == 'Field(1: Test Field)'


def test_field_attr(field_config):
f = Field(config=field_config,
platform='tvm',
platform_map={'tvm': 'Test Platform'}
)
assert f.attr == 'test'

field_config.pop('attr', None)
field_config['platform_id'] = True
f = Field(config=field_config,
platform='tvm',
platform_map={'tvm': 'Test Platform'}
)
assert f.attribute == None
assert f.platform_id == 'Test Platform'
assert f.attr == 'Test Platform'

field_config.pop('platform_id', None)
field_config['static_value'] = 'static'
f = Field(config=field_config,
platform='tvm',
platform_map={'tvm': 'Test Platform'}
)
assert f.attribute == None
assert f.platform_id == None
assert f.static_value == 'static'
assert f.attr == 'static'


def test_field_noapi(field_config):
f = Field(config=field_config,
platform='tvm',
Expand Down Expand Up @@ -130,9 +167,9 @@ def test_field_parse_value_float(field_config):
platform_map={'tvm': 'Test Platform'}
)
f.type = 'float'
assert f.parse_value({'test': 1}) == '1.0'
assert f.parse_value({'test': 1.0}) == '1.0'
assert f.parse_value({'test': '1'}) == '1.0'
assert f.parse_value({'test': 1}) == 1.0
assert f.parse_value({'test': 1.0}) == 1.0
assert f.parse_value({'test': '1'}) == 1.0


def test_field_parse_value_datetime(field_config):
Expand Down
40 changes: 22 additions & 18 deletions tests/jira/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,11 @@ def test_with_tvm_data(tvm_generator, example_config):
'CVE-2024-4777',
'CVE-2024-4778',
],
'customfield_13': '9.2',
'customfield_14': '6.4',
'customfield_15': '5.0',
'customfield_16': '6.5',
'customfield_17': '5.9',
'customfield_13': 9.2,
'customfield_14': 6.4,
'customfield_15': 5.0,
'customfield_16': 6.5,
'customfield_17': 5.9,
'customfield_18': '51192',
'customfield_19': 'General',
'customfield_20': 'SSL Certificate Cannot Be Trusted',
Expand Down Expand Up @@ -369,11 +369,11 @@ def test_with_tvm_data(tvm_generator, example_config):
'CVE-2024-4777',
'CVE-2024-4778',
],
'customfield_13': '9.2',
'customfield_14': '6.4',
'customfield_15': '5.0',
'customfield_16': '6.5',
'customfield_17': '5.9',
'customfield_13': 9.2,
'customfield_14': 6.4,
'customfield_15': 5.0,
'customfield_16': 6.5,
'customfield_17': 5.9,
'customfield_18': '51192',
'customfield_19': 'General',
'customfield_20': 'SSL Certificate Cannot Be Trusted',
Expand Down Expand Up @@ -447,6 +447,10 @@ def test_with_tsc_data(tsc_generator, example_config):
finding = next(tsc_generator)
rtask = task.generate(finding)
rsubtask = subtask.generate(finding)

assert repr(rtask) == ('Task("project = "VULN" AND issuetype = "Task" AND '
'"Tenable Plugin ID" ~ "123560"", 35)'
)
assert rtask.fields == {
'customfield_1': ['d90cdab5-b745-3e7e-9268-aa0f445ed924'],
'customfield_2': None,
Expand All @@ -465,10 +469,10 @@ def test_with_tsc_data(tsc_generator, example_config):
'CVE-2019-3863'
],
'customfield_13': None,
'customfield_14': '9.3',
'customfield_15': '6.9',
'customfield_16': '8.8',
'customfield_17': '7.7',
'customfield_14': 9.3,
'customfield_15': 6.9,
'customfield_16': 8.8,
'customfield_17': 7.7,
'customfield_18': '123560',
'customfield_19': None,
'customfield_20': 'CentOS 7 : libssh2 (CESA-2019:0679)',
Expand Down Expand Up @@ -532,10 +536,10 @@ def test_with_tsc_data(tsc_generator, example_config):
'CVE-2019-3863'
],
'customfield_13': None,
'customfield_14': '9.3',
'customfield_15': '6.9',
'customfield_16': '8.8',
'customfield_17': '7.7',
'customfield_14': 9.3,
'customfield_15': 6.9,
'customfield_16': 8.8,
'customfield_17': 7.7,
'customfield_18': '123560',
'customfield_19': None,
'customfield_20': 'CentOS 7 : libssh2 (CESA-2019:0679)',
Expand Down

0 comments on commit 25712ef

Please sign in to comment.