Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbylica-splunk committed Dec 6, 2024
1 parent 0cca7ea commit 38c5664
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions package/etc/pylib/parser_source_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import traceback
import socket
import struct
from restricted_sqlitedict import SqliteDict
from package.etc.pylib.sqlite_utils import RestrictedSqliteDict

import time

Expand Down Expand Up @@ -54,7 +54,7 @@ def int_to_ip6(num):
class psc_parse(LogParser):
def init(self, options):
self.logger = syslogng.Logger()
self.db = SqliteDict(f"{hostdict}.sqlite")
self.db = RestrictedSqliteDict(f"{hostdict}.sqlite")
return True

def deinit(self):
Expand Down Expand Up @@ -82,7 +82,7 @@ class psc_dest(LogDestination):
def init(self, options):
self.logger = syslogng.Logger()
try:
self.db = SqliteDict(f"{hostdict}.sqlite", autocommit=True)
self.db = RestrictedSqliteDict(f"{hostdict}.sqlite", autocommit=True)
except Exception:
exc_type, exc_value, exc_traceback = sys.exc_info()
lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
Expand Down Expand Up @@ -123,7 +123,7 @@ def flush(self):


if __name__ == "__main__":
db = SqliteDict(f"{hostdict}.sqlite", autocommit=True)
db = RestrictedSqliteDict(f"{hostdict}.sqlite", autocommit=True)
db[0] = "seed"
db.commit()
db.close()
6 changes: 3 additions & 3 deletions package/etc/pylib/parser_vps_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import traceback
import socket
import struct
from restricted_sqlitedict import SqliteDict
from sqlite_utils import RestrictedSqliteDict

import time

Expand All @@ -24,7 +24,7 @@ class LogDestination:
class vpsc_parse(LogParser):
def init(self, options):
self.logger = syslogng.Logger()
self.db = SqliteDict(f"{hostdict}.sqlite")
self.db = RestrictedSqliteDict(f"{hostdict}.sqlite")
return True

def deinit(self):
Expand Down Expand Up @@ -52,7 +52,7 @@ class vpsc_dest(LogDestination):
def init(self, options):
self.logger = syslogng.Logger()
try:
self.db = SqliteDict(f"{hostdict}.sqlite", autocommit=True)
self.db = RestrictedSqliteDict(f"{hostdict}.sqlite", autocommit=True)
except Exception:
exc_type, exc_value, exc_traceback = sys.exc_info()
lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
Expand Down
2 changes: 1 addition & 1 deletion package/etc/pylib/sqlite_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import io
import pickle
from base64 import b64decode
from restricted_sqlitedict import SqliteDict
from sqlitedict import SqliteDict


class RestrictedUnpickler(pickle.Unpickler):
Expand Down
10 changes: 5 additions & 5 deletions tests/test_name_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from .sendmessage import sendsingle
from .splunkutils import splunk_single
from package.etc.pylib.parser_source_cache import ip2int, int2ip
from restricted_sqlitedict import SqliteDict
from package.etc.pylib.sqlite_utils import RestrictedSqliteDict

env = Environment()

Expand Down Expand Up @@ -86,12 +86,12 @@ def test_ipv6_utils():
@pytest.mark.name_cache
def test_RestrictedSqliteDict_stores_and_retrieves_string():
with tempfile.NamedTemporaryFile(delete=True) as temp_db_file:
cache = SqliteDict(f"{temp_db_file.name}.db")
cache = RestrictedSqliteDict(f"{temp_db_file.name}.db")
cache["key"] = "value"
cache.commit()
cache.close()

cache = SqliteDict(f"{temp_db_file.name}.db")
cache = RestrictedSqliteDict(f"{temp_db_file.name}.db")
assert cache["key"] == "value"
cache.close()

Expand All @@ -106,14 +106,14 @@ def __reduce__(self):

with tempfile.NamedTemporaryFile(delete=True) as temp_db_file:
# Initialize the RestrictedSqliteDict and insert an 'injected' object
cache = SqliteDict(f"{temp_db_file.name}.db")
cache = RestrictedSqliteDict(f"{temp_db_file.name}.db")
cache["key"] = InjectionTestClass()
cache.commit()
cache.close()

# Re-open cache and attempt to deserialize 'injected' object
# Expecting UnpicklingError due to RestrictedSqliteDict restrictions
cache = SqliteDict(f"{temp_db_file.name}.db")
cache = RestrictedSqliteDict(f"{temp_db_file.name}.db")
with pytest.raises(pickle.UnpicklingError):
_ = cache["key"]
cache.close()

0 comments on commit 38c5664

Please sign in to comment.