Skip to content

Add Unit Tests for Runner Package#1396

Merged
ehsandeep merged 5 commits intoprojectdiscovery:devfrom
knakul853:test/improve-unit-test-coverage
Feb 21, 2025
Merged

Add Unit Tests for Runner Package#1396
ehsandeep merged 5 commits intoprojectdiscovery:devfrom
knakul853:test/improve-unit-test-coverage

Conversation

@knakul853
Copy link
Copy Markdown
Contributor

Description

Added comprehensive unit tests for the Runner package to improve code coverage and ensure reliability of core scanning functionality.

Added Test Cases

Core Runner Tests

  • TestNewRunner: Tests runner initialization with various configurations
    • Default settings validation
    • IPv6 configuration
    • Custom resolver configuration
    • Invalid port handling
    • Progress bar functionality
    • Proxy configuration

Resource Management

  • TestRunnerClose: Tests proper cleanup of resources
  • TestRunnerOnReceive: Tests result handling and callbacks
    • Port result processing
    • JSON/CSV output handling
    • CDN detection
    • IPv4/IPv6 handling
    • Duplicate port handling

IP and Port Management

  • TestRunnerPickIP: Tests IP selection from CIDR ranges
  • TestRunnerSetSourceIP: Tests source IP configuration
  • TestRunnerSetSourcePort: Tests source port configuration
  • TestRunnerCanIScanIfCDN: Tests CDN scanning restrictions

Scan Flow Tests

  • TestRunnerEnumeration: Tests complete enumeration workflow
    • SYN scan with host discovery
    • Connect scan with verification
    • CDN exclusion handling

Host Discovery and Target Processing

  • TestRunnerHostDiscovery: Tests host discovery methods
  • TestRunnerGetIPs: Tests IP preprocessing
  • TestRunnerConnectVerification: Tests port verification

Test Coverage

The added tests cover:

  • Configuration validation
  • Resource management
  • Result handling
  • Network operations
  • Error conditions
  • Edge cases

Testing Notes

  • Tests include both privileged and unprivileged operations
  • Mock objects used where appropriate
  • Proper cleanup of resources
  • Timeout handling for network operations

Related Issues

#1388

@ehsandeep ehsandeep linked an issue Feb 20, 2025 that may be closed by this pull request
@GeorginaReeder
Copy link
Copy Markdown

Thanks for your contribution @knakul853 ! :)

Copy link
Copy Markdown
Member

@ehsandeep ehsandeep left a comment

Choose a reason for hiding this comment

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

@knakul853 can you take a look at failing test?

@knakul853
Copy link
Copy Markdown
Contributor Author

@ehsandeep Yup, I'm looking into it. Trying to set up a Windows environment locally for testing to prevent issues in the future.

@knakul853 knakul853 requested a review from ehsandeep February 20, 2025 12:54
@ehsandeep ehsandeep requested a review from Mzack9999 February 20, 2025 12:54
@ehsandeep ehsandeep merged commit ce81726 into projectdiscovery:dev Feb 21, 2025
9 checks passed
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.

Add Unit Tests for Scanner Runner Implementation

4 participants