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, #callback, #create_provision_payload, #credentials, #heroku_id

Methods inherited from Check

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

Constructor Details

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

Instance Method Details

#agentObject



489
490
491
# File 'lib/heroku/kensa/check.rb', line 489

def agent
  @agent ||= Mechanize.new
end

#call!Object



511
512
513
514
515
516
517
518
519
520
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
# File 'lib/heroku/kensa/check.rb', line 511

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



506
507
508
509
# File 'lib/heroku/kensa/check.rb', line 506

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

#mechanize_getObject



493
494
495
496
497
498
499
500
501
502
503
504
# File 'lib/heroku/kensa/check.rb', line 493

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