Class: InternetHakai::RedirectCheckAction

Inherits:
RequestAction show all
Defined in:
lib/internethakai/action.rb

Overview

リダイレクトをチェック / config に assert_redirectという名前でリダイレクト先を追加

Constant Summary

Constants inherited from RequestAction

InternetHakai::RequestAction::ERROR_MAX, InternetHakai::RequestAction::REDIRECT_MAX

Instance Attribute Summary

Attributes inherited from BaseAction

#performance_id

Instance Method Summary collapse

Methods inherited from RequestAction

#check_scan, #check_size, #free, #get_client, #get_default, #http_request, #init, #log, #mkclient, #on_error, #on_free, #on_response, #run, #set_client, #set_wait, #to_s

Methods inherited from BaseAction

#dispatch_next, #free, #get_default, #has_on_complete?, #quit, #run, #set_on_complete

Constructor Details

#initialize(opt, scenario) ⇒ RedirectCheckAction

Returns a new instance of RedirectCheckAction.



355
356
357
358
359
360
# File 'lib/internethakai/action.rb', line 355

def initialize opt, scenario
    super
    if @opt.has_key? "assert_redirect_scan"
        @opt["assert_redirect_scan"] = Util::convert_encoding(@opt["assert_redirect_scan"], @opt)
    end
end

Instance Method Details

#on_complete(response) ⇒ Object



384
385
386
387
388
389
390
391
392
393
394
395
396
# File 'lib/internethakai/action.rb', line 384

def on_complete response
    super
    if(@redirect >= 1 && @opt["assert_redirect_scan"])
        return if response.nil?
        scan = @opt["assert_redirect_scan"]
        unless response.body.include? scan
            log "REDIRECT_SCAN:::false:::"+scan
            @errorcount += 1
        else
            log "REDIRECT_SCAN:::true"
        end
    end
end

#on_redirect(newurl) ⇒ Object



361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
# File 'lib/internethakai/action.rb', line 361

def on_redirect newurl
    if curl = @opt["assert_redirect"]
        if curl.is_a? Array
            if curl.any?{|u| newurl.include? u}
                log "ASSERT_REDIRECT:::true #{newurl}"
            else
                @errorcount+=1
                log "ASSERT_REDIRECT:::false #{newurl}"
                #@detail += "invalid redirect: " + newurl
            end
        else
            if ! newurl.include? @opt["assert_redirect"]
                @errorcount+=1
                #@detail += "invalid redirect: " + newurl
                log "ASSERT_REDIRECT:::false #{newurl}"
            else
                log "ASSERT_REDIRECT:::true #{newurl}"
            end
        end
    else
        @errorcount += 1
    end
end