FakeWeb.register fails with an e-mail address as username

33 views
Skip to first unread message

Ken Mayer

unread,
Jul 2, 2009, 10:04:20 PM7/2/09
to FakeWeb
This is not really fakeweb's fault, but perhaps there's another way to
handle Basic Auth... If the username is an e-mail address (which is
used more and more frequently, then the Standard Library URI parse
croaks on the URI passed in.

Here's how I reproduce this:

$ gem list -l fakeweb
fakeweb (1.2.4)
r$ irb -rubygems -r fakeweb
irb(main):001:0> FakeWeb.register_uri(:get, "http://
som...@example.org:test@localhost:3000/foobar.html", :body => "")
URI::InvalidURIError: the scheme http does not accept registry part:
som...@example.org:test@localhost:3000 (or bad hostname?)
from /opt/local/lib/ruby/1.8/uri/generic.rb:195:in `initialize'
from /opt/local/lib/ruby/1.8/uri/http.rb:78:in `initialize'
from /opt/local/lib/ruby/1.8/uri/common.rb:488:in `new'
from /opt/local/lib/ruby/1.8/uri/common.rb:488:in `parse'
from /opt/local/lib/ruby/gems/1.8/gems/fakeweb-1.2.4/lib/fake_web/
registry.rb:95:in `normalize_uri'
from /opt/local/lib/ruby/gems/1.8/gems/fakeweb-1.2.4/lib/fake_web/
registry.rb:21:in `register_uri'
from /opt/local/lib/ruby/gems/1.8/gems/fakeweb-1.2.4/lib/fake_web.rb:
113:in `register_uri'
from (irb):1

Chris Kampmeier

unread,
Jul 3, 2009, 2:49:31 AM7/3/09
to FakeWeb
On Jul 2, 10:04 pm, Ken Mayer <li...@bitwrangler.com> wrote:
> This is not really fakeweb's fault, but perhaps there's another way to
> handle Basic Auth... If the username is an e-mail address (which is
> used more and more frequently, then the Standard Library URI parse
> croaks on the URI passed in.
>
> Here's how I reproduce this:
>
> $ gem list -l fakeweb
> fakeweb (1.2.4)
> r$ irb -rubygems -r fakeweb
> irb(main):001:0> FakeWeb.register_uri(:get, "http://
> some...@example.org:test@localhost:3000/foobar.html", :body => "")
> URI::InvalidURIError: the scheme http does not accept registry part:
> some...@example.org:test@localhost:3000 (or bad hostname?)

Hey Ken, thanks for posting. I think what you were trying to do is not
quite valid, but I wrote a test for the actual valid approach and it
doesn't work either :) oops. So I just fixed that:
http://github.com/chrisk/fakeweb/commit/1ad638500be9ddd570c6a888e5b344a2f8e82216

Here's what you should do once that's released (in 1.2.5):

# percent-encode unsafe characters in the userinfo part, per RFC 3986
FakeWeb.register_uri(:get, "http://someone
%40example.org:test@localhost:3000/foobar.html", :body => "")

http = Net::HTTP.new("localhost", 3000)
request = Net::HTTP::Get.new("/foobar.html")
request.basic_auth("som...@example.org", "test") # but no need to
escape here, since it's not a URI
http.request(request)

That should do the trick. I'll try to release 1.2.5 soon -- I need to
refactor the ugly implementation in that commit a bit, and write some
more tests.

Thanks again,
Chris

Ken Mayer

unread,
Jul 3, 2009, 4:37:31 AM7/3/09
to fakewe...@googlegroups.com
Chris,

Thanks for the update!

Aloha a hui hou,
Ken
--
Ken Mayer / kma...@bitwrangler.com / 808-722-6142 / http://www.bitwrangler.com/
Reply all
Reply to author
Forward
0 new messages