Skip to content

Commit

Permalink
Merge pull request ivre#362 from p-l-/searchnonexistent
Browse files Browse the repository at this point in the history
DB: add .searchnonexistent() method to replace a broken hack
  • Loading branch information
p-l- authored Mar 13, 2017
2 parents 26335fe + 7279166 commit 8ee2d15
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ivre/db/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,10 @@ def _flt_and(cond1, cond2):
def flt_or(*args):
return {'$or': args} if len(args) > 1 else args[0]

@staticmethod
def searchnonexistent():
return {'_id': 0}

@staticmethod
def searchobjectid(oid, neg=False):
"""Filters records by their ObjectID. `oid` can be a single or many
Expand Down
4 changes: 4 additions & 0 deletions ivre/db/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -2083,6 +2083,10 @@ def getscan(self, scanid, archive=False):
return self.db.execute(select([ScanFile])\
.where(ScanFile.sha256 == scanid)).fetchone()

@staticmethod
def searchnonexistent():
return NmapFilter(main=False)

@staticmethod
def _searchobjectid(oid, neg=False):
if len(oid) == 1:
Expand Down
2 changes: 1 addition & 1 deletion ivre/webutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def get_anonymized_user():

QUERIES = {
'full': lambda: db.nmap.flt_empty,
'noaccess': lambda: db.nmap.searchid(0),
'noaccess': lambda: db.nmap.searchnonexistent(),
'category': lambda cat: db.nmap.searchcategory(cat.split(',')),
}

Expand Down
3 changes: 3 additions & 0 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ def host_stored_test(line):
self.assertEqual(res, 0)
archives_count = int(out)

count = ivre.db.db.nmap.count(ivre.db.db.nmap.searchnonexistent())
self.assertEqual(count, 0)

# Is the test case OK?
self.assertGreater(hosts_count, 0)
self.check_value("nmap_get_count", hosts_count)
Expand Down

0 comments on commit 8ee2d15

Please sign in to comment.