Skip to content

Commit b2070d4

Browse files
committed
Refactored database and test for profileId from IP
1 parent 8e36f4c commit b2070d4

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

slips_files/core/database/database.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ def addProfile(self, profileid, starttime, duration):
364364
if not self.should_add(profileid):
365365
return False
366366
# Add the profile to the index. The index is called prefix + separator + 'profiles'
367-
self.r.sadd(self.prefix + self.separator + 'profiles', str(profileid))
367+
self.r.sadd(self.prefix + self.separator + 'profiles', self.prefix + self.separator + str(profileid))
368368
# Create the hashmap with the profileid. The hasmap of each profile is named with the profileid
369369
# Add the start time of profile
370370
self.r.hset(self.prefix + self.separator + str(profileid), 'starttime', starttime)
@@ -724,7 +724,7 @@ def getProfileIdFromIP(self, daddr_as_obj):
724724
"""Receive an IP and we want the profileid"""
725725
try:
726726
profileid = f'profile{self.separator}{str(daddr_as_obj)}'
727-
if data := self.r.sismember('profiles', profileid):
727+
if data := self.r.sismember(self.prefix + self.separator +'profiles', self.prefix + self.separator + str(profileid)):
728728
return profileid
729729
return False
730730
except redis.exceptions.ResponseError as inst:

tests/test_database.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def test_getProfileIdFromIP(outputQueue):
9595
os.system('./slips.py -c config/slips.conf -cc')
9696

9797
# add a profile
98-
database.addProfile(f'{prefix}_profile_192.168.1.1', '00:00', '1')
98+
database.addProfile(f'profile_192.168.1.1', '00:00', '1')
9999
# try to retrieve it
100100
assert database.getProfileIdFromIP(test_ip) is not False
101101

0 commit comments

Comments
 (0)