hansmach1ne / LFImap

Local File Inclusion discovery and exploitation tool
Apache License 2.0
194 stars 29 forks source link

Add Tests #101

Closed nrathaus closed 1 week ago

nrathaus commented 1 week ago

I recreated the branch to make it a bit easier to read

I did the following changes:

  1. Removed pwn import - was causing a loop
  2. Moved colors into its own class, and have it use an init to prevent the import from accessing args which is preventing us from using pytest (as args cannot be externally provided)
  3. Created a pytest of two modules

If this flow is ok, let me know, I will add more pytest

I already found one bug using the pytest related to the rfi bug you already fixed

hansmach1ne commented 6 days ago

@nrathaus I like this way of testing and thanks for this recommendation. Cool way to find bugs within the code, however noticed there is a bit of a learning curve if others will want to join writing tests like these. Feel free to add more if you want.

hansmach1ne commented 6 days ago

For me this test fails, though.

test_tests.py::test_test_rfi PASSED test_tests.py::test_test_cmd_injection FAILED

Failed with message: We are expecting 2 'requests', got: 7

If I understand this correctly, this test fails, because test functions are used within the same context, so if we initialize stats dictionary and both functions consume it, stats will be shared and accessible across the board.

In other words, when we first run test_test_rfi, stats["requests"] will be 5 as we send 5 RFI requests. Afterwards, inside test_test_cmd_injection, then number of requests would indeed be 2, (without previous RFI tests), but with the previous ones we should check if stats["requests"] == 5+2. Same thing for stats["vulns"].

nrathaus commented 6 days ago

I fixed the issue you raised: https://github.com/hansmach1ne/LFImap/pull/103