litmus_paper 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -27,6 +27,7 @@ module LitmusPaper
|
|
27
27
|
uri = URI.parse(@uri)
|
28
28
|
request = Net::HTTP.const_get(@method.capitalize).new(uri.normalize.path)
|
29
29
|
request.set_form_data({})
|
30
|
+
request.basic_auth(uri.user, uri.password) if uri.user || uri.password
|
30
31
|
|
31
32
|
connection = Net::HTTP.new(uri.host, uri.port)
|
32
33
|
connection.open_timeout = @timeout
|
data/lib/litmus_paper/version.rb
CHANGED
@@ -39,6 +39,30 @@ describe LitmusPaper::Dependency::HTTP do
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
+
context "basic auth" do
|
43
|
+
it "uses the basic auth credentials provided in the URL" do
|
44
|
+
check = LitmusPaper::Dependency::HTTP.new("http://admin:admin@127.0.0.1:9294/basic_auth")
|
45
|
+
check.should be_available
|
46
|
+
end
|
47
|
+
|
48
|
+
it "works with blank password" do
|
49
|
+
check = LitmusPaper::Dependency::HTTP.new("http://justadmin:@127.0.0.1:9294/basic_auth_without_password")
|
50
|
+
check.should be_available
|
51
|
+
end
|
52
|
+
|
53
|
+
it "works with blank user" do
|
54
|
+
check = LitmusPaper::Dependency::HTTP.new("http://:justpassword@127.0.0.1:9294/basic_auth_without_user")
|
55
|
+
check.should be_available
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "special characters in path" do
|
60
|
+
it "works with a URI encoded slash" do
|
61
|
+
check = LitmusPaper::Dependency::HTTP.new("http://admin:admin@127.0.0.1:9294/return_next_path_segment/%2F", :content => '/')
|
62
|
+
check.should be_available
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
42
66
|
it "is true when response is 200" do
|
43
67
|
check = LitmusPaper::Dependency::HTTP.new("#{@url}/status/200")
|
44
68
|
check.should be_available
|
@@ -25,7 +25,40 @@ class HttpTestServer < Sinatra::Base
|
|
25
25
|
text 200, "Woke up after #{params.inspect} seconds"
|
26
26
|
end
|
27
27
|
|
28
|
+
get '/basic_auth' do
|
29
|
+
requires_basic_auth!('admin', 'admin')
|
30
|
+
"Welcome, authenticated client"
|
31
|
+
end
|
32
|
+
|
33
|
+
get '/basic_auth_without_password' do
|
34
|
+
requires_basic_auth!('justadmin', '')
|
35
|
+
"Welcome, authenticated client"
|
36
|
+
end
|
37
|
+
|
38
|
+
get '/basic_auth_without_user' do
|
39
|
+
requires_basic_auth!('', 'justpassword')
|
40
|
+
"Welcome, authenticated client"
|
41
|
+
end
|
42
|
+
|
43
|
+
get '/return_next_path_segment/:something' do
|
44
|
+
params[:something]
|
45
|
+
end
|
46
|
+
|
28
47
|
def text(response_code, body, headers ={})
|
29
48
|
[response_code, { "Content-Type" => "text/plain" }.merge(headers), body]
|
30
49
|
end
|
50
|
+
|
51
|
+
helpers do
|
52
|
+
def requires_basic_auth!(user, pass)
|
53
|
+
unless authorized?(user, pass)
|
54
|
+
response['WWW-Authenticate'] = %(Basic realm="Restricted Area")
|
55
|
+
throw(:halt, [401, "Not authorized\n"])
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def authorized?(user, pass)
|
60
|
+
@auth ||= Rack::Auth::Basic::Request.new(request.env)
|
61
|
+
@auth.provided? && @auth.basic? && @auth.credentials && @auth.credentials == [user, pass]
|
62
|
+
end
|
63
|
+
end
|
31
64
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: litmus_paper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 6
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.6.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Braintreeps
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-08-
|
18
|
+
date: 2012-08-21 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|