vault-tools 0.4.15 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/vault-tools/version.rb +1 -1
- data/lib/vault-tools/web.rb +5 -4
- data/test/web_test.rb +49 -7
- metadata +4 -4
data/lib/vault-tools/version.rb
CHANGED
data/lib/vault-tools/web.rb
CHANGED
@@ -13,8 +13,8 @@ module Vault
|
|
13
13
|
helpers do
|
14
14
|
# Protects an http method. Returns 401 Not Authorized response
|
15
15
|
# when authorized? returns false
|
16
|
-
def protected!
|
17
|
-
unless authorized?
|
16
|
+
def protected!(*passwords)
|
17
|
+
unless authorized?(passwords)
|
18
18
|
response['WWW-Authenticate'] = %(Basic realm="Restricted Area")
|
19
19
|
throw(:halt, [401, "Not authorized\n"])
|
20
20
|
end
|
@@ -22,10 +22,11 @@ module Vault
|
|
22
22
|
|
23
23
|
# Check request for HTTP Basic creds and
|
24
24
|
# password matches settings.basic_password
|
25
|
-
def authorized?
|
25
|
+
def authorized?(passwords)
|
26
|
+
passwords << settings.basic_password if passwords.empty?
|
26
27
|
@auth ||= Rack::Auth::Basic::Request.new(request.env)
|
27
28
|
@auth.provided? && @auth.basic? && @auth.credentials &&
|
28
|
-
@auth.credentials[1]
|
29
|
+
passwords.include?(@auth.credentials[1])
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
data/test/web_test.rb
CHANGED
@@ -10,6 +10,15 @@ class WebTest < Vault::TestCase
|
|
10
10
|
@app ||= Class.new(Vault::Web)
|
11
11
|
end
|
12
12
|
|
13
|
+
# Middleware is attached at load time, so we have to delete the Vault::Web
|
14
|
+
# class and reload it to simulate being loaded with different environment
|
15
|
+
# variables.
|
16
|
+
def reload_web!
|
17
|
+
# remove the constant to force a clean reload
|
18
|
+
Vault.send(:remove_const, 'Web')
|
19
|
+
load 'lib/vault-tools/web.rb'
|
20
|
+
end
|
21
|
+
|
13
22
|
# Always reload the web class to eliminate test leakage
|
14
23
|
def setup
|
15
24
|
super
|
@@ -18,6 +27,11 @@ class WebTest < Vault::TestCase
|
|
18
27
|
reload_web!
|
19
28
|
end
|
20
29
|
|
30
|
+
def teardown
|
31
|
+
super
|
32
|
+
@app = nil
|
33
|
+
end
|
34
|
+
|
21
35
|
def test_http_basic_auth
|
22
36
|
app.set :basic_password, 'password'
|
23
37
|
app.get '/protected' do
|
@@ -33,13 +47,41 @@ class WebTest < Vault::TestCase
|
|
33
47
|
assert_equal 'You may pass', last_response.body
|
34
48
|
end
|
35
49
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
50
|
+
def test_http_basic_auth_with_alternate_password
|
51
|
+
app.set :basic_password, 'password'
|
52
|
+
app.get '/protected' do
|
53
|
+
protected!('leelu-dallas-multipass')
|
54
|
+
'You may pass'
|
55
|
+
end
|
56
|
+
|
57
|
+
get '/protected'
|
58
|
+
assert_equal 401, last_response.status
|
59
|
+
authorize('','password')
|
60
|
+
get '/protected'
|
61
|
+
assert_equal 401, last_response.status
|
62
|
+
authorize('','leelu-dallas-multipass')
|
63
|
+
get '/protected'
|
64
|
+
assert_equal 200, last_response.status
|
65
|
+
assert_equal 'You may pass', last_response.body
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_http_basic_auth_with_two_passwords
|
69
|
+
app.set :basic_password, 'password'
|
70
|
+
app.get '/protected' do
|
71
|
+
protected!('leelu-dallas-multipass','password')
|
72
|
+
'You may pass'
|
73
|
+
end
|
74
|
+
|
75
|
+
get '/protected'
|
76
|
+
assert_equal 401, last_response.status
|
77
|
+
authorize('','password')
|
78
|
+
get '/protected'
|
79
|
+
assert_equal 200, last_response.status
|
80
|
+
assert_equal 'You may pass', last_response.body
|
81
|
+
authorize('','leelu-dallas-multipass')
|
82
|
+
get '/protected'
|
83
|
+
assert_equal 200, last_response.status
|
84
|
+
assert_equal 'You may pass', last_response.body
|
43
85
|
end
|
44
86
|
|
45
87
|
# An `http_200` and an `http_2xx` log metric is written for successful
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vault-tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-01-
|
13
|
+
date: 2014-01-31 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: scrolls
|
@@ -239,7 +239,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
239
239
|
version: '0'
|
240
240
|
segments:
|
241
241
|
- 0
|
242
|
-
hash:
|
242
|
+
hash: 4584414138595131643
|
243
243
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
244
244
|
none: false
|
245
245
|
requirements:
|
@@ -248,7 +248,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
248
248
|
version: '0'
|
249
249
|
segments:
|
250
250
|
- 0
|
251
|
-
hash:
|
251
|
+
hash: 4584414138595131643
|
252
252
|
requirements: []
|
253
253
|
rubyforge_project:
|
254
254
|
rubygems_version: 1.8.23
|