Permalink
Browse files

Merge pull request #1 from mptre/master

Adding support for HTTP Basic Auth.
  • Loading branch information...
2 parents f1c4b04 + 078c374 commit 7f3ca6c4cf21aca43d5eadd0999aed28f76698eb @hannestyden committed Mar 30, 2012
Showing with 35 additions and 0 deletions.
  1. +1 −0 lib/hyperspec.rb
  2. +20 −0 spec/fixtures/vcr_cassettes/localhost.yml
  3. +14 −0 spec/hyperspec_spec.rb
View
1 lib/hyperspec.rb
@@ -108,6 +108,7 @@ def request_response(klass, uri, headers, body = '')
req = klass.new(request_uri)
headers.inject(req) { |m, (k, v)| m[k] = v; m }
req.body = body if body
+ req.basic_auth(uri.user, uri.password) if uri.userinfo
if headers['Content-Type']
req.content_type = headers['Content-Type']
end
View
20 spec/fixtures/vcr_cassettes/localhost.yml
@@ -92,3 +92,23 @@
body: |+
{"is-this-json":true}
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
+ method: :get
+ uri: http://username:password@localhost:80/secret
+ headers:
+ authorization:
+ - Basic dXNlcm5hbWU6cGFzc3dvcmQ=
+ body:
+ response: !ruby/struct:VCR::Response
+ http_version: "1.1"
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 200
+ message: OK
+ headers:
+ content-length:
+ - "24"
+ content-type:
+ - application/json;charset=utf-8
+ body: |+
+ {"is-this-secret":true}
View
14 spec/hyperspec_spec.rb
@@ -204,5 +204,19 @@
it { subject.status_code 200 }
it { subject.status :ok }
end
+
+ describe "basic auth" do
+ subject do
+ the_spec do |bound|
+ service("http://username:password@localhost") do
+ resource("/secret") do
+ bound.value = get {}
+ end
+ end
+ end.response
+ end
+
+ it { subject.status_code.must_equal 200 }
+ end
end
end

0 comments on commit 7f3ca6c

Please sign in to comment.