Ejemplo n.º 1
0
  def testCopyAttributesFromSessionCompletion(self):
    """Tests the CopyAttributesFromSessionCompletion function."""
    attribute_container = sessions.Session()

    session_completion = sessions.SessionCompletion(
        identifier=attribute_container.identifier)
    attribute_container.CopyAttributesFromSessionCompletion(session_completion)

    with self.assertRaises(ValueError):
      session_completion = sessions.SessionCompletion()
      attribute_container.CopyAttributesFromSessionCompletion(
          session_completion)
Ejemplo n.º 2
0
    def testReadAndWriteSerializedSessionCompletion(self):
        """Test ReadSerialized and WriteSerialized of SessionCompletion."""
        timestamp = int(time.time() * 1000000)
        session_identifier = '{0:s}'.format(uuid.uuid4().hex)

        parsers_counter = collections.Counter()
        parsers_counter['filestat'] = 3
        parsers_counter['total'] = 3

        expected_session_completion = sessions.SessionCompletion(
            identifier=session_identifier)
        expected_session_completion.timestamp = timestamp
        expected_session_completion.parsers_counter = parsers_counter

        json_string = (json_serializer.JSONAttributeContainerSerializer.
                       WriteSerialized(expected_session_completion))

        self.assertIsNotNone(json_string)

        session_completion = (json_serializer.JSONAttributeContainerSerializer.
                              ReadSerialized(json_string))

        self.assertIsNotNone(session_completion)
        self.assertIsInstance(session_completion, sessions.SessionCompletion)

        expected_session_completion_dict = {
            'aborted': False,
            'identifier': session_identifier,
            'parsers_counter': parsers_counter,
            'timestamp': timestamp
        }

        session_completion_dict = session_completion.CopyToDict()
        self.assertEqual(sorted(session_completion_dict.items()),
                         sorted(expected_session_completion_dict.items()))
Ejemplo n.º 3
0
    def testGetAttributeNames(self):
        """Tests the GetAttributeNames function."""
        attribute_container = sessions.SessionCompletion()

        expected_attribute_names = [
            'aborted', 'analysis_reports_counter', 'event_labels_counter',
            'identifier', 'parsers_counter', 'timestamp'
        ]

        attribute_names = sorted(attribute_container.GetAttributeNames())

        self.assertEqual(attribute_names, expected_attribute_names)
Ejemplo n.º 4
0
    def testWriteSessionStartAndCompletion(self):
        """Tests the WriteSessionStart and WriteSessionCompletion functions."""
        session = sessions.Session()
        session_start = sessions.SessionStart(identifier=session.identifier)
        session_completion = sessions.SessionCompletion(
            identifier=session.identifier)

        with shared_test_lib.TempDirectory() as temp_directory:
            temp_file = os.path.join(temp_directory, 'plaso.sqlite')
            storage_file = sqlite_file.SQLiteStorageFile(
                storage_type=definitions.STORAGE_TYPE_TASK)
            storage_file.Open(path=temp_file, read_only=False)

            storage_file.WriteSessionStart(session_start)
            storage_file.WriteSessionCompletion(session_completion)

            storage_file.Close()
Ejemplo n.º 5
0
  def testCopyToDict(self):
    """Tests the CopyToDict function."""
    timestamp = int(time.time() * 1000000)
    session_identifier = '{0:s}'.format(uuid.uuid4().hex)
    session_completion = sessions.SessionCompletion(
        identifier=session_identifier)
    session_completion.timestamp = timestamp

    self.assertEqual(session_completion.identifier, session_identifier)

    expected_dict = {
        'aborted': False,
        'identifier': session_completion.identifier,
        'timestamp': timestamp}

    test_dict = session_completion.CopyToDict()

    self.assertEqual(test_dict, expected_dict)