[rspec-users] Cucumber, Webrat and http basic auth

aslak hellesoy aslak.hellesoy at gmail.com
Thu Nov 20 06:11:54 EST 2008


On Thu, Nov 20, 2008 at 11:32 AM, kwe <kwevans at gmail.com> wrote:
> Starting out with Cucumber and webrat and seem to be hitting a problem
> with a resource protected with http basic auth.
>
> i.e.
>
> The following feature..
>
> Feature: Manage Pages
>  In order to add a reference pages
>  As a administrator
>  I want to create a page
>
>        Scenario: Add a page
>                Given I am logged in
>          And I am on the new page page
>                Then I should see "New page"
>                When I fill in "page_title" with "Demo Page"
>                And I fill in "page_summary" with "A short trip to the loo"
>                And I fill in "page_body" with "A very long long long story"
>                And I press "Create"
>                Then I should see "Show Page: Demo Page"
>
> with the step "Given I am logged in" defined as..
>
> Given /^I am logged in$/ do
>        basic_auth('username', 'apassword')
> end
>
> All the steps work and a record is created, but the last step fails
> with a "HTTP Basic: Access denied"
>
> test.log has a
>
> Processing PagesController#show (for 127.0.0.1 at 2008-11-19 22:52:23)
> [GET]
>  Session ID:
> BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo
> SGFzaHsGOgtub3RpY2UiI1BhZ2Ugd2FzIHN1Y2Nlc3NmdWxseSBjcmVhdGVk
> LgY6CkB1c2VkewY7BkY=--fb242e74f0776d7728d62c6224c763ed60ad7064
>  Parameters: {"action"=>"show", "id"=>"1-demo-page",
> "controller"=>"admin/pages"}
> Filter chain halted as [:authenticate] rendered_or_redirected.
> Completed in 0.00095 (1053 reqs/sec) | Rendering: 0.00081 (85%) | DB:
> 0.00000 (0%) | 401 Unauthorized [http://www.example.com/admin/pages/1-
> demo-page]
>
> The :authenticate it refers to is a pretty standard..
>
>  def authenticate
>     authenticate_or_request_with_http_basic("no peeping") do |
> username, password|
>       username == 'username' && password == 'apassword'
>     end
>  end
>
> I'm assuming it's possibly an implementation problem with webrat?!?!

I added basic auth support to webrat a few weeks back, and Bryan pulled it in:
http://github.com/brynary/webrat/commit/17cf56eb5e9f3872b842a43a3181caca4f005a28

Are you using this?

Aslak

> Given that the steps to fill out the form and press the create button
> work fine (HTTP_AUTHORIZATION is passed in the heads for each action),
> but sadly not for the redirect that follows the creation of a record.
>
> Any ideas how I should proceed?
>
> with thanks
> Kevin
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list