Back to Repositories

Testing WooFramework Meta Generator Theme Version Detection in WPScan

This test suite validates the WooFramework Meta Generator functionality for WordPress theme version detection in WPScan. It focuses on testing passive detection capabilities for theme versions using meta generator tags specific to the Woo Framework.

Test Coverage Overview

The test suite provides comprehensive coverage for theme version detection through meta generator tags.
  • Tests theme slug matching scenarios
  • Validates version extraction from HTML content
  • Verifies correct version model creation
  • Handles both matching and non-matching cases

Implementation Analysis

The testing approach uses RSpec to mock HTTP requests and validate version detection logic. It implements stub requests for CSS files and content directory paths, while utilizing fixture data to simulate WordPress theme responses.

Key patterns include request stubbing, expectation setting, and context-based test organization.

Technical Details

Testing tools and configuration include:
  • RSpec for test framework
  • Web request stubbing
  • Fixture-based test data
  • Model instantiation for Theme and Version objects
  • HTTP response simulation

Best Practices Demonstrated

The test suite exemplifies several testing best practices including proper isolation of test cases, clear context separation, and effective use of fixtures. It demonstrates clean code organization through contextual grouping and maintains high test readability with well-structured expectations and assertions.

wpscanteam/wpscan

spec/app/finders/theme_version/woo_framework_meta_generator_spec.rb

            
# frozen_string_literal: true

describe WPScan::Finders::ThemeVersion::WooFrameworkMetaGenerator do
  subject(:finder) { described_class.new(theme) }
  let(:theme)      { WPScan::Model::Theme.new(slug, target) }
  let(:target)     { WPScan::Target.new('http://wp.lab/') }
  let(:fixtures)   { FINDERS_FIXTURES.join('theme_version', 'woo_framework_meta_generator') }

  before do
    expect(target).to receive(:content_dir).and_return('wp-content')
    stub_request(:get, /\.css\z/)
  end

  describe '#passive' do
    after do
      stub_request(:get, target.url).to_return(body: File.read(fixtures.join('editorial-1.3.5.html')))

      expect(finder.passive).to eql @expected
    end

    context 'when the theme slug does not match' do
      let(:slug) { 'spec' }

      it 'returns nil' do
        @expected = nil
      end
    end

    context 'when the theme slug matches' do
      let(:slug) { 'Editorial' }

      it 'return the expected version' do
        @expected = WPScan::Model::Version.new(
          '1.3.5',
          found_by: 'Woo Framework Meta Generator (Passive Detection)',
          confidence: 80
        )
      end
    end
  end
end