Class: Xplenty::Kensa::SsoCheck
- Includes:
- HTTP
- Defined in:
- lib/xplenty/kensa/check.rb
Instance Attribute Summary
Attributes inherited from Check
Instance Method Summary collapse
Methods included from HTTP
#delete, #get, #post, #put, #request
Methods inherited from ApiCheck
#base_path, #credentials, #xplenty_id
Methods inherited from Check
#call, #env, #error, #initialize, #run, #test, #to_proc, #url
Constructor Details
This class inherits a constructor from Xplenty::Kensa::Check
Instance Method Details
#agent ⇒ Object
409 410 411 |
# File 'lib/xplenty/kensa/check.rb', line 409 def agent @agent ||= Mechanize.new end |
#call! ⇒ Object
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 |
# File 'lib/xplenty/kensa/check.rb', line 431 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. = (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 xplenty-nav-data cookie" do = agent..(URI.parse(@sso.full_url)).detect { |c| c.name == 'xplenty-nav-data' } error("could not find cookie xplenty-nav-data") unless error("expected #{@sso.sample_nav_data}, got #{.value}") unless .value == @sso.sample_nav_data true end check "displays the xplenty layout" do if page_logged_in.search('div#xplenty-header').empty? && page_logged_in.search('script[src*=boomerang]').empty? error("could not find Xplenty layout") end true end end |
#check(msg) ⇒ Object
426 427 428 429 |
# File 'lib/xplenty/kensa/check.rb', line 426 def check(msg) @sso = Sso.new(data) super end |
#mechanize_get ⇒ Object
413 414 415 416 417 418 419 420 421 422 423 424 |
# File 'lib/xplenty/kensa/check.rb', line 413 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 |