rack-cerberus 0.2.0 → 0.3.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/README.md +11 -0
- data/cerberus.gemspec +1 -1
- data/cerberus.rb +1 -1
- data/spec.rb +6 -6
- metadata +4 -4
data/README.md
CHANGED
@@ -50,6 +50,16 @@ If you want to see a concrete example, go into the Cerberus directory and run:
|
|
50
50
|
|
51
51
|
It's gonna start the example at http://localhost:9292
|
52
52
|
|
53
|
+
You can also use the 3rd argument which is the request object:
|
54
|
+
|
55
|
+
use Cerberus, {:company_name => 'Nintendo'} do |login, pass, req|
|
56
|
+
pass=='secret' && req.xhr?
|
57
|
+
end
|
58
|
+
|
59
|
+
This is more if you use it as a gateway for an API or something and you want to check other values.
|
60
|
+
Like the referer or another parameter.
|
61
|
+
But bear in mind that `cerberus_login` and `cerberus_pass` are still mandatory.
|
62
|
+
|
53
63
|
Logout
|
54
64
|
------
|
55
65
|
|
@@ -74,6 +84,7 @@ Changelog
|
|
74
84
|
0.1.5 Fix CSS and Javascript for IE (Yes I'm too kind)
|
75
85
|
0.1.6 Send an Array instead of a string to Rack so that it works on Ruby 1.9
|
76
86
|
0.2.0 External CSS file + `:text_color` option + keep details after login failure
|
87
|
+
0.3.0 Now sends request as a 3rd argument to the block
|
77
88
|
|
78
89
|
Copyright
|
79
90
|
---------
|
data/cerberus.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'rack-cerberus'
|
3
|
-
s.version = "0.
|
3
|
+
s.version = "0.3.0"
|
4
4
|
s.platform = Gem::Platform::RUBY
|
5
5
|
s.summary = "A Rack middleware for form-based authentication"
|
6
6
|
s.description = "A Rack middleware for form-based authentication. Aim is a compromise between fonctionality, beauty and customization."
|
data/cerberus.rb
CHANGED
@@ -85,7 +85,7 @@ PAGE
|
|
85
85
|
login = req['cerberus_login']
|
86
86
|
pass = req['cerberus_pass']
|
87
87
|
err = req.post? ? "<p class='err'>Wrong login or password</p>" : ''
|
88
|
-
if ((env['rack.session']['cerberus_user']!=nil && env['PATH_INFO']!='/logout') || (login && pass && @block.call(login, pass)))
|
88
|
+
if ((env['rack.session']['cerberus_user']!=nil && env['PATH_INFO']!='/logout') || (login && pass && @block.call(login, pass, req)))
|
89
89
|
env['rack.session']['cerberus_user'] ||= login
|
90
90
|
if env['PATH_INFO']=='/logout'
|
91
91
|
res = Rack::Response.new(env)
|
data/spec.rb
CHANGED
@@ -9,9 +9,9 @@ Bacon.summary_on_exit
|
|
9
9
|
describe 'cerberus' do
|
10
10
|
|
11
11
|
secret_app = lambda {|env| [200, {'Content-Type'=>'text/plain'}, env['rack.session'].inspect] }
|
12
|
-
app = Rack::Session::Cookie.new(Cerberus.new(secret_app, {}) {|login,pass| [login,pass]==['mario','bros']})
|
12
|
+
app = Rack::Session::Cookie.new(Cerberus.new(secret_app, {}) {|login,pass| [login,pass]==['mario@nintendo.com','bros']})
|
13
13
|
req = Rack::MockRequest.new(app)
|
14
|
-
app_with_css =
|
14
|
+
app_with_css = Rack::Session::Cookie.new(Cerberus.new(secret_app, {:css_location=>'/main.css'}) {|login,pass| [login,pass]==['mario','bros']})
|
15
15
|
req_with_css = Rack::MockRequest.new(app_with_css)
|
16
16
|
cookie = ''
|
17
17
|
|
@@ -37,7 +37,7 @@ describe 'cerberus' do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
should 'Give access with the appropriate login and pass' do
|
40
|
-
res = req.get('/', :params => {'cerberus_login' => 'mario', 'cerberus_pass' => 'bros'})
|
40
|
+
res = req.get('/', :params => {'cerberus_login' => 'mario@nintendo.com', 'cerberus_pass' => 'bros'})
|
41
41
|
cookie = res["Set-Cookie"]
|
42
42
|
res.status.should==200
|
43
43
|
end
|
@@ -45,7 +45,7 @@ describe 'cerberus' do
|
|
45
45
|
should 'Use session for persistent login' do
|
46
46
|
res = req.get('/', "HTTP_COOKIE" => cookie)
|
47
47
|
res.status.should==200
|
48
|
-
res.body.should=='{"cerberus_user"=>"mario"}'
|
48
|
+
res.body.should=='{"cerberus_user"=>"mario@nintendo.com"}'
|
49
49
|
cookie = res["Set-Cookie"]
|
50
50
|
req.get('/', "HTTP_COOKIE" => cookie).status.should==200
|
51
51
|
end
|
@@ -59,12 +59,12 @@ describe 'cerberus' do
|
|
59
59
|
end
|
60
60
|
|
61
61
|
should 'Not send not_found when logging after a logout (because the path is /logout)' do
|
62
|
-
res = req.get('/logout', :params => {'cerberus_login' => 'mario', 'cerberus_pass' => 'bros'})
|
62
|
+
res = req.get('/logout', :params => {'cerberus_login' => 'mario@nintendo.com', 'cerberus_pass' => 'bros'})
|
63
63
|
res.status.should==302
|
64
64
|
res['Location'].should=='/'
|
65
65
|
|
66
66
|
req = Rack::MockRequest.new(Rack::URLMap.new({'/backend' => app}))
|
67
|
-
res = req.get('/backend/logout', :params => {'cerberus_login' => 'mario', 'cerberus_pass' => 'bros'})
|
67
|
+
res = req.get('/backend/logout', :params => {'cerberus_login' => 'mario@nintendo.com', 'cerberus_pass' => 'bros'})
|
68
68
|
res.status.should==302
|
69
69
|
res['Location'].should=='/backend'
|
70
70
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-cerberus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 3
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Mickael Riga
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-10-07 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|