rack-wwwhisper 1.1.5 → 1.1.6
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/rack/wwwhisper.rb +15 -8
- data/lib/rack/wwwhisper_version.rb +1 -1
- data/test/test_wwwhisper.rb +17 -14
- metadata +3 -9
data/lib/rack/wwwhisper.rb
CHANGED
@@ -11,11 +11,11 @@ require 'rack/wwwhisper_version'
|
|
11
11
|
|
12
12
|
module Rack
|
13
13
|
|
14
|
-
# Communicates with the wwwhisper service to authorize each
|
14
|
+
# Communicates with the wwwhisper service to authorize each incoming
|
15
15
|
# request. Acts as a proxy for requests to locations handled by
|
16
16
|
# wwwhisper (/wwwhisper/auth and /wwwhisper/admin)
|
17
17
|
#
|
18
|
-
# For each
|
18
|
+
# For each incoming request an authorization query is sent.
|
19
19
|
# The query contains a normalized path that a request is
|
20
20
|
# trying to access and wwwhisper session cookies. The
|
21
21
|
# query result determines the action to be performed:
|
@@ -24,6 +24,8 @@ module Rack
|
|
24
24
|
# page is returned.
|
25
25
|
# [403] the user is not authorized, request is denied, error is returned.
|
26
26
|
# [any other] error while communicating with wwwhisper, request is denied.
|
27
|
+
#
|
28
|
+
# This class is thread safe, it can handle multiple simultaneous requests.
|
27
29
|
class WWWhisper
|
28
30
|
# Path prefix of requests that are passed to wwwhisper.
|
29
31
|
@@WWWHISPER_PREFIX = '/wwwhisper/'
|
@@ -59,8 +61,16 @@ class WWWhisper
|
|
59
61
|
# HTML documents (has a default value).
|
60
62
|
def initialize(app)
|
61
63
|
@app = app
|
62
|
-
if ENV['
|
64
|
+
if not ENV['WWWHISPER_URL']
|
63
65
|
def self.call(env)
|
66
|
+
# Delay check for WWWHISPER_DISABLE until the first
|
67
|
+
# request. This way Rails assets pipeline does not fail if
|
68
|
+
# environment variables are not set (as is the case on
|
69
|
+
# Heroku).
|
70
|
+
if ENV['WWWHISPER_DISABLE'] != '1'
|
71
|
+
raise(StandardError,
|
72
|
+
'WWWHISPER_URL nor WWWHISPER_DISABLE environment variable set')
|
73
|
+
end
|
64
74
|
@app.call(env)
|
65
75
|
end
|
66
76
|
return
|
@@ -68,10 +78,7 @@ class WWWhisper
|
|
68
78
|
|
69
79
|
@app = NoPublicCache.new(app)
|
70
80
|
|
71
|
-
|
72
|
-
raise StandardError, 'WWWHISPER_URL environment variable not set'
|
73
|
-
end
|
74
|
-
|
81
|
+
# net/http/persistent connections are thread safe.
|
75
82
|
@http = http_init('wwwhisper')
|
76
83
|
@wwwhisper_uri = parse_uri(ENV['WWWHISPER_URL'])
|
77
84
|
|
@@ -127,7 +134,7 @@ class WWWhisper
|
|
127
134
|
def parse_uri(uri)
|
128
135
|
parsed_uri = Addressable::URI.parse(uri)
|
129
136
|
# If port is not specified, net/http/persistent uses port 80 for
|
130
|
-
# https connections which is
|
137
|
+
# https connections which is counter-intuitive.
|
131
138
|
parsed_uri.port ||= parsed_uri.default_port
|
132
139
|
parsed_uri
|
133
140
|
end
|
data/test/test_wwwhisper.rb
CHANGED
@@ -70,11 +70,27 @@ class TestWWWhisper < Test::Unit::TestCase
|
|
70
70
|
|
71
71
|
def test_wwwhisper_url_required
|
72
72
|
ENV.delete('WWWHISPER_URL')
|
73
|
+
# Exception should not be raised during initialization, but during
|
74
|
+
# the first request.
|
75
|
+
@wwwhisper = Rack::WWWhisper.new(MockBackend.new(nil))
|
73
76
|
assert_raise(StandardError) {
|
74
|
-
|
77
|
+
get '/foo/bar'
|
75
78
|
}
|
76
79
|
end
|
77
80
|
|
81
|
+
def test_disable_wwwhisper
|
82
|
+
ENV.delete('WWWHISPER_URL')
|
83
|
+
ENV['WWWHISPER_DISABLE'] = "1"
|
84
|
+
# Configure MockBackend to make sure REMOTE_USER is not set.
|
85
|
+
@wwwhisper = Rack::WWWhisper.new(MockBackend.new(nil))
|
86
|
+
|
87
|
+
path = '/foo/bar'
|
88
|
+
get path
|
89
|
+
assert last_response.ok?
|
90
|
+
assert_equal 'Hello World', last_response.body
|
91
|
+
assert_nil last_response['User']
|
92
|
+
end
|
93
|
+
|
78
94
|
def test_auth_query_path
|
79
95
|
assert_equal('/wwwhisper/auth/api/is-authorized/?path=/foo/bar',
|
80
96
|
@wwwhisper.auth_query('/foo/bar'))
|
@@ -305,19 +321,6 @@ class TestWWWhisper < Test::Unit::TestCase
|
|
305
321
|
assert_requested :get, full_url(@wwwhisper.auth_query(path))
|
306
322
|
end
|
307
323
|
|
308
|
-
def test_disable_wwwhisper
|
309
|
-
ENV.delete('WWWHISPER_URL')
|
310
|
-
ENV['WWWHISPER_DISABLE'] = "1"
|
311
|
-
# Configure MockBackend to make sure REMOTE_USER is not set.
|
312
|
-
@wwwhisper = Rack::WWWhisper.new(MockBackend.new(nil))
|
313
|
-
|
314
|
-
path = '/foo/bar'
|
315
|
-
get path
|
316
|
-
assert last_response.ok?
|
317
|
-
assert_equal 'Hello World', last_response.body
|
318
|
-
assert_nil last_response['User']
|
319
|
-
end
|
320
|
-
|
321
324
|
def test_chunked_encoding_from_wwwhisper_removed
|
322
325
|
path = '/foo/bar'
|
323
326
|
stub_request(:get, full_url(@wwwhisper.auth_query(path))).
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-wwwhisper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-04-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
@@ -107,7 +107,7 @@ dependencies:
|
|
107
107
|
- - ! '>='
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
|
-
description: Middleware
|
110
|
+
description: Middleware uses wwwhisper service to authorize requests.
|
111
111
|
email: wrr@mixedbit.org
|
112
112
|
executables: []
|
113
113
|
extensions: []
|
@@ -130,18 +130,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
130
130
|
- - ! '>='
|
131
131
|
- !ruby/object:Gem::Version
|
132
132
|
version: '0'
|
133
|
-
segments:
|
134
|
-
- 0
|
135
|
-
hash: 239074857713187767
|
136
133
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
134
|
none: false
|
138
135
|
requirements:
|
139
136
|
- - ! '>='
|
140
137
|
- !ruby/object:Gem::Version
|
141
138
|
version: '0'
|
142
|
-
segments:
|
143
|
-
- 0
|
144
|
-
hash: 239074857713187767
|
145
139
|
requirements: []
|
146
140
|
rubyforge_project:
|
147
141
|
rubygems_version: 1.8.24
|