sinatra_warden 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -0
- data/README.rdoc +1 -1
- data/Rakefile +3 -5
- data/VERSION +1 -1
- data/bin/autospec +1 -1
- data/bin/css2sass +3 -0
- data/bin/edit_json.rb +3 -0
- data/bin/haml +3 -0
- data/bin/html2haml +3 -0
- data/bin/jeweler +3 -0
- data/bin/prettify_json.rb +3 -0
- data/bin/rackup +1 -1
- data/bin/rake +1 -1
- data/bin/rcov +2 -2
- data/bin/rubyforge +3 -0
- data/bin/sass +3 -0
- data/bin/spec +1 -1
- data/bin/yard-graph +1 -1
- data/bin/yardoc +1 -1
- data/bin/yri +1 -1
- data/lib/sinatra_warden/sinatra.rb +6 -5
- data/sinatra_warden.gemspec +5 -28
- data/spec/fixtures/basic_strategy.rb +10 -0
- data/spec/fixtures/testing_login.rb +6 -0
- data/spec/fixtures/user.rb +4 -10
- data/spec/fixtures/{bcrypt_strategy.rb → views/login.haml} +0 -0
- data/spec/sinatra_warden_spec.rb +32 -9
- data/spec/spec_helper.rb +6 -1
- metadata +12 -83
data/Gemfile
CHANGED
@@ -4,6 +4,8 @@ gem 'sinatra', '>= 0.9.4'
|
|
4
4
|
gem 'warden', '~> 0.5.0'
|
5
5
|
|
6
6
|
gem 'rake', :only => :testing
|
7
|
+
gem 'jeweler', :only => :testing
|
8
|
+
gem 'bundler', :only => :testing
|
7
9
|
gem 'rspec', '~> 1.2.9', :only => :testing, :require_as => 'spec'
|
8
10
|
gem 'yard', :only => :testing
|
9
11
|
gem 'rack-test', '~> 0.5.0', :only => :testing, :require_as => 'rack/test'
|
@@ -12,5 +14,7 @@ gem 'rcov', :only => :testing
|
|
12
14
|
gem 'do_sqlite3', '~> 0.10.0', :only => :testing
|
13
15
|
gem 'dm-core', '~> 0.10.1', :only => :testing
|
14
16
|
gem 'bcrypt-ruby', :only => :testing, :require_as => 'bcrypt'
|
17
|
+
gem 'haml', :only => :testing
|
18
|
+
gem 'rack-flash', :only => :testing, :require_as => 'rack/flash'
|
15
19
|
|
16
20
|
disable_system_gems
|
data/README.rdoc
CHANGED
@@ -32,7 +32,7 @@ We use bundler on this project and disable system gems. Contributers should do t
|
|
32
32
|
$ git clone git://github.com/jsmestad/sinatra_warden.git
|
33
33
|
$ cd sinatra_warden
|
34
34
|
$ gem bundle
|
35
|
-
$ rake
|
35
|
+
$ ./bin/rake
|
36
36
|
|
37
37
|
* Fork the project.
|
38
38
|
* Make your feature addition or bug fix.
|
data/Rakefile
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
require '
|
1
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), 'vendor', 'gems', 'environment')
|
2
|
+
Bundler.require_env
|
2
3
|
require 'rake'
|
3
4
|
require 'bundler'
|
4
5
|
|
@@ -14,11 +15,10 @@ begin
|
|
14
15
|
|
15
16
|
manifest = Bundler::Environment.load(File.dirname(__FILE__) + '/Gemfile')
|
16
17
|
manifest.dependencies.each do |d|
|
17
|
-
next if d.only && d.only.include?('
|
18
|
+
next if d.only && d.only.include?('testing')
|
18
19
|
gem.add_dependency(d.name, d.version)
|
19
20
|
end
|
20
21
|
|
21
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
22
22
|
end
|
23
23
|
Jeweler::GemcutterTasks.new
|
24
24
|
rescue LoadError
|
@@ -37,8 +37,6 @@ Spec::Rake::SpecTask.new(:rcov) do |spec|
|
|
37
37
|
spec.rcov = true
|
38
38
|
end
|
39
39
|
|
40
|
-
task :spec => :check_dependencies
|
41
|
-
|
42
40
|
task :default => :spec
|
43
41
|
|
44
42
|
begin
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/bin/autospec
CHANGED
data/bin/css2sass
ADDED
data/bin/edit_json.rb
ADDED
data/bin/haml
ADDED
data/bin/html2haml
ADDED
data/bin/jeweler
ADDED
data/bin/rackup
CHANGED
data/bin/rake
CHANGED
data/bin/rcov
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
#!/usr/bin/
|
1
|
+
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
|
2
2
|
require File.join(File.dirname(__FILE__), "../vendor/gems/environment")
|
3
|
-
load File.join(File.dirname(__FILE__), "../vendor/gems/gems/rcov-0.9.
|
3
|
+
load File.join(File.dirname(__FILE__), "../vendor/gems/gems/rcov-0.9.6/bin/rcov")
|
data/bin/rubyforge
ADDED
data/bin/sass
ADDED
data/bin/spec
CHANGED
data/bin/yard-graph
CHANGED
data/bin/yardoc
CHANGED
data/bin/yri
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Sinatra
|
2
2
|
module Warden
|
3
3
|
module Helpers
|
4
|
-
|
4
|
+
|
5
5
|
# The main accessor for the warden proxy instance
|
6
6
|
def warden
|
7
7
|
request.env['warden']
|
@@ -35,9 +35,9 @@ module Sinatra
|
|
35
35
|
|
36
36
|
def self.registered(app)
|
37
37
|
app.helpers Warden::Helpers
|
38
|
-
|
38
|
+
|
39
39
|
app.set :auth_failure_path, '/'
|
40
|
-
app.set :auth_success_path, lambda{ back }
|
40
|
+
app.set :auth_success_path, lambda { back }
|
41
41
|
|
42
42
|
app.set :auth_error_message, "Could not log you in."
|
43
43
|
app.set :auth_success_message, "You have logged in successfully."
|
@@ -46,7 +46,7 @@ module Sinatra
|
|
46
46
|
|
47
47
|
app.post '/unauthenticated/?' do
|
48
48
|
status 401
|
49
|
-
flash[:error] =
|
49
|
+
flash[:error] = options.auth_error_message if defined?(Rack::Flash)
|
50
50
|
options.auth_use_erb ? erb(options.auth_login_template) : haml(options.auth_login_template)
|
51
51
|
end
|
52
52
|
|
@@ -61,8 +61,9 @@ module Sinatra
|
|
61
61
|
end
|
62
62
|
|
63
63
|
app.get '/logout/?' do
|
64
|
+
authorize!
|
64
65
|
env['warden'].logout
|
65
|
-
flash[:success] = options.
|
66
|
+
flash[:success] = options.auth_success_message if defined?(Rack::Flash)
|
66
67
|
redirect options.auth_success_path
|
67
68
|
end
|
68
69
|
end
|
data/sinatra_warden.gemspec
CHANGED
@@ -5,14 +5,14 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{sinatra_warden}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Justin Smestad", "Daniel Neighman"]
|
12
12
|
s.date = %q{2009-11-03}
|
13
13
|
s.description = %q{basic helpers and authentication methods for using warden with sinatra also providing some hooks into Rack::Flash}
|
14
14
|
s.email = %q{justin.smestad@gmail.com}
|
15
|
-
s.executables = ["autospec", "rackup", "rake", "rcov", "spec", "yard-graph", "yardoc", "yri"]
|
15
|
+
s.executables = ["autospec", "css2sass", "edit_json.rb", "haml", "html2haml", "jeweler", "prettify_json.rb", "rackup", "rake", "rcov", "rubyforge", "sass", "spec", "yard-graph", "yardoc", "yri"]
|
16
16
|
s.extra_rdoc_files = [
|
17
17
|
"LICENSE",
|
18
18
|
"README.rdoc"
|
@@ -28,9 +28,10 @@ Gem::Specification.new do |s|
|
|
28
28
|
"lib/sinatra_warden.rb",
|
29
29
|
"lib/sinatra_warden/sinatra.rb",
|
30
30
|
"sinatra_warden.gemspec",
|
31
|
-
"spec/fixtures/
|
31
|
+
"spec/fixtures/basic_strategy.rb",
|
32
32
|
"spec/fixtures/testing_login.rb",
|
33
33
|
"spec/fixtures/user.rb",
|
34
|
+
"spec/fixtures/views/login.haml",
|
34
35
|
"spec/sinatra_warden_spec.rb",
|
35
36
|
"spec/spec.opts",
|
36
37
|
"spec/spec_helper.rb"
|
@@ -41,7 +42,7 @@ Gem::Specification.new do |s|
|
|
41
42
|
s.rubygems_version = %q{1.3.5}
|
42
43
|
s.summary = %q{authentication system for using warden with sinatra}
|
43
44
|
s.test_files = [
|
44
|
-
"spec/fixtures/
|
45
|
+
"spec/fixtures/basic_strategy.rb",
|
45
46
|
"spec/fixtures/testing_login.rb",
|
46
47
|
"spec/fixtures/user.rb",
|
47
48
|
"spec/sinatra_warden_spec.rb",
|
@@ -55,37 +56,13 @@ Gem::Specification.new do |s|
|
|
55
56
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
56
57
|
s.add_runtime_dependency(%q<sinatra>, [">= 0.9.4"])
|
57
58
|
s.add_runtime_dependency(%q<warden>, ["~> 0.5.0"])
|
58
|
-
s.add_runtime_dependency(%q<rake>, [">= 0"])
|
59
|
-
s.add_runtime_dependency(%q<rspec>, ["~> 1.2.9"])
|
60
|
-
s.add_runtime_dependency(%q<yard>, [">= 0"])
|
61
|
-
s.add_runtime_dependency(%q<rack-test>, ["~> 0.5.0"])
|
62
|
-
s.add_runtime_dependency(%q<rcov>, [">= 0"])
|
63
|
-
s.add_runtime_dependency(%q<do_sqlite3>, ["~> 0.10.0"])
|
64
|
-
s.add_runtime_dependency(%q<dm-core>, ["~> 0.10.1"])
|
65
|
-
s.add_runtime_dependency(%q<bcrypt-ruby>, [">= 0"])
|
66
59
|
else
|
67
60
|
s.add_dependency(%q<sinatra>, [">= 0.9.4"])
|
68
61
|
s.add_dependency(%q<warden>, ["~> 0.5.0"])
|
69
|
-
s.add_dependency(%q<rake>, [">= 0"])
|
70
|
-
s.add_dependency(%q<rspec>, ["~> 1.2.9"])
|
71
|
-
s.add_dependency(%q<yard>, [">= 0"])
|
72
|
-
s.add_dependency(%q<rack-test>, ["~> 0.5.0"])
|
73
|
-
s.add_dependency(%q<rcov>, [">= 0"])
|
74
|
-
s.add_dependency(%q<do_sqlite3>, ["~> 0.10.0"])
|
75
|
-
s.add_dependency(%q<dm-core>, ["~> 0.10.1"])
|
76
|
-
s.add_dependency(%q<bcrypt-ruby>, [">= 0"])
|
77
62
|
end
|
78
63
|
else
|
79
64
|
s.add_dependency(%q<sinatra>, [">= 0.9.4"])
|
80
65
|
s.add_dependency(%q<warden>, ["~> 0.5.0"])
|
81
|
-
s.add_dependency(%q<rake>, [">= 0"])
|
82
|
-
s.add_dependency(%q<rspec>, ["~> 1.2.9"])
|
83
|
-
s.add_dependency(%q<yard>, [">= 0"])
|
84
|
-
s.add_dependency(%q<rack-test>, ["~> 0.5.0"])
|
85
|
-
s.add_dependency(%q<rcov>, [">= 0"])
|
86
|
-
s.add_dependency(%q<do_sqlite3>, ["~> 0.10.0"])
|
87
|
-
s.add_dependency(%q<dm-core>, ["~> 0.10.1"])
|
88
|
-
s.add_dependency(%q<bcrypt-ruby>, [">= 0"])
|
89
66
|
end
|
90
67
|
end
|
91
68
|
|
@@ -1,8 +1,14 @@
|
|
1
1
|
class TestingLogin < Sinatra::Base
|
2
2
|
register Sinatra::Warden
|
3
3
|
|
4
|
+
set :views, File.join(File.dirname(__FILE__), 'views')
|
5
|
+
set :sessions, true
|
6
|
+
|
7
|
+
set :auth_success_path, '/welcome'
|
8
|
+
|
4
9
|
get '/dashboard' do
|
5
10
|
authorize!('/login')
|
11
|
+
"My Dashboard"
|
6
12
|
end
|
7
13
|
|
8
14
|
get '/admin' do
|
data/spec/fixtures/user.rb
CHANGED
@@ -1,20 +1,14 @@
|
|
1
|
-
require 'dm-core'
|
2
|
-
require 'bcrypt'
|
3
1
|
|
4
2
|
class User
|
5
3
|
include DataMapper::Resource
|
6
4
|
|
7
5
|
property :id, Serial
|
8
6
|
property :email, String
|
9
|
-
property :
|
7
|
+
property :password, String
|
10
8
|
|
11
|
-
def password
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
def password
|
17
|
-
@password ||= BCrypt::Password.new(encrypted_password)
|
9
|
+
def self.authenticate(email, password)
|
10
|
+
u = self.first(:email => email)
|
11
|
+
u.password == password ? u : nil
|
18
12
|
end
|
19
13
|
|
20
14
|
end
|
File without changes
|
data/spec/sinatra_warden_spec.rb
CHANGED
@@ -9,13 +9,23 @@ describe "SinatraWarden" do
|
|
9
9
|
@user.new?.should be_false
|
10
10
|
end
|
11
11
|
|
12
|
-
|
12
|
+
it "should create successfully" do
|
13
|
+
@user.password.should == "thedude"
|
14
|
+
User.authenticate('justin.smestad@gmail.com', 'thedude').should == @user
|
15
|
+
end
|
13
16
|
|
14
|
-
|
17
|
+
context "the authentication system" do
|
15
18
|
|
16
|
-
it "should allow us to
|
19
|
+
it "should allow us to login as that user" do
|
20
|
+
post '/login', 'email' => 'justin.smestad@gmail.com', 'password' => 'thedude'
|
21
|
+
last_request.env['warden'].authenticated?.should == true
|
22
|
+
end
|
17
23
|
|
18
|
-
it "should
|
24
|
+
it "should allow us to logout after logging in" do
|
25
|
+
post '/login', 'email' => 'justin.smestad@gmail.com', 'password' => 'thedude'
|
26
|
+
last_request.env['warden'].authenticated?.should == true
|
27
|
+
pending
|
28
|
+
end
|
19
29
|
|
20
30
|
end
|
21
31
|
|
@@ -23,11 +33,24 @@ describe "SinatraWarden" do
|
|
23
33
|
|
24
34
|
context "the authorize! helper" do
|
25
35
|
|
26
|
-
it "should redirect to root if not logged in"
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
36
|
+
it "should redirect to root (default) if not logged in" do
|
37
|
+
get '/admin'
|
38
|
+
follow_redirect!
|
39
|
+
last_request.url.should == 'http://example.org/'
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should redirect to the passed path if available" do
|
43
|
+
get '/dashboard'
|
44
|
+
follow_redirect!
|
45
|
+
last_request.url.should == 'http://example.org/login'
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should allow access if user is logged in" do
|
49
|
+
post '/login', 'email' => 'justin.smestad@gmail.com', 'password' => 'thedude'
|
50
|
+
last_request.env['warden'].authenticated?.should == true
|
51
|
+
get '/dashboard'
|
52
|
+
last_response.body.should == "My Dashboard"
|
53
|
+
end
|
31
54
|
|
32
55
|
end
|
33
56
|
|
data/spec/spec_helper.rb
CHANGED
@@ -28,7 +28,12 @@ Spec::Runner.configure do |config|
|
|
28
28
|
def app
|
29
29
|
@app ||= Rack::Builder.app do
|
30
30
|
use Rack::Session::Cookie
|
31
|
-
|
31
|
+
use Warden::Manager do |manager|
|
32
|
+
manager.default_strategies :password
|
33
|
+
manager.failure_app = TestingLogin
|
34
|
+
end
|
35
|
+
use Rack::Flash
|
36
|
+
run TestingLogin
|
32
37
|
end
|
33
38
|
end
|
34
39
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra_warden
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Smestad
|
@@ -33,93 +33,21 @@ dependencies:
|
|
33
33
|
- !ruby/object:Gem::Version
|
34
34
|
version: 0.5.0
|
35
35
|
version:
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: rake
|
38
|
-
type: :runtime
|
39
|
-
version_requirement:
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
requirements:
|
42
|
-
- - ">="
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
version: "0"
|
45
|
-
version:
|
46
|
-
- !ruby/object:Gem::Dependency
|
47
|
-
name: rspec
|
48
|
-
type: :runtime
|
49
|
-
version_requirement:
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ~>
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 1.2.9
|
55
|
-
version:
|
56
|
-
- !ruby/object:Gem::Dependency
|
57
|
-
name: yard
|
58
|
-
type: :runtime
|
59
|
-
version_requirement:
|
60
|
-
version_requirements: !ruby/object:Gem::Requirement
|
61
|
-
requirements:
|
62
|
-
- - ">="
|
63
|
-
- !ruby/object:Gem::Version
|
64
|
-
version: "0"
|
65
|
-
version:
|
66
|
-
- !ruby/object:Gem::Dependency
|
67
|
-
name: rack-test
|
68
|
-
type: :runtime
|
69
|
-
version_requirement:
|
70
|
-
version_requirements: !ruby/object:Gem::Requirement
|
71
|
-
requirements:
|
72
|
-
- - ~>
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
version: 0.5.0
|
75
|
-
version:
|
76
|
-
- !ruby/object:Gem::Dependency
|
77
|
-
name: rcov
|
78
|
-
type: :runtime
|
79
|
-
version_requirement:
|
80
|
-
version_requirements: !ruby/object:Gem::Requirement
|
81
|
-
requirements:
|
82
|
-
- - ">="
|
83
|
-
- !ruby/object:Gem::Version
|
84
|
-
version: "0"
|
85
|
-
version:
|
86
|
-
- !ruby/object:Gem::Dependency
|
87
|
-
name: do_sqlite3
|
88
|
-
type: :runtime
|
89
|
-
version_requirement:
|
90
|
-
version_requirements: !ruby/object:Gem::Requirement
|
91
|
-
requirements:
|
92
|
-
- - ~>
|
93
|
-
- !ruby/object:Gem::Version
|
94
|
-
version: 0.10.0
|
95
|
-
version:
|
96
|
-
- !ruby/object:Gem::Dependency
|
97
|
-
name: dm-core
|
98
|
-
type: :runtime
|
99
|
-
version_requirement:
|
100
|
-
version_requirements: !ruby/object:Gem::Requirement
|
101
|
-
requirements:
|
102
|
-
- - ~>
|
103
|
-
- !ruby/object:Gem::Version
|
104
|
-
version: 0.10.1
|
105
|
-
version:
|
106
|
-
- !ruby/object:Gem::Dependency
|
107
|
-
name: bcrypt-ruby
|
108
|
-
type: :runtime
|
109
|
-
version_requirement:
|
110
|
-
version_requirements: !ruby/object:Gem::Requirement
|
111
|
-
requirements:
|
112
|
-
- - ">="
|
113
|
-
- !ruby/object:Gem::Version
|
114
|
-
version: "0"
|
115
|
-
version:
|
116
36
|
description: basic helpers and authentication methods for using warden with sinatra also providing some hooks into Rack::Flash
|
117
37
|
email: justin.smestad@gmail.com
|
118
38
|
executables:
|
119
39
|
- autospec
|
40
|
+
- css2sass
|
41
|
+
- edit_json.rb
|
42
|
+
- haml
|
43
|
+
- html2haml
|
44
|
+
- jeweler
|
45
|
+
- prettify_json.rb
|
120
46
|
- rackup
|
121
47
|
- rake
|
122
48
|
- rcov
|
49
|
+
- rubyforge
|
50
|
+
- sass
|
123
51
|
- spec
|
124
52
|
- yard-graph
|
125
53
|
- yardoc
|
@@ -140,9 +68,10 @@ files:
|
|
140
68
|
- lib/sinatra_warden.rb
|
141
69
|
- lib/sinatra_warden/sinatra.rb
|
142
70
|
- sinatra_warden.gemspec
|
143
|
-
- spec/fixtures/
|
71
|
+
- spec/fixtures/basic_strategy.rb
|
144
72
|
- spec/fixtures/testing_login.rb
|
145
73
|
- spec/fixtures/user.rb
|
74
|
+
- spec/fixtures/views/login.haml
|
146
75
|
- spec/sinatra_warden_spec.rb
|
147
76
|
- spec/spec.opts
|
148
77
|
- spec/spec_helper.rb
|
@@ -175,7 +104,7 @@ signing_key:
|
|
175
104
|
specification_version: 3
|
176
105
|
summary: authentication system for using warden with sinatra
|
177
106
|
test_files:
|
178
|
-
- spec/fixtures/
|
107
|
+
- spec/fixtures/basic_strategy.rb
|
179
108
|
- spec/fixtures/testing_login.rb
|
180
109
|
- spec/fixtures/user.rb
|
181
110
|
- spec/sinatra_warden_spec.rb
|