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 +8 -0
- data/VERSION +1 -1
- data/features/step_definitions/basic_auth_steps.rb +12 -0
- data/features/support/paths.rb +2 -0
- data/features/web_steps.feature +6 -0
- data/lib/mechanical-cuke.rb +4 -0
- data/test/fixtures/server/server.rb +12 -0
- metadata +2 -1
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.
|
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
|
data/features/support/paths.rb
CHANGED
data/features/web_steps.feature
CHANGED
@@ -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
|
data/lib/mechanical-cuke.rb
CHANGED
@@ -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.
|
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
|