Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests for handling invalid LiteDB files #2507

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

PanWuming
Copy link

@PanWuming PanWuming commented Jun 12, 2024

Description

This PR adds four unit tests to handle scenarios where LiteDB attempts to open invalid database files and streams:

  • Test_AddDatabase_InvalidDatabase: Tests handling of a file with invalid content.
  • Test_AddDatabase_InvalidDatabase_LargeFile: Tests handling of a file with invalid content larger than 16KB.
  • Test_AddDatabase_InvalidDatabase_MemoryStream: Tests handling of an invalid content stream.
  • Test_AddDatabase_InvalidDatabase_LargeFile_MemoryStream: Tests handling of a large invalid content stream.

Issues

These tests are intended to address issue #2501.

Bugs Discovered

  1. Test_AddDatabase_InvalidDatabase:

    • Bug: The test expected a LiteDB.LiteException to be thrown.
    • Actual: No exception was thrown.
    • Details:
      Assert.Throws() Failure
      Expected: typeof(LiteDB.LiteException)
      Actual:   (No exception was thrown)
      
      
  2. Test_AddDatabase_InvalidDatabase_LargeFile:

    • Bug: The test expected a LiteDB.LiteException to be thrown.
    • Actual: A System.ArgumentOutOfRangeException was thrown.
    • Details:
      Assert.Throws() Failure
      Expected: typeof(LiteDB.LiteException)
      Actual:   typeof(System.ArgumentOutOfRangeException): Ticks must be between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks. (Parameter 'ticks')
      
  3. Test_AddDatabase_InvalidDatabase_MemoryStream:

    • Bug: The test expected a LiteDB.LiteException to be thrown.
    • Actual: A System.NotSupportedException was thrown.
    • Details:
      Assert.IsType() Failure
      Expected: LiteDB.LiteException
      Actual:   System.NotSupportedException
      
  4. Test_AddDatabase_InvalidDatabase_LargeFile_MemoryStream:

    • Bug: The test expected a LiteDB.LiteException to be thrown.
    • Actual: A System.ArgumentOutOfRangeException was thrown.
    • Details:
      Assert.IsType() Failure
      Expected: LiteDB.LiteException
      Actual:   System.ArgumentOutOfRangeException
      

These findings indicate that LiteDB is not handling invalid files and streams as expected, leading to different types of exceptions or no exceptions at all.

@JKamsker
Copy link
Collaborator

Does it also work with memorystreams? I prefer not to write on my disk.

@PanWuming
Copy link
Author

Does it also work with memorystreams? I prefer not to write on my disk.

Thank you for your feedback. I have updated the PR with the requested MemoryStream tests and included exception outputs for debugging. Please review the latest changes.

Copy link
Owner

@mbdavid mbdavid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants