mechanical-cuke 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -100,6 +100,14 @@ bc. Then show me the page
100
100
 
101
101
  Save the current page and open in the default browser.
102
102
 
103
+ h2. Basic Auth
104
+
105
+ You can provide basic auth credentials by calling:
106
+
107
+ bc. basic_auth(username,password)
108
+
109
+ in your step definitions before visiting a protected page.
110
+
103
111
  h2. Todo
104
112
 
105
113
  Add scopes to allow steps to function within an element e.g:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
@@ -0,0 +1,12 @@
1
+ Given /^I have no basic auth credentials$/ do
2
+ basic_auth(nil, nil)
3
+ end
4
+
5
+ Then /^I should not be able to access (.+)$/ do |page_name|
6
+ assert_raise(Mechanize::ResponseCodeError) { get path_to(page_name) }
7
+ end
8
+
9
+ Given /^I have basic auth credentials "([^\"]*)"$/ do |credentials|
10
+ username, password = credentials.split(':')
11
+ basic_auth(username, password)
12
+ end
@@ -13,6 +13,8 @@ module NavigationHelpers
13
13
  '/table'
14
14
  when /the upload page/
15
15
  '/upload'
16
+ when /the protected page/
17
+ '/protected'
16
18
  else
17
19
  raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
18
20
  "Now, go and add a mapping in #{__FILE__}"
@@ -59,6 +59,12 @@ Feature: Using Mechanize
59
59
  And I should see "Named"
60
60
  And I should see "ID-ed"
61
61
 
62
+ Scenario: Basic Auth
63
+ Given I have no basic auth credentials
64
+ Then I should not be able to access the protected page
65
+ Given I have basic auth credentials "username:password"
66
+ When I go to the protected page
67
+ Then I should see "Authorized!"
62
68
 
63
69
  @mock_launchy
64
70
  Scenario: Save and Open Step
@@ -25,6 +25,10 @@ module MechanicalCuke
25
25
  def response_body
26
26
  current_page.body
27
27
  end
28
+
29
+ def basic_auth(username,password)
30
+ mechanize.basic_auth(username,password)
31
+ end
28
32
  end
29
33
 
30
34
  World(MechanicalCuke)
@@ -36,3 +36,15 @@ post '/upload' do
36
36
  "File #{name} uploaded"
37
37
  end
38
38
  end
39
+
40
+ get '/protected' do
41
+ auth = Rack::Auth::Basic::Request.new(request.env)
42
+ if auth.provided? && auth.basic? && auth.credentials &&
43
+ auth.credentials == ['username', 'password']
44
+ "Authorized!"
45
+ else
46
+ response['WWW-Authenticate'] = %(Basic realm="Protected")
47
+ throw :halt, [ 401, 'Authorization Required' ]
48
+ end
49
+ end
50
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mechanical-cuke
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Spike Ilacqua
@@ -58,6 +58,7 @@ files:
58
58
  - README.textile
59
59
  - Rakefile
60
60
  - VERSION
61
+ - features/step_definitions/basic_auth_steps.rb
61
62
  - features/step_definitions/mechanical-cuke_steps.rb
62
63
  - features/step_definitions/table_steps.rb
63
64
  - features/support/env.rb