Skip to content
This repository has been archived by the owner on Nov 29, 2021. It is now read-only.

[2.0] Fix VT Filter. #165

Merged
merged 1 commit into from
Nov 4, 2019
Merged

Conversation

jjnicola
Copy link
Member

If no vts matches the filter, returns an empty element.

@codecov
Copy link

codecov bot commented Oct 25, 2019

Codecov Report

Merging #165 into ospd-2.0 will decrease coverage by 0.02%.
The diff coverage is 80%.

Impacted file tree graph

@@             Coverage Diff              @@
##           ospd-2.0     #165      +/-   ##
============================================
- Coverage      68.5%   68.48%   -0.03%     
============================================
  Files            12       12              
  Lines          1759     1761       +2     
============================================
+ Hits           1205     1206       +1     
- Misses          554      555       +1
Impacted Files Coverage Δ
ospd/ospd.py 72.9% <80%> (-0.06%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 560fe37...fccd732. Read the comment docs.

ospd/vtfilter.py Outdated
@@ -128,4 +128,4 @@ def get_filtered_vts_list(self, vts, vt_filter):
else:
_vts_aux.pop(vt_id)

return _vts_aux
return _vts_aux if len(_vts_aux) else -1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a look at the return value docstring and it says "Dictionary with filtered vulnerability tests.". In that case it would be better to return None here to indicate an error/special case. Also the docstring should be updated to reflect this change.

Suggested change
return _vts_aux if len(_vts_aux) else -1
return _vts_aux if len(_vts_aux) else None

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't use a filter, the default filter is None. Then, instead of getting the complete VTs set , you get none.
We need to differentiate the "no filter" with the "no matches". A no matches returned an empty dictionary, and this was the initial problem, so when the filter does not have matches, it returned the complete set.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok the None case when no filter isn't mentioned in the docs too. Therefore I did oversee it in the function code. But I still don't understand why you want to return -1 when the dict is empty instead of checking at the place where this is used for an empty dict as in my suggestion here https://github.com/greenbone/ospd/pull/165/files/05918e21c73c861ea88c3064ff0e6d3a555e2130#r339015657

ospd/ospd.py Outdated
@@ -1542,6 +1542,8 @@ def get_vts_xml(self, vt_id=None, filtered_vts=None):
"""

vts_xml = Element('vts')
if filtered_vts == -1:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if filtered_vts == -1:
if filtered_vts is None:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh just recognized, wouldn't it be possible to just do a

Suggested change
if filtered_vts == -1:
if not filtered_vts:

here and even drop the get_filtered_vts_list change?

@jjnicola jjnicola changed the title Fix VT Filter. [2.0] Fix VT Filter. Oct 25, 2019
ospd/ospd.py Outdated
@@ -994,6 +994,11 @@ def handle_get_scans_command(self, scan_et):

def handle_get_vts_command(self, vt_et):
""" Handles <get_vts> command.
The <get_vts> element accept two optional arguments.
vt_id argument receives a single vt id.
filter argument receives a filter select a sub set of vts.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
filter argument receives a filter select a sub set of vts.
filter argument receives a filter selecting a sub set of vts.

ospd/ospd.py Outdated
If no vt_id is specified, the collection will contain all vts or those
passed in filtered_vts.
If no vt_id is specified or filtered_vts is None (default), the
collection will contain all vts. Otherwise return those vts passed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
collection will contain all vts. Otherwise return those vts passed
collection will contain all vts. Otherwise those vts passed

ospd/ospd.py Outdated
passed in filtered_vts.
If no vt_id is specified or filtered_vts is None (default), the
collection will contain all vts. Otherwise return those vts passed
in filtered_vts or vt_id. In case of both vt_id and filtered_vts are
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
in filtered_vts or vt_id. In case of both vt_id and filtered_vts are
in filtered_vts or vt_id are returned. In case of both vt_id and filtered_vts are

ospd/ospd.py Show resolved Hide resolved
If no vts matches the filter, returns an empty element.
@bjoernricks bjoernricks merged commit f2977c7 into greenbone:ospd-2.0 Nov 4, 2019
@jjnicola jjnicola deleted the fix-filter-2 branch November 4, 2019 11:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants