Skip to content

Commit

Permalink
Merge pull request #749 from tenable/asset-export-open-ports
Browse files Browse the repository at this point in the history
Support for include_open_ports property in asset export request
  • Loading branch information
aseemsavio authored Jan 11, 2024
2 parents 47e57b8 + 7533f7a commit 4e74249
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
2 changes: 2 additions & 0 deletions tenable/io/exports/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ def assets(self, **kwargs) -> Union[ExportsIterator, UUID]:
Should we return assets that have a ServiceNOW sysid?
if ``True`` only assets with an id will be returned.
if ``False`` only assets without an id will be returned.
include_open_ports (bool, optional):
Should we include open ports of assets in the exported chunks?
chunk_size (int, optional):
How many asset objects should be returned per chunk of data?
The default is ``1000``.
Expand Down
3 changes: 2 additions & 1 deletion tenable/io/exports/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class AssetExportSchema(Schema):
is_licensed = fields.Bool()
is_terminated = fields.Bool()
servicenow_sysid = fields.Bool()
include_open_ports = fields.Bool()

# Other params
chunk_size = fields.Int(dump_default=1000)
Expand All @@ -49,7 +50,7 @@ class AssetExportSchema(Schema):
@post_dump
def post_serialization(self, data, **kwargs): # noqa PLR0201 PLW0613
data = serialize_tags(data)
data = envelope(data, 'filters', excludes=['chunk_size'])
data = envelope(data, 'filters', excludes=['chunk_size', 'include_open_ports'])
return data


Expand Down
54 changes: 54 additions & 0 deletions tests/io/exports/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,35 @@ def asset_export():
]
}

@pytest.fixture
def asset_export_with_open_ports_true():
"""
Asset export request with open ports set as true.
"""
return {
'chunk_size': 1000,
'include_open_ports': True
}

@pytest.fixture
def asset_export_with_open_ports_false():
"""
Asset export request with open ports set as false.
"""
return {
'chunk_size': 1000,
'include_open_ports': False
}

@pytest.fixture
def asset_export_with_out_open_ports():
"""
Asset export request without open ports.
"""
return {
'chunk_size': 1000
}


@pytest.fixture
def compliance_export():
Expand Down Expand Up @@ -190,3 +219,28 @@ def test_vulnerabilityschema(vuln_export):
with pytest.raises(ValidationError):
vuln_export['scan_uuid'] = 0
schema.load(vuln_export)

def test_asset_export_schema_for_open_ports_true(asset_export_with_open_ports_true):
"""
Ensure Asset Export request is correctly formed with include_open_ports set to true.
"""
schema = AssetExportSchema()
schema_dump = schema.dump(schema.load(asset_export_with_open_ports_true))
assert schema_dump["include_open_ports"] == True


def test_asset_export_schema_for_open_ports_false(asset_export_with_open_ports_false):
"""
Ensure Asset Export request is correctly formed with include_open_ports set to false.
"""
schema = AssetExportSchema()
schema_dump = schema.dump(schema.load(asset_export_with_open_ports_false))
assert schema_dump["include_open_ports"] == False

def test_asset_export_schema_without_open_ports(asset_export_with_out_open_ports):
"""
Ensure Asset Export request is correctly formed without include_open_ports.
"""
schema = AssetExportSchema()
schema_dump = schema.dump(schema.load(asset_export_with_out_open_ports))
assert "include_open_ports" not in schema_dump

0 comments on commit 4e74249

Please sign in to comment.