Re: [Cucumber] [Ruby] problem with testing basic_auth

98 views
Skip to first unread message

Matt Wynne

unread,
Sep 27, 2012, 6:23:44 AM9/27/12
to cu...@googlegroups.com

On 27 Sep 2012, at 09:08, Gerd Koenig wrote:

Hey all,

I started playing with cucumber-nagios recently and wanted to use the basic_auth functionality for checking a website that requires HTTP basic authentication. There are many examples out there and I think I did it like described, but I always receive an "401 => Net::HTTPUnauthorized"-error. Now I'm stuck there and don't know how to proceed......

The details:
=========
basic-auth-test.feature
""
Feature: mytestwebserver.com
  It should be up

  Scenario: test basic_auth
    When I visit the url "http://mytestwebserver.com/status.php"
    Then the request should succeed

  Scenario: test basic_auth_2
    Given I am logged in
    And I go to "http://mytestwebserver.com/status.php"
    Then the request should succeed



""

basic-auth-test_steps.rb
""
Given /^I am logged in$/ do
  basic_auth('myuser','mypassword')
end

When /^I visit the url "(.*)"$/ do |u|
  basic_auth('myuser','mypassword')
  visit u
end

""

============================

If I run the test via command line => "cucumber --require ./features features/mytestwebserver.com/basic-auth-test.feature" I get the following error (for each of both scenarios):
""
Scenario: test basic auth                                          # features/mytestwebserver.com/basic-auth-test.feature:9
    When I visit the url "http://sn1.slaves.memonews.com/status.php" # features/mytestwebserver.com/steps/basic-auth-test_steps.rb:5
      401 => Net::HTTPUnauthorized (Mechanize::ResponseCodeError)

  
""

The content of webrat's log file is:
""
D, [2012-09-27T09:42:16.957571 #27060] DEBUG -- : REQUESTING PAGE: GET http://http://mytestwebserver.com/status.php with {} and HTTP headers {"HTTP_AUTHORIZATION"=>"Basic bmFnaW9zOlFZVURwQ1NJVHp1OHZuQVMxcEZk"}
""

The login via browser to the website works, and the browsers webdeveloper extension prints exactly the same authorization hash, therefore I assume the credentials are correct ?!? Here is the header information from successful browser login (manually):
""
GET /status.php HTTP/1.1 Host: mytestwebserver.com Connection: keep-alive Cache-Control: max-age=0 Authorization: Basic bmFnaW9zOlFZVURwQ1NJVHp1OHZuQVMxcEZk
""

====================================

while looking for further debugging options I wanted to include save_and_open_page to have a look at the page webrat is dealing with, but I got the error:
""
      undefined method `content' for nil:NilClass (NoMethodError)
      /var/lib/gems/1.8/gems/webrat-0.7.2/lib/webrat/adapters/mechanize.rb:43:in `response_body'
      /var/lib/gems/1.8/gems/webrat-0.7.2/lib/webrat/core/save_and_open_page.rb:14:in `save_and_open_page'
      /var/lib/gems/1.8/gems/webrat-0.7.2/lib/webrat/core/save_and_open_page.rb:13:in `open'
      /var/lib/gems/1.8/gems/webrat-0.7.2/lib/webrat/core/save_and_open_page.rb:13:in `save_and_open_page'


""
hmmmmm, no idea what to do....

====================================

Now I really don't know what to check further and how to get to a working basic_auth authorization......any help highly appreciated. If you need more information just let me know...

many thanks in advance...:: Gerd ::....

--
-- Rules --
 
1) Please prefix the subject with [Ruby], [JVM] or [JS].
2) Please use interleaved answers http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
3) If you have a question, don't reply to an existing message. Start a new topic instead.
 
You received this message because you are subscribed to the Google Groups Cukes group. To post to this group, send email to cu...@googlegroups.com. To unsubscribe from this group, send email to cukes+un...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/cukes?hl=en

I'd approach the cucumber-nagios guys directly if I were you.


Gerd Koenig

unread,
Sep 27, 2012, 7:08:00 AM9/27/12
to cu...@googlegroups.com
Hi Matt,

thanks for answering.
Yes, I did it, too, although I ran the test with plain cucumber command. That's the reason why I posted it here, I thought the error isn't dedicated to just cucumber-nagios. Nobody else with that basic_auth related issue ?

br....: Gerd :...

Ben Lovell

unread,
Sep 27, 2012, 7:20:22 AM9/27/12
to cu...@googlegroups.com
Hi

 I'd check the remote logs and ensure your test is actually reaching the endpoint you expect. Alternatively you could sniff the exchange with wireshark or a similar tool. Either way this isn't necessarily a discussion for this list. You might have more luck pitching it over on the webrat list, although one would assume that is a ghost town these days.

Regards,
Ben
Reply all
Reply to author
Forward
0 new messages