sorcery 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sorcery might be problematic. Click here for more details.
- data/README.rdoc +89 -59
- data/VERSION +1 -1
- data/lib/generators/sorcery_migration/sorcery_migration_generator.rb +24 -0
- data/lib/generators/sorcery_migration/templates/activity_logging.rb +17 -0
- data/lib/generators/sorcery_migration/templates/brute_force_protection.rb +11 -0
- data/lib/generators/sorcery_migration/templates/core.rb +16 -0
- data/lib/generators/sorcery_migration/templates/oauth.rb +14 -0
- data/lib/generators/sorcery_migration/templates/remember_me.rb +15 -0
- data/lib/generators/sorcery_migration/templates/reset_password.rb +13 -0
- data/lib/generators/sorcery_migration/templates/user_activation.rb +17 -0
- data/lib/sorcery.rb +8 -0
- data/lib/sorcery/controller/adapters/sinatra.rb +97 -0
- data/lib/sorcery/controller/submodules/http_basic_auth.rb +10 -6
- data/lib/sorcery/controller/submodules/oauth.rb +6 -3
- data/lib/sorcery/controller/submodules/oauth/oauth1.rb +11 -4
- data/lib/sorcery/controller/submodules/oauth/oauth2.rb +1 -1
- data/lib/sorcery/model/submodules/activity_logging.rb +1 -1
- data/lib/sorcery/model/submodules/brute_force_protection.rb +0 -4
- data/lib/sorcery/sinatra.rb +14 -0
- data/lib/sorcery/test_helpers.rb +8 -52
- data/lib/sorcery/test_helpers/rails.rb +57 -0
- data/lib/sorcery/test_helpers/sinatra.rb +131 -0
- data/sorcery.gemspec +77 -3
- data/spec/Gemfile +1 -1
- data/spec/Gemfile.lock +2 -2
- data/spec/rails3/app_root/Gemfile +2 -4
- data/spec/rails3/app_root/Gemfile.lock +2 -5
- data/spec/rails3/app_root/spec/controller_oauth2_spec.rb +2 -0
- data/spec/rails3/app_root/spec/controller_oauth_spec.rb +6 -1
- data/spec/rails3/app_root/spec/controller_session_timeout_spec.rb +2 -2
- data/spec/rails3/app_root/spec/spec_helper.rb +1 -0
- data/spec/sinatra/Gemfile +12 -0
- data/spec/sinatra/Gemfile.lock +134 -0
- data/spec/sinatra/Rakefile +10 -0
- data/spec/sinatra/authentication.rb +3 -0
- data/spec/sinatra/db/migrate/activation/20101224223622_add_activation_to_users.rb +17 -0
- data/spec/sinatra/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +17 -0
- data/spec/sinatra/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +11 -0
- data/spec/sinatra/db/migrate/core/20101224223620_create_users.rb +16 -0
- data/spec/sinatra/db/migrate/oauth/20101224223628_create_authentications.rb +14 -0
- data/spec/sinatra/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb +15 -0
- data/spec/sinatra/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb +13 -0
- data/spec/sinatra/filters.rb +21 -0
- data/spec/sinatra/myapp.rb +133 -0
- data/spec/sinatra/sorcery_mailer.rb +25 -0
- data/spec/sinatra/spec/controller_activity_logging_spec.rb +85 -0
- data/spec/sinatra/spec/controller_brute_force_protection_spec.rb +69 -0
- data/spec/sinatra/spec/controller_http_basic_auth_spec.rb +53 -0
- data/spec/sinatra/spec/controller_oauth2_spec.rb +119 -0
- data/spec/sinatra/spec/controller_oauth_spec.rb +121 -0
- data/spec/sinatra/spec/controller_remember_me_spec.rb +64 -0
- data/spec/sinatra/spec/controller_session_timeout_spec.rb +52 -0
- data/spec/sinatra/spec/controller_spec.rb +120 -0
- data/spec/sinatra/spec/spec.opts +4 -0
- data/spec/sinatra/spec/spec_helper.rb +44 -0
- data/spec/sinatra/spec/user_activation_spec.rb +188 -0
- data/spec/sinatra/spec/user_activity_logging_spec.rb +36 -0
- data/spec/sinatra/spec/user_brute_force_protection_spec.rb +76 -0
- data/spec/sinatra/spec/user_oauth_spec.rb +39 -0
- data/spec/sinatra/spec/user_remember_me_spec.rb +66 -0
- data/spec/sinatra/spec/user_reset_password_spec.rb +178 -0
- data/spec/sinatra/spec/user_spec.rb +317 -0
- data/spec/sinatra/user.rb +6 -0
- data/spec/sinatra/views/test_login.erb +4 -0
- data/spec/untitled folder +18 -0
- metadata +76 -2
data/spec/Gemfile
CHANGED
data/spec/Gemfile.lock
CHANGED
@@ -2,10 +2,8 @@ source 'http://rubygems.org'
|
|
2
2
|
|
3
3
|
gem 'rails', '3.0.3'
|
4
4
|
gem 'sqlite3-ruby', :require => 'sqlite3'
|
5
|
-
gem "sorcery", '0.
|
6
|
-
|
7
|
-
gem 'oauth', ">= 0.4.4"
|
8
|
-
gem 'oauth2', ">= 0.1.1"
|
5
|
+
gem "sorcery", '0.3.0', :path => '../../../'
|
6
|
+
|
9
7
|
group :development, :test do
|
10
8
|
gem 'rspec'
|
11
9
|
gem 'rspec-rails'
|
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ../../../
|
3
3
|
specs:
|
4
|
-
sorcery (0.
|
4
|
+
sorcery (0.3.0)
|
5
5
|
bcrypt-ruby (~> 2.1.4)
|
6
6
|
json (>= 1.5.1)
|
7
7
|
oauth (>= 0.4.4)
|
@@ -126,14 +126,11 @@ PLATFORMS
|
|
126
126
|
ruby
|
127
127
|
|
128
128
|
DEPENDENCIES
|
129
|
-
bcrypt-ruby (~> 2.1.4)
|
130
|
-
oauth (>= 0.4.4)
|
131
|
-
oauth2 (>= 0.1.1)
|
132
129
|
rails (= 3.0.3)
|
133
130
|
rspec
|
134
131
|
rspec-rails
|
135
132
|
ruby-debug19
|
136
133
|
simplecov (>= 0.3.8)
|
137
|
-
sorcery (= 0.
|
134
|
+
sorcery (= 0.3.0)!
|
138
135
|
spork (~> 0.9.0.rc)
|
139
136
|
sqlite3-ruby
|
@@ -32,6 +32,7 @@ describe ApplicationController do
|
|
32
32
|
|
33
33
|
after(:each) do
|
34
34
|
User.delete_all
|
35
|
+
Authentication.delete_all
|
35
36
|
end
|
36
37
|
|
37
38
|
it "auth_at_provider redirects correctly" do
|
@@ -60,6 +61,7 @@ describe ApplicationController do
|
|
60
61
|
before(:each) do
|
61
62
|
stub_all_oauth2_requests!
|
62
63
|
User.delete_all
|
64
|
+
Authentication.delete_all
|
63
65
|
end
|
64
66
|
|
65
67
|
it "should create a new user" do
|
@@ -9,7 +9,9 @@ def stub_all_oauth_requests!
|
|
9
9
|
@consumer.stub!(:get_request_token).and_return(@req_token)
|
10
10
|
@acc_token = OAuth::AccessToken.new(@consumer)
|
11
11
|
@req_token.stub!(:get_access_token).and_return(@acc_token)
|
12
|
-
session[:request_token] = @req_token
|
12
|
+
session[:request_token] = @req_token.token
|
13
|
+
session[:request_token_secret] = @req_token.secret
|
14
|
+
OAuth::RequestToken.stub!(:new).and_return(@req_token)
|
13
15
|
response = OpenStruct.new()
|
14
16
|
response.body = {"following"=>false, "listed_count"=>0, "profile_link_color"=>"0084B4", "profile_image_url"=>"http://a1.twimg.com/profile_images/536178575/noamb_normal.jpg", "description"=>"Programmer/Heavy Metal Fan/New Father", "status"=>{"text"=>"coming soon to sorcery gem: twitter and facebook authentication support.", "truncated"=>false, "favorited"=>false, "source"=>"web", "geo"=>nil, "in_reply_to_screen_name"=>nil, "in_reply_to_user_id"=>nil, "in_reply_to_status_id_str"=>nil, "created_at"=>"Sun Mar 06 23:01:12 +0000 2011", "contributors"=>nil, "place"=>nil, "retweeted"=>false, "in_reply_to_status_id"=>nil, "in_reply_to_user_id_str"=>nil, "coordinates"=>nil, "retweet_count"=>0, "id"=>44533012284706816, "id_str"=>"44533012284706816"}, "show_all_inline_media"=>false, "geo_enabled"=>true, "profile_sidebar_border_color"=>"a8c7f7", "url"=>nil, "followers_count"=>10, "screen_name"=>"nbenari", "profile_use_background_image"=>true, "location"=>"Israel", "statuses_count"=>25, "profile_background_color"=>"022330", "lang"=>"en", "verified"=>false, "notifications"=>false, "profile_background_image_url"=>"http://a3.twimg.com/profile_background_images/104087198/04042010339.jpg", "favourites_count"=>5, "created_at"=>"Fri Nov 20 21:58:19 +0000 2009", "is_translator"=>false, "contributors_enabled"=>false, "protected"=>false, "follow_request_sent"=>false, "time_zone"=>"Greenland", "profile_text_color"=>"333333", "name"=>"Noam Ben Ari", "friends_count"=>10, "profile_sidebar_fill_color"=>"C0DFEC", "id"=>123, "id_str"=>"91434812", "profile_background_tile"=>false, "utc_offset"=>-10800}.to_json
|
15
17
|
@acc_token.stub!(:get).and_return(response)
|
@@ -37,6 +39,7 @@ describe ApplicationController do
|
|
37
39
|
|
38
40
|
after(:each) do
|
39
41
|
User.delete_all
|
42
|
+
Authentication.delete_all
|
40
43
|
end
|
41
44
|
|
42
45
|
it "auth_at_provider redirects correctly" do
|
@@ -65,6 +68,7 @@ describe ApplicationController do
|
|
65
68
|
before(:each) do
|
66
69
|
stub_all_oauth_requests!
|
67
70
|
User.delete_all
|
71
|
+
Authentication.delete_all
|
68
72
|
end
|
69
73
|
|
70
74
|
it "should create a new user" do
|
@@ -98,6 +102,7 @@ describe ApplicationController do
|
|
98
102
|
|
99
103
|
after(:each) do
|
100
104
|
User.delete_all
|
105
|
+
Authentication.delete_all
|
101
106
|
end
|
102
107
|
|
103
108
|
it "should not send activation email to external users" do
|
@@ -27,7 +27,7 @@ describe ApplicationController do
|
|
27
27
|
|
28
28
|
it "with 'session_timeout_from_last_action' should not logout if there was activity" do
|
29
29
|
sorcery_controller_property_set(:session_timeout_from_last_action, true)
|
30
|
-
|
30
|
+
get :test_login, :username => 'gizmo', :password => 'secret'
|
31
31
|
sleep 0.3
|
32
32
|
get :test_should_be_logged_in
|
33
33
|
session[:user_id].should_not be_nil
|
@@ -39,7 +39,7 @@ describe ApplicationController do
|
|
39
39
|
|
40
40
|
it "with 'session_timeout_from_last_action' should logout if there was no activity" do
|
41
41
|
sorcery_controller_property_set(:session_timeout_from_last_action, true)
|
42
|
-
|
42
|
+
get :test_login, :username => 'gizmo', :password => 'secret'
|
43
43
|
sleep 0.6
|
44
44
|
get :test_should_be_logged_in
|
45
45
|
session[:user_id].should be_nil
|
@@ -0,0 +1,12 @@
|
|
1
|
+
source 'http://rubygems.org'
|
2
|
+
|
3
|
+
gem 'sinatra', '>= 1.2.0'
|
4
|
+
gem 'sqlite3-ruby', :require => 'sqlite3'
|
5
|
+
gem "sorcery", '0.3.0', :path => '../../'
|
6
|
+
|
7
|
+
group :development, :test do
|
8
|
+
gem 'rspec'
|
9
|
+
gem 'ruby-debug19'
|
10
|
+
gem 'simplecov', '>= 0.3.8', :require => false # Will install simplecov-html as a dependency
|
11
|
+
gem 'spork', '~> 0.9.0.rc'
|
12
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ../../
|
3
|
+
specs:
|
4
|
+
sorcery (0.3.0)
|
5
|
+
bcrypt-ruby (~> 2.1.4)
|
6
|
+
json (>= 1.5.1)
|
7
|
+
oauth (>= 0.4.4)
|
8
|
+
oauth (>= 0.4.4)
|
9
|
+
oauth2 (>= 0.1.1)
|
10
|
+
oauth2 (>= 0.1.1)
|
11
|
+
rails (>= 3.0.0)
|
12
|
+
|
13
|
+
GEM
|
14
|
+
remote: http://rubygems.org/
|
15
|
+
specs:
|
16
|
+
abstract (1.0.0)
|
17
|
+
actionmailer (3.0.3)
|
18
|
+
actionpack (= 3.0.3)
|
19
|
+
mail (~> 2.2.9)
|
20
|
+
actionpack (3.0.3)
|
21
|
+
activemodel (= 3.0.3)
|
22
|
+
activesupport (= 3.0.3)
|
23
|
+
builder (~> 2.1.2)
|
24
|
+
erubis (~> 2.6.6)
|
25
|
+
i18n (~> 0.4)
|
26
|
+
rack (~> 1.2.1)
|
27
|
+
rack-mount (~> 0.6.13)
|
28
|
+
rack-test (~> 0.5.6)
|
29
|
+
tzinfo (~> 0.3.23)
|
30
|
+
activemodel (3.0.3)
|
31
|
+
activesupport (= 3.0.3)
|
32
|
+
builder (~> 2.1.2)
|
33
|
+
i18n (~> 0.4)
|
34
|
+
activerecord (3.0.3)
|
35
|
+
activemodel (= 3.0.3)
|
36
|
+
activesupport (= 3.0.3)
|
37
|
+
arel (~> 2.0.2)
|
38
|
+
tzinfo (~> 0.3.23)
|
39
|
+
activeresource (3.0.3)
|
40
|
+
activemodel (= 3.0.3)
|
41
|
+
activesupport (= 3.0.3)
|
42
|
+
activesupport (3.0.3)
|
43
|
+
addressable (2.2.4)
|
44
|
+
archive-tar-minitar (0.5.2)
|
45
|
+
arel (2.0.7)
|
46
|
+
bcrypt-ruby (2.1.4)
|
47
|
+
builder (2.1.2)
|
48
|
+
columnize (0.3.2)
|
49
|
+
diff-lcs (1.1.2)
|
50
|
+
erubis (2.6.6)
|
51
|
+
abstract (>= 1.0.0)
|
52
|
+
faraday (0.5.5)
|
53
|
+
addressable (~> 2.2.4)
|
54
|
+
multipart-post (~> 1.1.0)
|
55
|
+
rack (< 2, >= 1.1.0)
|
56
|
+
i18n (0.5.0)
|
57
|
+
json (1.5.1)
|
58
|
+
linecache19 (0.5.11)
|
59
|
+
ruby_core_source (>= 0.1.4)
|
60
|
+
mail (2.2.15)
|
61
|
+
activesupport (>= 2.3.6)
|
62
|
+
i18n (>= 0.4.0)
|
63
|
+
mime-types (~> 1.16)
|
64
|
+
treetop (~> 1.4.8)
|
65
|
+
mime-types (1.16)
|
66
|
+
multi_json (0.0.5)
|
67
|
+
multipart-post (1.1.0)
|
68
|
+
oauth (0.4.4)
|
69
|
+
oauth2 (0.1.1)
|
70
|
+
faraday (~> 0.5.0)
|
71
|
+
multi_json (~> 0.0.4)
|
72
|
+
polyglot (0.3.1)
|
73
|
+
rack (1.2.1)
|
74
|
+
rack-mount (0.6.13)
|
75
|
+
rack (>= 1.0.0)
|
76
|
+
rack-test (0.5.7)
|
77
|
+
rack (>= 1.0)
|
78
|
+
rails (3.0.3)
|
79
|
+
actionmailer (= 3.0.3)
|
80
|
+
actionpack (= 3.0.3)
|
81
|
+
activerecord (= 3.0.3)
|
82
|
+
activeresource (= 3.0.3)
|
83
|
+
activesupport (= 3.0.3)
|
84
|
+
bundler (~> 1.0)
|
85
|
+
railties (= 3.0.3)
|
86
|
+
railties (3.0.3)
|
87
|
+
actionpack (= 3.0.3)
|
88
|
+
activesupport (= 3.0.3)
|
89
|
+
rake (>= 0.8.7)
|
90
|
+
thor (~> 0.14.4)
|
91
|
+
rake (0.8.7)
|
92
|
+
rspec (2.4.0)
|
93
|
+
rspec-core (~> 2.4.0)
|
94
|
+
rspec-expectations (~> 2.4.0)
|
95
|
+
rspec-mocks (~> 2.4.0)
|
96
|
+
rspec-core (2.4.0)
|
97
|
+
rspec-expectations (2.4.0)
|
98
|
+
diff-lcs (~> 1.1.2)
|
99
|
+
rspec-mocks (2.4.0)
|
100
|
+
ruby-debug-base19 (0.11.24)
|
101
|
+
columnize (>= 0.3.1)
|
102
|
+
linecache19 (>= 0.5.11)
|
103
|
+
ruby_core_source (>= 0.1.4)
|
104
|
+
ruby-debug19 (0.11.6)
|
105
|
+
columnize (>= 0.3.1)
|
106
|
+
linecache19 (>= 0.5.11)
|
107
|
+
ruby-debug-base19 (>= 0.11.19)
|
108
|
+
ruby_core_source (0.1.4)
|
109
|
+
archive-tar-minitar (>= 0.5.2)
|
110
|
+
simplecov (0.3.9)
|
111
|
+
simplecov-html (>= 0.3.7)
|
112
|
+
simplecov-html (0.3.9)
|
113
|
+
sinatra (1.2.0)
|
114
|
+
rack (~> 1.1)
|
115
|
+
tilt (< 2.0, >= 1.2.2)
|
116
|
+
spork (0.9.0.rc3)
|
117
|
+
sqlite3-ruby (1.3.2)
|
118
|
+
thor (0.14.6)
|
119
|
+
tilt (1.2.2)
|
120
|
+
treetop (1.4.9)
|
121
|
+
polyglot (>= 0.3.1)
|
122
|
+
tzinfo (0.3.24)
|
123
|
+
|
124
|
+
PLATFORMS
|
125
|
+
ruby
|
126
|
+
|
127
|
+
DEPENDENCIES
|
128
|
+
rspec
|
129
|
+
ruby-debug19
|
130
|
+
simplecov (>= 0.3.8)
|
131
|
+
sinatra (>= 1.2.0)
|
132
|
+
sorcery (= 0.3.0)!
|
133
|
+
spork (~> 0.9.0.rc)
|
134
|
+
sqlite3-ruby
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class AddActivationToUsers < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
add_column :users, :activation_state, :string, :default => nil
|
4
|
+
add_column :users, :activation_token, :string, :default => nil
|
5
|
+
add_column :users, :activation_token_expires_at, :datetime, :default => nil
|
6
|
+
|
7
|
+
add_index :users, :activation_token
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.down
|
11
|
+
remove_index :users, :activation_token
|
12
|
+
|
13
|
+
remove_column :users, :activation_token_expires_at
|
14
|
+
remove_column :users, :activation_token
|
15
|
+
remove_column :users, :activation_state
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class AddActivityLoggingToUsers < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
add_column :users, :last_login_at, :datetime, :default => nil
|
4
|
+
add_column :users, :last_logout_at, :datetime, :default => nil
|
5
|
+
add_column :users, :last_activity_at, :datetime, :default => nil
|
6
|
+
|
7
|
+
add_index :users, [:last_logout_at, :last_activity_at]
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.down
|
11
|
+
remove_index :users, [:last_logout_at, :last_activity_at]
|
12
|
+
|
13
|
+
remove_column :users, :last_activity_at
|
14
|
+
remove_column :users, :last_logout_at
|
15
|
+
remove_column :users, :last_login_at
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class AddBruteForceProtectionToUsers < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
add_column :users, :failed_logins_count, :integer, :default => 0
|
4
|
+
add_column :users, :lock_expires_at, :datetime, :default => nil
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.down
|
8
|
+
remove_column :users, :lock_expires_at
|
9
|
+
remove_column :users, :failed_logins_count
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class CreateUsers < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :users do |t|
|
4
|
+
t.string :username, :null => false
|
5
|
+
t.string :email, :default => nil
|
6
|
+
t.string :crypted_password, :default => nil
|
7
|
+
t.string :salt, :default => nil
|
8
|
+
|
9
|
+
t.timestamps
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.down
|
14
|
+
drop_table :users
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class CreateAuthentications < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :authentications do |t|
|
4
|
+
t.integer :user_id, :null => false
|
5
|
+
t.string :provider, :uid, :null => false
|
6
|
+
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.down
|
12
|
+
drop_table :authentications
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class AddRememberMeTokenToUsers < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
add_column :users, :remember_me_token, :string, :default => nil
|
4
|
+
add_column :users, :remember_me_token_expires_at, :datetime, :default => nil
|
5
|
+
|
6
|
+
add_index :users, :remember_me_token
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.down
|
10
|
+
remove_index :users, :remember_me_token
|
11
|
+
|
12
|
+
remove_column :users, :remember_me_token_expires_at
|
13
|
+
remove_column :users, :remember_me_token
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class AddResetPasswordToUsers < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
add_column :users, :reset_password_token, :string, :default => nil
|
4
|
+
add_column :users, :reset_password_token_expires_at, :datetime, :default => nil
|
5
|
+
add_column :users, :reset_password_email_sent_at, :datetime, :default => nil
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.down
|
9
|
+
remove_column :users, :reset_password_email_sent_at
|
10
|
+
remove_column :users, :reset_password_token_expires_at
|
11
|
+
remove_column :users, :reset_password_token
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# --- before filters
|
2
|
+
|
3
|
+
['/test_logout','/some_action','/test_should_be_logged_in'].each do |patt|
|
4
|
+
before patt do
|
5
|
+
require_login
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
before '/test_http_basic_auth' do
|
10
|
+
require_login_from_http_basic
|
11
|
+
end
|
12
|
+
|
13
|
+
# ----- test filters
|
14
|
+
|
15
|
+
before do
|
16
|
+
self.class.sorcery_vars = {}
|
17
|
+
end
|
18
|
+
|
19
|
+
after do
|
20
|
+
save_instance_vars
|
21
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require 'sinatra'
|
2
|
+
enable :sessions
|
3
|
+
|
4
|
+
require 'sqlite3'
|
5
|
+
require 'active_record'
|
6
|
+
|
7
|
+
# establish connection
|
8
|
+
ActiveRecord::Base.establish_connection(
|
9
|
+
:adapter => "sqlite3",
|
10
|
+
:database => ":memory:",
|
11
|
+
:verbosity => "quiet"
|
12
|
+
)
|
13
|
+
|
14
|
+
require 'action_mailer'
|
15
|
+
ActionMailer::Base.delivery_method = :test
|
16
|
+
require File.join(File.dirname(__FILE__),'sorcery_mailer')
|
17
|
+
|
18
|
+
# models
|
19
|
+
require File.join(File.dirname(__FILE__),'user')
|
20
|
+
require 'sorcery'
|
21
|
+
|
22
|
+
APP_ROOT = File.dirname(__FILE__)
|
23
|
+
|
24
|
+
require File.join(File.dirname(__FILE__),'filters')
|
25
|
+
|
26
|
+
get '/' do
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
get '/test_login' do
|
31
|
+
@user = login(params[:username],params[:password])
|
32
|
+
@current_user = current_user
|
33
|
+
@logged_in = logged_in?
|
34
|
+
erb :test_login
|
35
|
+
end
|
36
|
+
|
37
|
+
get '/test_logout' do
|
38
|
+
session[:user_id] = User.first.id
|
39
|
+
logout
|
40
|
+
@current_user = current_user
|
41
|
+
@logged_in = logged_in?
|
42
|
+
end
|
43
|
+
|
44
|
+
get '/test_current_user' do
|
45
|
+
session[:user_id] = params[:id]
|
46
|
+
current_user
|
47
|
+
end
|
48
|
+
|
49
|
+
get '/some_action' do
|
50
|
+
erb ''
|
51
|
+
end
|
52
|
+
|
53
|
+
post '/test_return_to' do
|
54
|
+
session[:return_to_url] = params[:return_to_url] if params[:return_to_url]
|
55
|
+
@user = login(params[:username], params[:password])
|
56
|
+
return_or_redirect_to(:some_action)
|
57
|
+
end
|
58
|
+
|
59
|
+
get '/test_should_be_logged_in' do
|
60
|
+
erb ''
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_not_authenticated_action
|
64
|
+
halt "test_not_authenticated_action"
|
65
|
+
end
|
66
|
+
|
67
|
+
def not_authenticated2
|
68
|
+
@session = session
|
69
|
+
save_instance_vars
|
70
|
+
redirect '/'
|
71
|
+
end
|
72
|
+
|
73
|
+
# remember me
|
74
|
+
|
75
|
+
post '/test_login_with_remember' do
|
76
|
+
@user = login(params[:username], params[:password])
|
77
|
+
remember_me!
|
78
|
+
erb ''
|
79
|
+
end
|
80
|
+
|
81
|
+
post '/test_login_with_remember_in_login' do
|
82
|
+
@user = login(params[:username], params[:password], params[:remember])
|
83
|
+
erb ''
|
84
|
+
end
|
85
|
+
|
86
|
+
get '/test_login_from_cookie' do
|
87
|
+
@user = current_user
|
88
|
+
erb ''
|
89
|
+
end
|
90
|
+
|
91
|
+
# http_basic
|
92
|
+
|
93
|
+
get '/test_http_basic_auth' do
|
94
|
+
erb "HTTP Basic Auth"
|
95
|
+
end
|
96
|
+
|
97
|
+
# oauth
|
98
|
+
|
99
|
+
get '/auth_at_provider_test' do
|
100
|
+
auth_at_provider(:twitter)
|
101
|
+
end
|
102
|
+
|
103
|
+
get '/test_login_from_access_token' do
|
104
|
+
if @user = login_from_access_token(:twitter)
|
105
|
+
erb "Success!"
|
106
|
+
else
|
107
|
+
erb "Failed!"
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# oauth2
|
112
|
+
|
113
|
+
get '/auth_at_provider_test2' do
|
114
|
+
auth_at_provider(:facebook)
|
115
|
+
end
|
116
|
+
|
117
|
+
get '/test_login_from_access_token2' do
|
118
|
+
if @user = login_from_access_token(:facebook)
|
119
|
+
erb "Success!"
|
120
|
+
else
|
121
|
+
erb "Failed!"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
get '/test_create_from_provider' do
|
126
|
+
provider = params[:provider]
|
127
|
+
login_from_access_token(provider)
|
128
|
+
if @user = create_from_provider!(provider)
|
129
|
+
erb "Success!"
|
130
|
+
else
|
131
|
+
erb "Failed!"
|
132
|
+
end
|
133
|
+
end
|