bbc-capybara-mechanize 0.3.8 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -21,6 +21,9 @@ class Capybara::Mechanize::Browser < Capybara::RackTest::Browser
21
21
  if driver.options[:user_agent]
22
22
  @agent.user_agent = driver.options[:user_agent]
23
23
  end
24
+ if driver.options[:username] and driver.options[:password]
25
+ @agent.basic_auth(driver.options[:username], driver.options[:password])
26
+ end
24
27
  if driver.options[:proxy] && !driver.options[:proxy].empty?
25
28
  proxy = nil
26
29
  begin
@@ -38,6 +41,10 @@ class Capybara::Mechanize::Browser < Capybara::RackTest::Browser
38
41
  super
39
42
  end
40
43
 
44
+ def auth(username, password)
45
+ @agent.basic_auth(username, password)
46
+ end
47
+
41
48
  def reset_host!
42
49
  @last_remote_host = nil
43
50
  @last_request_remote = nil
@@ -1,5 +1,5 @@
1
1
  module Capybara
2
2
  module Mechanize
3
- VERSION = '0.3.8'
3
+ VERSION = '0.4'
4
4
  end
5
5
  end
@@ -2,6 +2,22 @@ require 'capybara/spec/test_app'
2
2
 
3
3
  class ExtendedTestApp < TestApp#< Sinatra::Base
4
4
  set :environment, :production # so we don't get debug info that makes our test pass!
5
+
6
+ helpers do
7
+
8
+ def protected!
9
+ unless authorized?
10
+ response['WWW-Authenticate'] = %(Basic realm="Restricted Area")
11
+ throw(:halt, [401, "Not authorized\n"])
12
+ end
13
+ end
14
+
15
+ def authorized?
16
+ @auth ||= Rack::Auth::Basic::Request.new(request.env)
17
+ @auth.provided? && @auth.basic? && @auth.credentials && @auth.credentials == ['admin', 'password']
18
+ end
19
+
20
+ end
5
21
 
6
22
  get %r{/redirect_to/(.*)} do
7
23
  redirect params[:captures]
@@ -34,7 +50,11 @@ class ExtendedTestApp < TestApp#< Sinatra::Base
34
50
  post '/request_info/*' do
35
51
  current_request_info
36
52
  end
37
-
53
+
54
+ get '/basic_auth/' do
55
+ protected!
56
+ %{Successfully authenticated}
57
+ end
38
58
 
39
59
  private
40
60
 
@@ -71,4 +71,27 @@ describe Capybara::Session do
71
71
  @session.body.should include("Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3")
72
72
  end
73
73
  end
74
+
75
+ context "Basic HTTP Auth" do
76
+
77
+ before do
78
+ @session = Capybara::Session.new(:mechanize, TestApp)
79
+ @session.driver.options[:respect_data_method] = true
80
+ Capybara.default_host = 'http://www.local.com'
81
+ end
82
+
83
+ it "should allow basic authentication to be setup" do
84
+ @session.driver.options[:username] = "admin"
85
+ @session.driver.options[:password] = "password"
86
+ @session.visit("#{REMOTE_TEST_URL}/basic_auth/")
87
+ @session.body.should include("Successfully authenticated")
88
+ end
89
+
90
+ it "should allow basic authentication via auth method" do
91
+ @session.driver.browser.auth("admin", "password")
92
+ @session.visit("#{REMOTE_TEST_URL}/basic_auth/")
93
+ @session.body.should include("Successfully authenticated")
94
+ end
95
+
96
+ end
74
97
  end
metadata CHANGED
@@ -5,9 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 3
9
- - 8
10
- version: 0.3.8
8
+ - 4
9
+ version: "0.4"
11
10
  platform: ruby
12
11
  authors:
13
12
  - Jeroen van Dijk
@@ -16,7 +15,7 @@ autorequire:
16
15
  bindir: bin
17
16
  cert_chain: []
18
17
 
19
- date: 2012-03-14 00:00:00 Z
18
+ date: 2012-03-22 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  version_requirements: &id001 !ruby/object:Gem::Requirement