vault-tools 0.3.7 → 0.3.8
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/.ruby-version +1 -0
- data/lib/vault-tools/shushu_db_tasks.rb +31 -0
- data/lib/vault-tools/version.rb +1 -1
- data/lib/vault-tools/web.rb +20 -0
- data/test/web_test.rb +16 -1
- metadata +5 -2
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.9.2-p290
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# Rake tasks for Shushu DB
|
2
|
+
#
|
3
|
+
# include in Rakefile via:
|
4
|
+
#
|
5
|
+
# require 'vault-tools/shushu_db_tasks'
|
6
|
+
|
7
|
+
desc "Pull db/structure.sql from shushu HEAD"
|
8
|
+
task :pull_shushu do
|
9
|
+
steps = []
|
10
|
+
steps << 'cd contrib/'
|
11
|
+
if File.exists?('contrib/shushu')
|
12
|
+
steps << 'rm -rf shushu'
|
13
|
+
end
|
14
|
+
steps << 'git clone -n git@github.com:heroku/shushud shushu --depth 1'
|
15
|
+
steps << 'cd shushu'
|
16
|
+
steps << 'git checkout HEAD db/*'
|
17
|
+
# make sure we don't submodule it
|
18
|
+
steps << 'rm -rf .git'
|
19
|
+
sh steps.join(' && ')
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "Drop and create shushu-test database"
|
23
|
+
task :create_shushu_db => [:drop_shushu_db, :pull_shushu] do
|
24
|
+
sh 'createdb shushu-test'
|
25
|
+
sh 'cd contrib/shushu && ../../vendor/bin/sequel postgres:///shushu-test -m db/migrations'
|
26
|
+
end
|
27
|
+
|
28
|
+
desc "Drop the vault-usage-test, core-test and shushu-test databases"
|
29
|
+
task :drop_shushu_db do
|
30
|
+
sh 'dropdb shushu-test || true'
|
31
|
+
end
|
data/lib/vault-tools/version.rb
CHANGED
data/lib/vault-tools/web.rb
CHANGED
@@ -9,6 +9,26 @@ module Vault
|
|
9
9
|
super
|
10
10
|
end
|
11
11
|
|
12
|
+
# HTTP Basic Auth Support
|
13
|
+
helpers do
|
14
|
+
# Protects an http method. Returns 401 Not Authorized response
|
15
|
+
# when authorized? returns false
|
16
|
+
def protected!
|
17
|
+
unless authorized?
|
18
|
+
response['WWW-Authenticate'] = %(Basic realm="Restricted Area")
|
19
|
+
throw(:halt, [401, "Not authorized\n"])
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Check request for HTTP Basic creds and
|
24
|
+
# password matches settings.basic_password
|
25
|
+
def authorized?
|
26
|
+
@auth ||= Rack::Auth::Basic::Request.new(request.env)
|
27
|
+
@auth.provided? && @auth.basic? && @auth.credentials &&
|
28
|
+
@auth.credentials[1] == settings.basic_password
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
12
32
|
# Start timing the request.
|
13
33
|
before do
|
14
34
|
@start_request = Time.now
|
data/test/web_test.rb
CHANGED
@@ -5,7 +5,7 @@ class WebTest < Vault::TestCase
|
|
5
5
|
|
6
6
|
# Anonymous Web Frontend
|
7
7
|
def app
|
8
|
-
Class.new(Vault::Web)
|
8
|
+
@app ||= Class.new(Vault::Web)
|
9
9
|
end
|
10
10
|
|
11
11
|
# Always reload the web class to eliminate test leakage
|
@@ -14,6 +14,21 @@ class WebTest < Vault::TestCase
|
|
14
14
|
reload_web!
|
15
15
|
end
|
16
16
|
|
17
|
+
def test_http_basic_auth
|
18
|
+
app.set :basic_password, 'password'
|
19
|
+
app.get '/protected' do
|
20
|
+
protected!
|
21
|
+
'OKIE'
|
22
|
+
end
|
23
|
+
|
24
|
+
get '/protected'
|
25
|
+
assert_equal 401, last_response.status
|
26
|
+
authorize('','password')
|
27
|
+
get '/protected'
|
28
|
+
assert_equal 200, last_response.status
|
29
|
+
assert_equal 'OKIE', last_response.body
|
30
|
+
end
|
31
|
+
|
17
32
|
# Middleware is attached at load time, so we have to delete the Vault::Web
|
18
33
|
# class and reload it to simulate being loaded with different environment
|
19
34
|
# variables.
|
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.3.
|
4
|
+
version: 0.3.8
|
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: 2013-
|
13
|
+
date: 2013-05-14 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: scrolls
|
@@ -103,6 +103,7 @@ extensions: []
|
|
103
103
|
extra_rdoc_files: []
|
104
104
|
files:
|
105
105
|
- .gitignore
|
106
|
+
- .ruby-version
|
106
107
|
- .yardopts
|
107
108
|
- Gemfile
|
108
109
|
- LICENSE.txt
|
@@ -117,6 +118,7 @@ files:
|
|
117
118
|
- lib/vault-tools/payments_db_tasks.rb
|
118
119
|
- lib/vault-tools/pipeline.rb
|
119
120
|
- lib/vault-tools/product.rb
|
121
|
+
- lib/vault-tools/shushu_db_tasks.rb
|
120
122
|
- lib/vault-tools/sinatra_helpers/html_serializer.rb
|
121
123
|
- lib/vault-tools/user.rb
|
122
124
|
- lib/vault-tools/version.rb
|
@@ -157,3 +159,4 @@ signing_key:
|
|
157
159
|
specification_version: 3
|
158
160
|
summary: Test classes, base web classes, and helpers - oh my!
|
159
161
|
test_files: []
|
162
|
+
has_rdoc:
|