bad URI error (does FakeWeb work on Windows?)

40 Aufrufe
Direkt zur ersten ungelesenen Nachricht

Bill Kocik

ungelesen,
04.05.2009, 00:31:4804.05.09
an FakeWeb

Hi all -

For some reason, if I require fakeweb in my code, I get an odd "bad
URI" message on any attempt to access a URI. I'm trying to use FakeWeb
to stand in the way of my Twitter app when I run Cucumber acceptance
tests. I do my authentication with OAuth. Here's a console session
without requiring fakeweb (o is an OAuth::Consumer object):

>> rt = o.get_request_token
=> #<OAuth::RequestToken:0x7f300a8c
@secret="xxxxxxxxxxxxxxxxxxxxxxxxx", @consumer=#<OAuth::Consumer:
0x7f3096dc @options={:oauth_version=>"1.0", :site=>"http://
twitter.com", :request_token_path=>"/oauth/
request_token", :scheme=>:header, :signature_method=>"HMAC-
SHA1", :http_method=>:post, :authorize_path=>"/oauth/
authorize", :access_token_path=>"/oauth/access_token"},
@http=#<Net::HTTP twitter.com:80 open=false>,
@key="xxxxxxxxxxxxxxxxx", @secret="xxxxxxxxxxxxxxxxxxxxxxxxx",
@http_method=:post>, @token="xxxxxxxxxxxxxxxxxxxxxxxxx">

You can see the call went out just fine, and I got back a request
token (I've blanked out some informatoin here for obvious reasons).
But now in the same console session:

>> require 'fakeweb'
=> []
>> rt = o.get_request_token
URI::InvalidURIError: bad URI(is not URI?): http://8♂-++r¶↓è?Ç@twitter.com:80/oauth/request_token
from /usr/lib/ruby/1.8/uri/common.rb:436:in `split'
from /usr/lib/ruby/1.8/uri/common.rb:485:in `parse'
from /usr/lib/ruby/gems/1.8/gems/fakeweb-1.2.1/lib/fake_web/
registry.rb:64:in `normalize_uri'
from /usr/lib/ruby/gems/1.8/gems/fakeweb-1.2.1/lib/fake_web/
registry.rb:24:in `registered_uri?'
from /usr/lib/ruby/gems/1.8/gems/fakeweb-1.2.1/lib/fake_web.rb:
150:in `registered_uri?'
from /usr/lib/ruby/gems/1.8/gems/fakeweb-1.2.1/lib/fake_web/
ext/net_http.rb:50:in `request'
from /usr/lib/ruby/gems/1.8/gems/oauth-0.3.2/lib/oauth/
consumer.rb:122:in `request'
from /usr/lib/ruby/gems/1.8/gems/oauth-0.3.2/lib/oauth/
consumer.rb:156:in `token_request'
from /usr/lib/ruby/gems/1.8/gems/oauth-0.3.2/lib/oauth/
consumer.rb:104:in `get_request_token'
from (irb):4

As soon as I require fakeweb, everything breaks, even though I haven't
registered any URIs or done anything else with it other than require
it into my code.

The only thing I can think of: I'm working in Cygwin on Windows XP
(not my idea). Does FakeWeb perhaps not work on Windows, or is this
something else?

Thanks...

Bill Kocik

ungelesen,
04.05.2009, 00:54:0104.05.09
an FakeWeb

To partially answer my own question (sorry for the bad form): It's not
a Windows problem. I see the same behavior on a Linux box I tried it
on, which I should have done before posting initially.

On XP/Cygwin I'm using fakeweb 1.2.1 and oauth 0.3.2 with Ruby ruby
1.8.7 p72. The Linux box is using Phusion Enterprise Ruby, which is a
1.8.6-compatible release. I also tried this with the chrisk-fakeweb
fork on GitHub and got the exact same behavior. The "bad URI" error is
identical everywhere I get it, right down to the same strange
characters in the URI it complains about.

Chris Kampmeier

ungelesen,
04.05.2009, 01:45:5804.05.09
an FakeWeb
On May 3, 9:54 pm, Bill Kocik <bko...@gmail.com> wrote:
> To partially answer my own question (sorry for the bad form): It's not
> a Windows problem. I see the same behavior on a Linux box I tried it
> on, which I should have done before posting initially.
>
> On XP/Cygwin I'm using fakeweb 1.2.1 and oauth 0.3.2 with Ruby ruby
> 1.8.7 p72. The Linux box is using Phusion Enterprise Ruby, which is a
> 1.8.6-compatible release.

Hi Bill, thanks for the report!

Yup, those were my first questions. Fakeweb reopens Net::HTTP, and
there are lots of different versions out there (corresponding to the
ruby versions). I definitely test fakeweb with 1.8.7p72 and a few
varieties of 1.8.6, among other rubies, so it sounds like neither
Windows nor your versions of Ruby are the problem per se.

If I had to guess, based on that sweet URI::InvalidURIError, I'd say
that OAuth's use of the HTTP headers "Authorization" and "WWW-
Authenticate" is confusing either Net::HTTP or fakeweb itself, and one
of them thinks you're doing HTTP Basic authentication. That pops up in
my mind because we *just* added HTTP basic auth support to fakeweb in
1.2.1 -- before that, fakeweb didn't know or care about it.

So, as a next step, can I ask you to try it with 1.2.0 and report
back?

I haven't started playing with OAuth myself, but if it works with
1.2.0, then I'll know the recent HTTP basic auth additions are
overstepping their bounds, and then I can try adding some failing
tests to fakeweb's suite to confirm.

Thanks again,
Chris Kampmeier

Chris Kampmeier

ungelesen,
04.05.2009, 02:11:4804.05.09
an FakeWeb
> If I had to guess, based on that sweet URI::InvalidURIError, I'd say
> that OAuth's use of the HTTP headers "Authorization" and "WWW-
> Authenticate" is confusing either Net::HTTP or fakeweb itself, and one
> of them thinks you're doing HTTP Basic authentication. That pops up in
> my mind because we *just* added HTTP basic auth support to fakeweb in
> 1.2.1 -- before that, fakeweb didn't know or care about it.
>
> So, as a next step, can I ask you to try it with 1.2.0 and report
> back?

Another clue: Cássio Marques was successfully doing just about the
same thing as you, about two weeks ago:
http://cassiomarques.wordpress.com/2009/04/23/utilizando-fakeweb-cucumber-para-testar-autenticacao-por-oauth-no-twitter/
(in Portuguese, but hey.)

Chris

Chris Kampmeier

ungelesen,
04.05.2009, 03:42:2504.05.09
an FakeWeb
On May 3, 10:45 pm, Chris Kampmeier <ChrisGKampme...@gmail.com> wrote:
> If I had to guess, based on that sweet URI::InvalidURIError, I'd say
> that OAuth's use of the HTTP headers "Authorization" and "WWW-
> Authenticate" is confusing either Net::HTTP or fakeweb itself, and one
> of them thinks you're doing HTTP Basic authentication. That pops up in
> my mind because we *just* added HTTP basic auth support to fakeweb in
> 1.2.1 -- before that, fakeweb didn't know or care about it.

Indeed, that was it. Definitely fakeweb's fault, the new HTTP Basic
support was being a little too aggressive with the "Authorization"
header. Fixed!

http://github.com/chrisk/fakeweb/commit/871ff8949b5297328db8c86c82c7251eaaab5d50

I'll try to get out a 1.2.2 release tomorrow. In the meantime, I think
the 1.2.0 gem should work for you.

Chris

Bill Kocik

ungelesen,
04.05.2009, 10:13:0004.05.09
an fakewe...@googlegroups.com
On Mon, May 4, 2009 at 3:42 AM, Chris Kampmeier
<ChrisGK...@gmail.com> wrote:

> Indeed, that was it. Definitely fakeweb's fault, the new HTTP Basic
> support was being a little too aggressive with the "Authorization"
> header. Fixed!

You're too fast for me. I was in the midst of trying to reply to your
first message when I saw the next two. :)

That does make perfect sense, since OAuth uses those headers to store
tokens and signatures and such.

> http://github.com/chrisk/fakeweb/commit/871ff8949b5297328db8c86c82c7251eaaab5d50
>
> I'll try to get out a 1.2.2 release tomorrow. In the meantime, I think
> the 1.2.0 gem should work for you.

Awesome! Thanks so much!

--
Bill Kocik

http://bkocik.net

Bill Kocik

ungelesen,
04.05.2009, 16:28:1004.05.09
an fakewe...@googlegroups.com
Since I can't figure out how to install 1.2.0, I'll just wait for
1.2.2 to make its appearance. :)

Chris Kampmeier

ungelesen,
04.05.2009, 20:24:2704.05.09
an FakeWeb
On May 4, 1:28 pm, Bill Kocik <bko...@gmail.com> wrote:
> Since I can't figure out how to install 1.2.0, I'll just wait for
> 1.2.2 to make its appearance. :)

OK, I just pushed a 1.2.2 release to rubyforge. You should be able to
install it as usual with rubygems. If you get 1.2.1, try again in a
bit, sometimes the gem mirrors take a little while to update. Sorry
about the hassle with 1.2.1, this should fix things up.

I don't know if your cygwin stack is different, but usually you can do
something like `[sudo] gem install fakeweb --version=1.2.0` to install
a different version. Careful, though, you'd either want to uninstall
the newer one, or explicitly require the older version using
rubygems's #gem method:

require "rubygems"
gem "fakeweb", "1.2.0"
require "fakeweb"

Anyway, 1.2.2 should be available now, so try that instead :) Let me
know how it works out.

Chris

Bill Kocik

ungelesen,
04.05.2009, 20:51:3704.05.09
an fakewe...@googlegroups.com
On Mon, May 4, 2009 at 8:24 PM, Chris Kampmeier
<ChrisGK...@gmail.com> wrote:

> I don't know if your cygwin stack is different, but usually you can do
> something like `[sudo] gem install fakeweb --version=1.2.0` to install
> a different version.

D'oh! I actually use config.gem to manage my gems, and for some reason
I had it set up with :source => "http://gems.github.com". No wonder it
didn't work.

> Anyway, 1.2.2 should be available now, so try that instead :)  Let me
> know how it works out.

Yep, I've got it, and it did indeed solve the problem. Of course, now
my tests fail, but that's my fault, not yours. :)

Thanks so much for the quick turnaround. This gem is a lifesaver for
testing this project, which depends heavily on Twitter's API.

Allen antworten
Antwort an Autor
Weiterleiten
0 neue Nachrichten