Class: Heroku::Kensa::SsoCheck

Inherits:
ApiCheck show all
Includes:
HTTP
Defined in:
lib/heroku/kensa/check.rb

Instance Attribute Summary

Attributes inherited from Check

#data, #screen

Instance Method Summary collapse

Methods included from HTTP

#delete, #get, #post, #put, #request

Methods inherited from ApiCheck

#base_path, #credentials, #heroku_id

Methods inherited from Check

#call, #env, #error, #initialize, #run, #test, #to_proc, #url

Constructor Details

This class inherits a constructor from Heroku::Kensa::Check

Instance Method Details

#agentObject



428
429
430
# File 'lib/heroku/kensa/check.rb', line 428

def agent
  @agent ||= Mechanize.new
end

#call!Object



450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
# File 'lib/heroku/kensa/check.rb', line 450

def call!
  error("need an sso salt to perform sso test") unless data['api']['sso_salt']

  sso  = Sso.new(data)
  verb = sso.POST? ? 'POST' : 'GET'
  test "#{verb} #{sso.path}"

  check "validates token" do
    @sso.token = 'invalid'
    page, respcode = mechanize_get 
    error("expected 403, got #{respcode}") unless respcode == 403
    true
  end

  check "validates timestamp" do
    @sso.timestamp = (Time.now - 60*6).to_i
    page, respcode = mechanize_get
    error("expected 403, got #{respcode}") unless respcode == 403
    true
  end

  page_logged_in = nil
  check "logs in" do
    page_logged_in, respcode = mechanize_get 
    error("expected 200, got #{respcode}") unless respcode == 200
    true
  end

  check "creates the heroku-nav-data cookie" do
    cookie = agent.cookie_jar.cookies(URI.parse(@sso.full_url)).detect { |c| c.name == 'heroku-nav-data' }
    error("could not find cookie heroku-nav-data") unless cookie
    error("expected #{@sso.sample_nav_data}, got #{cookie.value}") unless cookie.value == @sso.sample_nav_data
    true
  end

  check "displays the heroku layout" do
      if page_logged_in.search('div#heroku-header').empty? &&
        page_logged_in.search('script[src*=boomerang]').empty?
        error("could not find Heroku layout")
      end
    true
  end
end

#check(msg) ⇒ Object



445
446
447
448
# File 'lib/heroku/kensa/check.rb', line 445

def check(msg)
  @sso = Sso.new(data)
  super
end

#mechanize_getObject



432
433
434
435
436
437
438
439
440
441
442
443
# File 'lib/heroku/kensa/check.rb', line 432

def mechanize_get
  if @sso.POST?
    page = agent.post(@sso.post_url, @sso.query_params)
  else
    page = agent.get(@sso.get_url)
  end
  return page, 200
rescue Mechanize::ResponseCodeError => error
  return nil, error.response_code.to_i
rescue Errno::ECONNREFUSED
  error("connection refused to #{url}")
end