sorcery 0.5.1 → 0.5.2

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.

Files changed (49) hide show
  1. data/README.rdoc +1 -1
  2. data/VERSION +1 -1
  3. data/lib/sorcery.rb +3 -5
  4. data/lib/sorcery/controller/adapters/sinatra.rb +35 -28
  5. data/lib/sorcery/controller/submodules/http_basic_auth.rb +1 -1
  6. data/lib/sorcery/engine.rb +0 -7
  7. data/lib/sorcery/initializers/initializer.rb +4 -2
  8. data/lib/sorcery/model.rb +2 -3
  9. data/lib/sorcery/test_helpers/internal/rails.rb +1 -0
  10. data/lib/sorcery/test_helpers/internal/sinatra.rb +3 -3
  11. data/lib/sorcery/test_helpers/internal/sinatra_modular.rb +74 -0
  12. data/sorcery.gemspec +54 -2
  13. data/spec/Gemfile.lock +1 -1
  14. data/spec/rails3/Gemfile.lock +1 -1
  15. data/spec/rails3/spec/user_spec.rb +0 -10
  16. data/spec/rails3_mongoid/Gemfile.lock +1 -1
  17. data/spec/rails3_mongoid/spec/user_spec.rb +0 -10
  18. data/spec/sinatra/Gemfile.lock +1 -1
  19. data/spec/sinatra/Rakefile +1 -1
  20. data/spec/sinatra/filters.rb +20 -14
  21. data/spec/sinatra/modular.rb +157 -0
  22. data/spec/sinatra_modular/Gemfile +15 -0
  23. data/spec/sinatra_modular/Gemfile.lock +117 -0
  24. data/spec/sinatra_modular/Rakefile +11 -0
  25. data/spec/sinatra_modular/authentication.rb +3 -0
  26. data/spec/sinatra_modular/db/migrate/activation/20101224223622_add_activation_to_users.rb +17 -0
  27. data/spec/sinatra_modular/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +17 -0
  28. data/spec/sinatra_modular/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +11 -0
  29. data/spec/sinatra_modular/db/migrate/core/20101224223620_create_users.rb +16 -0
  30. data/spec/sinatra_modular/db/migrate/external/20101224223628_create_authentications.rb +14 -0
  31. data/spec/sinatra_modular/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb +15 -0
  32. data/spec/sinatra_modular/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb +13 -0
  33. data/spec/sinatra_modular/filters.rb +27 -0
  34. data/spec/sinatra_modular/modular.rb +157 -0
  35. data/spec/sinatra_modular/myapp.rb +133 -0
  36. data/spec/sinatra_modular/sorcery_mailer.rb +25 -0
  37. data/spec/sinatra_modular/spec_modular/controller_activity_logging_spec.rb +85 -0
  38. data/spec/sinatra_modular/spec_modular/controller_brute_force_protection_spec.rb +70 -0
  39. data/spec/sinatra_modular/spec_modular/controller_http_basic_auth_spec.rb +53 -0
  40. data/spec/sinatra_modular/spec_modular/controller_oauth2_spec.rb +120 -0
  41. data/spec/sinatra_modular/spec_modular/controller_oauth_spec.rb +121 -0
  42. data/spec/sinatra_modular/spec_modular/controller_remember_me_spec.rb +64 -0
  43. data/spec/sinatra_modular/spec_modular/controller_session_timeout_spec.rb +57 -0
  44. data/spec/sinatra_modular/spec_modular/controller_spec.rb +116 -0
  45. data/spec/sinatra_modular/spec_modular/spec.opts +2 -0
  46. data/spec/sinatra_modular/spec_modular/spec_helper.rb +51 -0
  47. data/spec/sinatra_modular/user.rb +6 -0
  48. data/spec/sinatra_modular/views/test_login.erb +4 -0
  49. metadata +54 -2
@@ -2,7 +2,7 @@ PATH
2
2
  remote: ../../../
3
3
  specs:
4
4
  oauth (0.4.4)
5
- sorcery (0.5.0)
5
+ sorcery (0.5.2)
6
6
  bcrypt-ruby (~> 2.1.4)
7
7
  oauth (>= 0.4.4)
8
8
  oauth (>= 0.4.4)
@@ -11,16 +11,6 @@ describe "User with no submodules (core)" do
11
11
  User.should respond_to(:authenticates_with_sorcery!)
12
12
  end
13
13
  end
14
-
15
- # ----------------- PLUGIN ACTIVATION -----------------------
16
- describe TestUser, "Testing activated class self-registration" do
17
- it "should register itself as user_class if activated" do
18
- TestUser.class_eval do
19
- authenticates_with_sorcery!
20
- end
21
- ::Sorcery::Controller::Config.user_class.should == TestUser
22
- end
23
- end
24
14
 
25
15
  # ----------------- PLUGIN CONFIGURATION -----------------------
26
16
  describe User, "loaded plugin configuration" do
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../../
3
3
  specs:
4
- sorcery (0.5.0)
4
+ sorcery (0.5.2)
5
5
  bcrypt-ruby (~> 2.1.4)
6
6
  oauth (>= 0.4.4)
7
7
  oauth (>= 0.4.4)
@@ -6,6 +6,6 @@ task :default => :spec
6
6
 
7
7
  desc "Run all specs"
8
8
  RSpec::Core::RakeTask.new(:spec) do |t|
9
- t.pattern = '**/*_spec.rb'
9
+ t.pattern = 'spec/*_spec.rb'
10
10
  t.rspec_opts = ["--options #{File.dirname(__FILE__)}/spec/spec.opts"]
11
11
  end
@@ -1,21 +1,27 @@
1
1
  # --- before filters
2
+ module Filters
2
3
 
3
- ['/test_logout','/some_action','/test_should_be_logged_in'].each do |patt|
4
- before patt do
5
- require_login
6
- end
7
- end
4
+ def self.included(klass)
5
+ klass.class_eval do
6
+ ['/test_logout', '/some_action', '/test_should_be_logged_in'].each do |pattern|
7
+ before pattern do
8
+ require_login
9
+ end
10
+ end
8
11
 
9
- before '/test_http_basic_auth' do
10
- require_login_from_http_basic
11
- end
12
+ before '/test_http_basic_auth' do
13
+ require_login_from_http_basic
14
+ end
12
15
 
13
- # ----- test filters
16
+ # ----- test filters
14
17
 
15
- before do
16
- self.class.sorcery_vars = {}
17
- end
18
+ before do
19
+ self.class.sorcery_vars = {}
20
+ end
18
21
 
19
- after do
20
- save_instance_vars
22
+ after do
23
+ save_instance_vars
24
+ end
25
+ end
26
+ end
21
27
  end
@@ -0,0 +1,157 @@
1
+ require 'sinatra/base'
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
+ class Modular < Sinatra::Base
25
+ set :sessions, true
26
+
27
+ # ['/test_logout', '/some_action', '/test_should_be_logged_in'].each do |patt|
28
+ # before patt do
29
+ # require_login
30
+ # end
31
+ # end
32
+ #
33
+ # before '/test_http_basic_auth' do
34
+ # require_login_from_http_basic
35
+ # end
36
+ #
37
+ ## ----- test filters
38
+ #
39
+ # before do
40
+ # self.class.sorcery_vars = {}
41
+ # end
42
+ #
43
+ # after do
44
+ # save_instance_vars
45
+ # end
46
+
47
+ get '/' do
48
+
49
+ end
50
+
51
+ get '/test_login' do
52
+ @user = login(params[:username], params[:password])
53
+ @current_user = current_user
54
+ @logged_in = logged_in?
55
+ erb :test_login
56
+ end
57
+
58
+ get '/test_logout' do
59
+ session[:user_id] = User.first.id
60
+ logout
61
+ @current_user = current_user
62
+ @logged_in = logged_in?
63
+ end
64
+
65
+ get '/test_current_user' do
66
+ session[:user_id] = params[:id]
67
+ current_user
68
+ end
69
+
70
+ get '/some_action' do
71
+ erb ''
72
+ end
73
+
74
+ post '/test_return_to' do
75
+ session[:return_to_url] = params[:return_to_url] if params[:return_to_url]
76
+ @user = login(params[:username], params[:password])
77
+ redirect_back_or_to(:some_action)
78
+ end
79
+
80
+ get '/test_should_be_logged_in' do
81
+ erb ''
82
+ end
83
+
84
+ def test_not_authenticated_action
85
+ halt "test_not_authenticated_action"
86
+ end
87
+
88
+ def not_authenticated2
89
+ @session = session
90
+ save_instance_vars
91
+ redirect '/'
92
+ end
93
+
94
+ # remember me
95
+
96
+ post '/test_login_with_remember' do
97
+ @user = login(params[:username], params[:password])
98
+ remember_me!
99
+ erb ''
100
+ end
101
+
102
+ post '/test_login_with_remember_in_login' do
103
+ @user = login(params[:username], params[:password], params[:remember])
104
+ erb ''
105
+ end
106
+
107
+ get '/test_login_from_cookie' do
108
+ @user = current_user
109
+ erb ''
110
+ end
111
+
112
+ # http_basic
113
+
114
+ get '/test_http_basic_auth' do
115
+ erb "HTTP Basic Auth"
116
+ end
117
+
118
+ # oauth
119
+
120
+ get '/login_at_test' do
121
+ login_at(:twitter)
122
+ end
123
+
124
+ get '/test_login_from' do
125
+ if @user = login_from(:twitter)
126
+ erb "Success!"
127
+ else
128
+ erb "Failed!"
129
+ end
130
+ end
131
+
132
+ # oauth2
133
+
134
+ get '/login_at_test2' do
135
+ login_at(:facebook)
136
+ end
137
+
138
+ get '/test_login_from2' do
139
+ if @user = login_from(:facebook)
140
+ erb "Success!"
141
+ else
142
+ erb "Failed!"
143
+ end
144
+ end
145
+
146
+ get '/test_create_from_provider' do
147
+ provider = params[:provider]
148
+ login_from(provider)
149
+ if @user = create_from(provider)
150
+ erb "Success!"
151
+ else
152
+ erb "Failed!"
153
+ end
154
+ end
155
+
156
+ #run! if app_file == $2
157
+ end
@@ -0,0 +1,15 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'sinatra', '>= 1.2.0'
4
+ gem 'sqlite3-ruby', :require => 'sqlite3'
5
+ gem 'activerecord', '>= 3.0.3'
6
+ gem 'actionmailer', '>= 3.0.3'
7
+ gem "sorcery", '>= 0.1.0', :path => '../../'
8
+
9
+ group :development, :test do
10
+ gem "rake"
11
+ gem "rspec", "~> 2.5.0"
12
+ gem 'ruby-debug19'
13
+ gem 'simplecov', '>= 0.3.8', :require => false # Will install simplecov-html as a dependency
14
+ gem 'timecop'
15
+ end
@@ -0,0 +1,117 @@
1
+ PATH
2
+ remote: ../../
3
+ specs:
4
+ sorcery (0.5.2)
5
+ bcrypt-ruby (~> 2.1.4)
6
+ oauth (>= 0.4.4)
7
+ oauth (>= 0.4.4)
8
+ oauth2 (>= 0.1.1)
9
+ oauth2 (>= 0.1.1)
10
+
11
+ GEM
12
+ remote: http://rubygems.org/
13
+ specs:
14
+ abstract (1.0.0)
15
+ actionmailer (3.0.5)
16
+ actionpack (= 3.0.5)
17
+ mail (~> 2.2.15)
18
+ actionpack (3.0.5)
19
+ activemodel (= 3.0.5)
20
+ activesupport (= 3.0.5)
21
+ builder (~> 2.1.2)
22
+ erubis (~> 2.6.6)
23
+ i18n (~> 0.4)
24
+ rack (~> 1.2.1)
25
+ rack-mount (~> 0.6.13)
26
+ rack-test (~> 0.5.7)
27
+ tzinfo (~> 0.3.23)
28
+ activemodel (3.0.5)
29
+ activesupport (= 3.0.5)
30
+ builder (~> 2.1.2)
31
+ i18n (~> 0.4)
32
+ activerecord (3.0.5)
33
+ activemodel (= 3.0.5)
34
+ activesupport (= 3.0.5)
35
+ arel (~> 2.0.2)
36
+ tzinfo (~> 0.3.23)
37
+ activesupport (3.0.5)
38
+ addressable (2.2.5)
39
+ archive-tar-minitar (0.5.2)
40
+ arel (2.0.7)
41
+ bcrypt-ruby (2.1.4)
42
+ builder (2.1.2)
43
+ columnize (0.3.2)
44
+ diff-lcs (1.1.2)
45
+ erubis (2.6.6)
46
+ abstract (>= 1.0.0)
47
+ faraday (0.6.1)
48
+ addressable (~> 2.2.4)
49
+ multipart-post (~> 1.1.0)
50
+ rack (< 2, >= 1.1.0)
51
+ i18n (0.5.0)
52
+ linecache19 (0.5.11)
53
+ ruby_core_source (>= 0.1.4)
54
+ mail (2.2.15)
55
+ activesupport (>= 2.3.6)
56
+ i18n (>= 0.4.0)
57
+ mime-types (~> 1.16)
58
+ treetop (~> 1.4.8)
59
+ mime-types (1.16)
60
+ multi_json (1.0.1)
61
+ multipart-post (1.1.0)
62
+ oauth (0.4.4)
63
+ oauth2 (0.4.1)
64
+ faraday (~> 0.6.1)
65
+ multi_json (>= 0.0.5)
66
+ polyglot (0.3.1)
67
+ rack (1.2.1)
68
+ rack-mount (0.6.14)
69
+ rack (>= 1.0.0)
70
+ rack-test (0.5.7)
71
+ rack (>= 1.0)
72
+ rake (0.8.7)
73
+ rspec (2.5.0)
74
+ rspec-core (~> 2.5.0)
75
+ rspec-expectations (~> 2.5.0)
76
+ rspec-mocks (~> 2.5.0)
77
+ rspec-core (2.5.1)
78
+ rspec-expectations (2.5.0)
79
+ diff-lcs (~> 1.1.2)
80
+ rspec-mocks (2.5.0)
81
+ ruby-debug-base19 (0.11.24)
82
+ columnize (>= 0.3.1)
83
+ linecache19 (>= 0.5.11)
84
+ ruby_core_source (>= 0.1.4)
85
+ ruby-debug19 (0.11.6)
86
+ columnize (>= 0.3.1)
87
+ linecache19 (>= 0.5.11)
88
+ ruby-debug-base19 (>= 0.11.19)
89
+ ruby_core_source (0.1.4)
90
+ archive-tar-minitar (>= 0.5.2)
91
+ simplecov (0.3.9)
92
+ simplecov-html (>= 0.3.7)
93
+ simplecov-html (0.3.9)
94
+ sinatra (1.2.0)
95
+ rack (~> 1.1)
96
+ tilt (< 2.0, >= 1.2.2)
97
+ sqlite3-ruby (1.3.2)
98
+ tilt (1.2.2)
99
+ timecop (0.3.5)
100
+ treetop (1.4.9)
101
+ polyglot (>= 0.3.1)
102
+ tzinfo (0.3.24)
103
+
104
+ PLATFORMS
105
+ ruby
106
+
107
+ DEPENDENCIES
108
+ actionmailer (>= 3.0.3)
109
+ activerecord (>= 3.0.3)
110
+ rake
111
+ rspec (~> 2.5.0)
112
+ ruby-debug19
113
+ simplecov (>= 0.3.8)
114
+ sinatra (>= 1.2.0)
115
+ sorcery (>= 0.1.0)!
116
+ sqlite3-ruby
117
+ timecop
@@ -0,0 +1,11 @@
1
+ require 'rake'
2
+ require 'rspec/core/rake_task'
3
+
4
+ desc 'Default: Run all specs.'
5
+ task :default => :spec
6
+
7
+ desc "Run all specs"
8
+ RSpec::Core::RakeTask.new(:spec) do |t|
9
+ t.pattern = 'spec_modular/*_spec.rb'
10
+ t.rspec_opts = ["--options #{File.dirname(__FILE__)}/spec_modular/spec.opts"]
11
+ end
@@ -0,0 +1,3 @@
1
+ class Authentication < ActiveRecord::Base
2
+ belongs_to :user
3
+ end
@@ -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