DISQUS

DISQUS Hello! ruby on rails blog is using DISQUS, a powerful comment system, to manage its comments. Learn more.

Community Page

Jump to original thread »
Author

Testing with Basic HTTP Authentication in Rails 2.0 | ruby on rails blog

Started by ngng · 10 months ago

No excerpt available. Jump to website »

9 comments

  • Thanks for the tip. You just saved me couple of hours of fighting with the tests.

    Take Care.

    Hugues
  • Ce n'est pas un problème! (That's my year of Français I took coming out)

    I definitely spent too much time trying to figure this out...it's the simple things that are always a pain!
  • Thanks! Finally made my tests work..

    Regards
  • It's always kind of cool when random people read your blog and you can help them :)
  • Ahh, yes! I've been looking for this too. Thanks!
  • thanks for this. helped in our functional tests of our REST services using http basic auth.
  • A few months late, I found this via the Google. A couple notes:

    In case you're unfamiliar with testing Rails, this goes in test/test_helper.rb

    The function above doesn't actually let you test HTTP Authentication. To do that you'll need to do something like:

    def authenticate_with_http(username, password)
    @request.env[”HTTP_AUTHORIZATION”] =
    "Basic #{Base64.encode64("#{username}:#{password}")}"
    end
  • This was just what I needed!

    Like unit testing you can do

    def setup
    http_auth
    end

    so all your test methods are authenticated.
  • Instead of using Base64 directly, it's better to use:

    ActionController::HttpAuthentication::Basic.encode_credentials('username', 'password')

Add New Comment

Returning? Login