Class: Heroku::Kensa::SsoCheck

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

Instance Attribute Summary

Attributes inherited from Check

#data, #screen

Instance Method Summary collapse

Methods included from HTTPForChecks

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

Methods inherited from ApiCheck

#base_path, #callback, #create_provision_payload, #credentials, #heroku_id

Methods inherited from Check

#api_requires?, #call, #env, #error, #initialize, #run, #test, #to_proc, #url, #warning

Constructor Details

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

Instance Method Details

#agentObject



499
500
501
# File 'lib/heroku/kensa/check.rb', line 499

def agent
  @agent ||= Mechanize.new
end

#call!Object



521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
# File 'lib/heroku/kensa/check.rb', line 521

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



516
517
518
519
# File 'lib/heroku/kensa/check.rb', line 516

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

#mechanize_getObject



503
504
505
506
507
508
509
510
511
512
513
514
# File 'lib/heroku/kensa/check.rb', line 503

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