Rakefile 8.13 KB
Newer Older
1
=begin
Sophie Brun's avatar
Sophie Brun committed
2
    Copyright 2010-2017 Sarosys LLC <http://www.sarosys.com>
3

4 5 6
    This file is part of the Arachni Framework project and is subject to
    redistribution and commercial restrictions. Please see the Arachni Framework
    web site for more information on licensing and terms of use.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
=end

require 'bundler'
require 'fileutils'
require File.expand_path( File.dirname( __FILE__ ) ) + '/lib/arachni'

begin
    require 'rspec'
    require 'rspec/core/rake_task'

    namespace :spec do

        desc 'Run core library tests.'
        RSpec::Core::RakeTask.new( :core ) do |t|
            t.pattern = FileList[ 'spec/arachni/**/*_spec.rb' ]
        end

24 25 26
        desc 'Run check tests.'
        RSpec::Core::RakeTask.new( :checks ) do |t|
            t.pattern = FileList[ 'spec/components/checks/**/*_spec.rb' ]
27 28
        end

29 30 31 32
        namespace :checks do
            desc 'Run tests for the active checks.'
            RSpec::Core::RakeTask.new( :active ) do |t|
                t.pattern = FileList[ 'spec/components/checks/active/**/*_spec.rb' ]
33 34
            end

35 36 37
            desc 'Run tests for the passive checks.'
            RSpec::Core::RakeTask.new( :passive ) do |t|
                t.pattern = FileList[ 'spec/components/checks/passive/**/*_spec.rb' ]
38 39 40
            end
        end

41 42 43
        desc 'Run reporter tests.'
        RSpec::Core::RakeTask.new( :reporters ) do |t|
            t.pattern = FileList[ 'spec/components/reporters/*_spec.rb' ]
44 45 46 47
        end

        desc 'Run plugin tests.'
        RSpec::Core::RakeTask.new( :plugins ) do |t|
48
            t.pattern = FileList[ 'spec/components/plugins/**/*_spec.rb' ]
49 50 51 52
        end

        desc 'Run path-extractor tests.'
        RSpec::Core::RakeTask.new( :path_extractors ) do |t|
53 54 55 56 57 58
            t.pattern = FileList[ 'spec/components/path_extractors/**/*_spec.rb' ]
        end

        desc 'Run fingerprinter tests.'
        RSpec::Core::RakeTask.new( :fingerprinters ) do |t|
            t.pattern = FileList[ 'spec/components/fingerprinters/**/*_spec.rb' ]
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
        end

        desc 'Run external test suites.'
        RSpec::Core::RakeTask.new( :external ) do |t|
            t.pattern = FileList[ 'spec/external/**/*_spec.rb' ]
        end

        namespace :external do

            desc 'Run the WAVSEP test suite.'
            RSpec::Core::RakeTask.new( :wavsep ) do |t|
                t.pattern = FileList[ 'spec/external/wavsep/**/**/*_spec.rb' ]
            end

            namespace :wavsep do

                desc 'Run the WAVSEP active tests.'
                RSpec::Core::RakeTask.new( :active ) do |t|
                    t.pattern = FileList[ 'spec/external/wavsep/active/**/*_spec.rb' ]
                end

                namespace :active do

                    desc 'Run the WAVSEP XSS tests.'
                    RSpec::Core::RakeTask.new( :xss ) do |t|
84
                        t.pattern = FileList[ 'spec/external/wavsep/active/xss*_spec.rb' ]
85 86 87
                    end

                    desc 'Run the WAVSEP SQL injection tests.'
88 89
                    RSpec::Core::RakeTask.new( :sql_injection ) do |t|
                        t.pattern = FileList[ 'spec/external/wavsep/active/sql_injection_spec.rb' ]
90 91 92 93 94 95 96 97 98 99 100
                    end

                    desc 'Run the WAVSEP LFI tests.'
                    RSpec::Core::RakeTask.new( :lfi ) do |t|
                        t.pattern = FileList[ 'spec/external/wavsep/active/lfi_spec.rb' ]
                    end

                    desc 'Run the WAVSEP RFI tests.'
                    RSpec::Core::RakeTask.new( :rfi ) do |t|
                        t.pattern = FileList[ 'spec/external/wavsep/active/rfi_spec.rb' ]
                    end
101 102 103 104 105 106 107 108 109 110

                    desc 'Run the WAVSEP Unvalidated Redirect tests.'
                    RSpec::Core::RakeTask.new( :unvalidated_redirect ) do |t|
                        t.pattern = FileList[ 'spec/external/wavsep/active/unvalidated_redirect_spec.rb' ]
                    end

                    desc 'Run the WAVSEP Obsolete Files tests.'
                    RSpec::Core::RakeTask.new( :obsolete_files ) do |t|
                        t.pattern = FileList[ 'spec/external/wavsep/active/obsolete_files_spec.rb' ]
                    end
111 112 113 114 115 116 117 118 119 120 121 122 123 124
                end

                desc 'Run the WAVSEP false positive tests.'
                RSpec::Core::RakeTask.new( :false_positives ) do |t|
                    t.pattern = FileList[ 'spec/external/wavsep/false_positives/**/*_spec.rb' ]
                end

                namespace :false_positives do
                    desc 'Run the WAVSEP XSS false positive tests.'
                    RSpec::Core::RakeTask.new( :xss ) do |t|
                        t.pattern = FileList[ 'spec/external/wavsep/false_positives/xss_spec.rb' ]
                    end

                    desc 'Run the WAVSEP SQL injection false positive tests.'
125 126
                    RSpec::Core::RakeTask.new( :sql_injection ) do |t|
                        t.pattern = FileList[ 'spec/external/wavsep/false_positives/sql_injection_spec.rb' ]
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
                    end

                    desc 'Run the WAVSEP LFI false positive tests.'
                    RSpec::Core::RakeTask.new( :lfi ) do |t|
                        t.pattern = FileList[ 'spec/external/wavsep/false_positives/lfi_spec.rb' ]
                    end

                    desc 'Run the WAVSEP RFI false positive tests.'
                    RSpec::Core::RakeTask.new( :rfi ) do |t|
                        t.pattern = FileList[ 'spec/external/wavsep/false_positives/rfi_spec.rb' ]
                    end
                end
            end
        end

142
        desc 'Generate an AFR report for the reporter tests.'
143 144
        namespace :generate do
            task :afr do
145 146
                begin
                    $spec_issues = []
147

148
                    RSpec::Core::Runner.run(FileList[ 'spec/components/checks/**/*_spec.rb' ])
149

150 151 152 153 154
                    ($spec_issues.size / 3).times do |i|
                        # Add remarks to some issues.
                        issue = $spec_issues.sample
                        issue.add_remark( :stuff, 'Blah' )
                        issue.add_remark( :stuff, 'Blah2' )
155

Sophie Brun's avatar
Sophie Brun committed
156 157 158
                        issue.add_remark( :stuff2, '2 Blah' )
                        issue.add_remark( :stuff2, '2 Blah2' )

159 160 161
                        # Flag some issues as untrusted.
                        $spec_issues.sample.trusted = false
                    end
162

163 164 165 166
                    Arachni::Data.issues.store
                    $spec_issues.each { |i| Arachni::Data.issues << i }

                    Arachni::Options.url = 'http://test.com'
Sophie Brun's avatar
Sophie Brun committed
167
                    Arachni::Options.audit.elements Arachni::Page::ELEMENTS - [:link_templates]
168 169 170 171 172 173 174 175 176 177 178 179
                    Arachni::Options.audit.link_templates = [
                        /\/input\/(?<input>.+)\//,
                        /input\|(?<input>.+)/
                    ]

                    Arachni::Report.new(
                        sitemap: { Arachni::Options.url => 200 },
                        issues:  Arachni::Data.issues.sort
                    ).save( 'spec/support/fixtures/report.afr' )
                ensure
                    Arachni::Options.reset
                    Arachni::Data.reset
180 181 182 183 184 185 186 187 188 189 190
                end
            end
        end
    end

    RSpec::Core::RakeTask.new
rescue LoadError
    puts 'If you want to run the tests please install rspec first:'
    puts '  gem install rspec'
end

191 192 193 194 195 196 197
desc 'Start a web server dispatcher.'
task :web_server_dispatcher do
    require_relative 'spec/support/lib/web_server_dispatcher'

    WebServerDispatcher.new
end

198 199 200 201 202 203 204 205 206 207 208
desc 'Generate docs.'
task :docs do
    outdir = "../arachni-docs"
    sh "rm -rf #{outdir}"
    sh "mkdir -p #{outdir}"

    sh "yardoc -o #{outdir}"

    sh "rm -rf .yardoc"
end

209
desc 'Remove reporter and log files.'
210
task :clean do
211 212
    files = %w(error.log *.afr *.afs *.yaml *.json *.marshal *.gem pkg/*.gem
        snapshots/*.afs logs/*.log spec/support/logs/*.log).map { |file| Dir.glob( file ) }.flatten
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227

    next if files.empty?

    puts 'Removing:'
    files.each { |file| puts "  * #{file}" }
    FileUtils.rm files
end

Bundler::GemHelper.install_tasks

desc 'Push a new version to RubyGems'
task :publish => [ :release ]

desc 'Build Arachni and run all the tests.'
task :default => [ :build, :spec ]