google / timesketch

Collaborative forensic timeline analysis
Apache License 2.0
2.58k stars 589 forks source link

[e2e] end_to_end_tests/interface.py upload jsonl 'NoneType' object has no attribute 'lazyload_data' #2923

Closed jaegeral closed 10 months ago

jaegeral commented 12 months ago

Running a new end2end test with a jsonl file:

def test_upload_small_jsonl(self):
        """Test uploaading a timeline with a lot of events as jsonl. The test
        will create a temporary file with a large number of events and then
        upload the file to Timesketch. The test will then check that the
        number of events in the timeline is correct."""

        file_path = "sigma_events.jsonl"
        # create a new sketch
        import random

        randomnumber = random.randint(0, 10000)
        sketch = self.api.create_sketch(name=randomnumber)
        self.sketch = sketch

        self.import_timeline(file_path, index_name=randomnumber, sketch=sketch)

        search_obj = search.Search(sketch)
        search_obj.query_string = "timestamp_desc:Write time"
        search_obj.commit()
        self.assertions.assertEqual(len(search_obj.table), 3)

        # check that the number of events is correct with a different method
        events = sketch.explore("timestamp_desc:Write time", as_pandas=True)
        self.assertions.assertEqual(len(events), 3)

Is causing a AttributeError:

Running test: test_upload_small_jsonl ...No timeline ID has been stored as of yet.
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/end_to_end_tests/interface.py", line 253, in run_tests
    test_func()
  File "/usr/local/lib/python3.10/dist-packages/end_to_end_tests/upload_test.py", line 151, in test_upload_small_jsonl
    self.import_timeline(file_path, index_name=randomnumber, sketch=sketch)
  File "/usr/local/lib/python3.10/dist-packages/end_to_end_tests/interface.py", line 107, in import_timeline
    _ = timeline.lazyload_data(refresh_cache=True)
AttributeError: 'NoneType' object has no attribute 'lazyload_data'

15 total tests: 11 successful and 4 failed
jaegeral commented 10 months ago

This also triggers the problem:

def test_normal_upload_json(self):
        """Test the upload of a json file with a few events."""
        # create a new sketch
        rand = random.randint(0, 10000)
        sketch = self.api.create_sketch(name=rand)
        self.sketch = sketch

        file_path = "/usr/local/src/timesketch/end_to_end_tests/test_data/sigma_events.jsonl"
        self.import_timeline(file_path, index_name=rand, sketch=sketch)
        timeline = sketch.list_timelines()[0]
        # check that timeline was uploaded correctly
        self.assertions.assertEqual(timeline.name, file_path)
        self.assertions.assertEqual(timeline.index.name, str(rand))
        self.assertions.assertEqual(timeline.index.status, "ready")

        events = sketch.explore("*", as_pandas=True)
        self.assertions.assertEqual(len(events), 4)
jaegeral commented 10 months ago

closed with https://github.com/google/timesketch/pull/2976