sorcery 0.3.0 → 0.4.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/Gemfile +3 -2
- data/Gemfile.lock +13 -11
- data/README.rdoc +99 -33
- data/Rakefile +4 -4
- data/VERSION +1 -1
- data/lib/generators/sorcery_migration/templates/core.rb +2 -2
- data/lib/generators/sorcery_migration/templates/{oauth.rb → external.rb} +1 -1
- data/lib/sorcery/controller/submodules/external/protocols/oauth1.rb +35 -0
- data/lib/sorcery/controller/submodules/external/protocols/oauth2.rb +26 -0
- data/lib/sorcery/controller/submodules/{oauth → external}/providers/facebook.rb +24 -6
- data/lib/sorcery/controller/submodules/{oauth → external}/providers/twitter.rb +31 -6
- data/lib/sorcery/controller/submodules/{oauth.rb → external.rb} +18 -30
- data/lib/sorcery/controller/submodules/http_basic_auth.rb +1 -1
- data/lib/sorcery/controller.rb +21 -21
- data/lib/sorcery/crypto_providers/bcrypt.rb +1 -1
- data/lib/sorcery/crypto_providers/common.rb +35 -0
- data/lib/sorcery/crypto_providers/md5.rb +3 -23
- data/lib/sorcery/crypto_providers/sha1.rb +4 -16
- data/lib/sorcery/crypto_providers/sha256.rb +3 -23
- data/lib/sorcery/crypto_providers/sha512.rb +3 -23
- data/lib/sorcery/engine.rb +4 -0
- data/lib/sorcery/initializers/initializer.rb +86 -0
- data/lib/sorcery/model/submodules/{oauth.rb → external.rb} +3 -3
- data/lib/sorcery/model.rb +13 -8
- data/lib/sorcery/railties/tasks.rake +10 -0
- data/lib/sorcery/sinatra.rb +0 -9
- data/lib/sorcery/test_helpers/rails.rb +6 -9
- data/lib/sorcery/test_helpers/sinatra.rb +6 -9
- data/lib/sorcery/test_helpers.rb +12 -0
- data/lib/sorcery.rb +10 -7
- data/sorcery.gemspec +146 -153
- data/spec/Gemfile +2 -2
- data/spec/Gemfile.lock +10 -10
- data/spec/Rakefile +1 -0
- data/spec/rails3/.rspec +1 -1
- data/spec/rails3/{app_root/Gemfile → Gemfile} +4 -4
- data/spec/rails3/{app_root/Gemfile.lock → Gemfile.lock} +20 -20
- data/spec/rails3/{app_root/Rakefile → Rakefile} +1 -0
- data/spec/rails3/{app_root/app → app}/controllers/application_controller.rb +11 -11
- data/spec/rails3/config/database.yml +27 -0
- data/spec/rails3/{app_root/spec → spec}/controller_brute_force_protection_spec.rb +3 -2
- data/spec/rails3/{app_root/spec → spec}/controller_oauth2_spec.rb +23 -22
- data/spec/rails3/{app_root/spec → spec}/controller_oauth_spec.rb +17 -17
- data/spec/rails3/{app_root/spec → spec}/controller_session_timeout_spec.rb +8 -4
- data/spec/rails3/spec/spec.opts +2 -0
- data/spec/rails3/spec/spec_helper.rb +70 -0
- data/spec/rails3/{app_root/spec → spec}/user_activation_spec.rb +5 -1
- data/spec/{sinatra → rails3}/spec/user_oauth_spec.rb +7 -7
- data/spec/rails3/{app_root/spec → spec}/user_reset_password_spec.rb +7 -3
- data/spec/rails3/{app_root/spec → spec}/user_spec.rb +5 -11
- data/spec/sinatra/Gemfile +3 -3
- data/spec/sinatra/Gemfile.lock +17 -17
- data/spec/sinatra/Rakefile +1 -0
- data/spec/sinatra/myapp.rb +11 -11
- data/spec/sinatra/spec/controller_brute_force_protection_spec.rb +3 -2
- data/spec/sinatra/spec/controller_oauth2_spec.rb +23 -22
- data/spec/sinatra/spec/controller_oauth_spec.rb +17 -17
- data/spec/sinatra/spec/controller_session_timeout_spec.rb +8 -4
- data/spec/sinatra/spec/spec.opts +2 -4
- data/spec/sinatra/spec/spec_helper.rb +2 -1
- data/spec/sorcery_crypto_providers_spec.rb +5 -4
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +3 -4
- metadata +157 -156
- data/lib/sorcery/controller/submodules/oauth/oauth1.rb +0 -33
- data/lib/sorcery/controller/submodules/oauth/oauth2.rb +0 -24
- data/spec/rails3/app_root/.rspec +0 -1
- data/spec/rails3/app_root/config/database.yml +0 -27
- data/spec/rails3/app_root/spec/spec_helper.rb +0 -62
- data/spec/rails3/app_root/spec/user_oauth_spec.rb +0 -39
- data/spec/sinatra/spec/user_activation_spec.rb +0 -188
- data/spec/sinatra/spec/user_activity_logging_spec.rb +0 -36
- data/spec/sinatra/spec/user_brute_force_protection_spec.rb +0 -76
- data/spec/sinatra/spec/user_remember_me_spec.rb +0 -66
- data/spec/sinatra/spec/user_reset_password_spec.rb +0 -178
- data/spec/sinatra/spec/user_spec.rb +0 -317
- /data/spec/rails3/{app_root/.gitignore → .gitignore} +0 -0
- /data/spec/rails3/{app_root/README → README} +0 -0
- /data/spec/rails3/{app_root/Rakefile.unused → Rakefile.unused} +0 -0
- /data/spec/rails3/{app_root/app → app}/helpers/application_helper.rb +0 -0
- /data/spec/rails3/{app_root/app → app}/mailers/sorcery_mailer.rb +0 -0
- /data/spec/rails3/{app_root/app → app}/models/authentication.rb +0 -0
- /data/spec/rails3/{app_root/app → app}/models/user.rb +0 -0
- /data/spec/rails3/{app_root/app → app}/views/layouts/application.html.erb +0 -0
- /data/spec/rails3/{app_root/app → app}/views/sorcery_mailer/activation_email.html.erb +0 -0
- /data/spec/rails3/{app_root/app → app}/views/sorcery_mailer/activation_email.text.erb +0 -0
- /data/spec/rails3/{app_root/app → app}/views/sorcery_mailer/activation_success_email.html.erb +0 -0
- /data/spec/rails3/{app_root/app → app}/views/sorcery_mailer/activation_success_email.text.erb +0 -0
- /data/spec/rails3/{app_root/app → app}/views/sorcery_mailer/reset_password_email.html.erb +0 -0
- /data/spec/rails3/{app_root/app → app}/views/sorcery_mailer/reset_password_email.text.erb +0 -0
- /data/spec/rails3/{app_root/config → config}/application.rb +0 -0
- /data/spec/rails3/{app_root/config → config}/boot.rb +0 -0
- /data/spec/rails3/{app_root/config → config}/environment.rb +0 -0
- /data/spec/rails3/{app_root/config → config}/environments/development.rb +0 -0
- /data/spec/rails3/{app_root/config → config}/environments/in_memory.rb +0 -0
- /data/spec/rails3/{app_root/config → config}/environments/production.rb +0 -0
- /data/spec/rails3/{app_root/config → config}/environments/test.rb +0 -0
- /data/spec/rails3/{app_root/config → config}/initializers/backtrace_silencers.rb +0 -0
- /data/spec/rails3/{app_root/config → config}/initializers/inflections.rb +0 -0
- /data/spec/rails3/{app_root/config → config}/initializers/mime_types.rb +0 -0
- /data/spec/rails3/{app_root/config → config}/initializers/secret_token.rb +0 -0
- /data/spec/rails3/{app_root/config → config}/initializers/session_store.rb +0 -0
- /data/spec/rails3/{app_root/config → config}/locales/en.yml +0 -0
- /data/spec/rails3/{app_root/config → config}/routes.rb +0 -0
- /data/spec/rails3/{app_root/config.ru → config.ru} +0 -0
- /data/spec/rails3/{app_root/db → db}/migrate/activation/20101224223622_add_activation_to_users.rb +0 -0
- /data/spec/rails3/{app_root/db → db}/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +0 -0
- /data/spec/rails3/{app_root/db → db}/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +0 -0
- /data/spec/rails3/{app_root/db → db}/migrate/core/20101224223620_create_users.rb +0 -0
- /data/spec/rails3/{app_root/db/migrate/oauth → db/migrate/external}/20101224223628_create_authentications.rb +0 -0
- /data/spec/rails3/{app_root/db → db}/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb +0 -0
- /data/spec/rails3/{app_root/db → db}/migrate/reset_password/20101224223622_add_reset_password_to_users.rb +0 -0
- /data/spec/rails3/{app_root/db → db}/schema.rb +0 -0
- /data/spec/rails3/{app_root/db → db}/seeds.rb +0 -0
- /data/spec/rails3/{app_root/lib → lib}/tasks/.gitkeep +0 -0
- /data/spec/rails3/{app_root/public → public}/404.html +0 -0
- /data/spec/rails3/{app_root/public → public}/422.html +0 -0
- /data/spec/rails3/{app_root/public → public}/500.html +0 -0
- /data/spec/rails3/{app_root/public → public}/favicon.ico +0 -0
- /data/spec/rails3/{app_root/public → public}/images/rails.png +0 -0
- /data/spec/rails3/{app_root/public → public}/index.html +0 -0
- /data/spec/rails3/{app_root/public → public}/javascripts/application.js +0 -0
- /data/spec/rails3/{app_root/public → public}/javascripts/controls.js +0 -0
- /data/spec/rails3/{app_root/public → public}/javascripts/dragdrop.js +0 -0
- /data/spec/rails3/{app_root/public → public}/javascripts/effects.js +0 -0
- /data/spec/rails3/{app_root/public → public}/javascripts/prototype.js +0 -0
- /data/spec/rails3/{app_root/public → public}/javascripts/rails.js +0 -0
- /data/spec/rails3/{app_root/public → public}/robots.txt +0 -0
- /data/spec/rails3/{app_root/public → public}/stylesheets/.gitkeep +0 -0
- /data/spec/rails3/{app_root/script → script}/rails +0 -0
- /data/spec/rails3/{app_root/spec → spec}/controller_activity_logging_spec.rb +0 -0
- /data/spec/rails3/{app_root/spec → spec}/controller_http_basic_auth_spec.rb +0 -0
- /data/spec/rails3/{app_root/spec → spec}/controller_remember_me_spec.rb +0 -0
- /data/spec/rails3/{app_root/spec → spec}/controller_spec.rb +0 -0
- /data/spec/rails3/{app_root/spec → spec}/spec_helper.orig.rb +0 -0
- /data/spec/rails3/{app_root/spec → spec}/user_activity_logging_spec.rb +0 -0
- /data/spec/rails3/{app_root/spec → spec}/user_brute_force_protection_spec.rb +0 -0
- /data/spec/rails3/{app_root/spec → spec}/user_remember_me_spec.rb +0 -0
- /data/spec/rails3/{app_root/vendor → vendor}/plugins/.gitkeep +0 -0
- /data/spec/sinatra/db/migrate/{oauth → external}/20101224223628_create_authentications.rb +0 -0
data/spec/sinatra/myapp.rb
CHANGED
|
@@ -53,7 +53,7 @@ end
|
|
|
53
53
|
post '/test_return_to' do
|
|
54
54
|
session[:return_to_url] = params[:return_to_url] if params[:return_to_url]
|
|
55
55
|
@user = login(params[:username], params[:password])
|
|
56
|
-
|
|
56
|
+
redirect_back_or_to(:some_action)
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
get '/test_should_be_logged_in' do
|
|
@@ -96,12 +96,12 @@ end
|
|
|
96
96
|
|
|
97
97
|
# oauth
|
|
98
98
|
|
|
99
|
-
get '/
|
|
100
|
-
|
|
99
|
+
get '/login_at_test' do
|
|
100
|
+
login_at(:twitter)
|
|
101
101
|
end
|
|
102
102
|
|
|
103
|
-
get '/
|
|
104
|
-
if @user =
|
|
103
|
+
get '/test_login_from' do
|
|
104
|
+
if @user = login_from(:twitter)
|
|
105
105
|
erb "Success!"
|
|
106
106
|
else
|
|
107
107
|
erb "Failed!"
|
|
@@ -110,12 +110,12 @@ end
|
|
|
110
110
|
|
|
111
111
|
# oauth2
|
|
112
112
|
|
|
113
|
-
get '/
|
|
114
|
-
|
|
113
|
+
get '/login_at_test2' do
|
|
114
|
+
login_at(:facebook)
|
|
115
115
|
end
|
|
116
116
|
|
|
117
|
-
get '/
|
|
118
|
-
if @user =
|
|
117
|
+
get '/test_login_from2' do
|
|
118
|
+
if @user = login_from(:facebook)
|
|
119
119
|
erb "Success!"
|
|
120
120
|
else
|
|
121
121
|
erb "Failed!"
|
|
@@ -124,8 +124,8 @@ end
|
|
|
124
124
|
|
|
125
125
|
get '/test_create_from_provider' do
|
|
126
126
|
provider = params[:provider]
|
|
127
|
-
|
|
128
|
-
if @user =
|
|
127
|
+
login_from(provider)
|
|
128
|
+
if @user = create_from(provider)
|
|
129
129
|
erb "Success!"
|
|
130
130
|
else
|
|
131
131
|
erb "Failed!"
|
|
@@ -23,6 +23,7 @@ describe Sinatra::Application do
|
|
|
23
23
|
Sorcery::Controller::Config.reset!
|
|
24
24
|
sorcery_controller_property_set(:user_class, User)
|
|
25
25
|
User.delete_all
|
|
26
|
+
Timecop.return
|
|
26
27
|
end
|
|
27
28
|
|
|
28
29
|
it "should count login retries" do
|
|
@@ -50,7 +51,7 @@ describe Sinatra::Application do
|
|
|
50
51
|
get "/test_login", :username => 'gizmo', :password => 'blabla'
|
|
51
52
|
get "/test_login", :username => 'gizmo', :password => 'blabla'
|
|
52
53
|
User.find_by_username('gizmo').lock_expires_at.should_not be_nil
|
|
53
|
-
|
|
54
|
+
Timecop.travel(Time.now+0.3)
|
|
54
55
|
get "/test_login", :username => 'gizmo', :password => 'blabla'
|
|
55
56
|
User.find_by_username('gizmo').lock_expires_at.should be_nil
|
|
56
57
|
end
|
|
@@ -61,7 +62,7 @@ describe Sinatra::Application do
|
|
|
61
62
|
get "/test_login", :username => 'gizmo', :password => 'blabla'
|
|
62
63
|
get "/test_login", :username => 'gizmo', :password => 'blabla'
|
|
63
64
|
unlock_date = User.find_by_username('gizmo').lock_expires_at
|
|
64
|
-
|
|
65
|
+
Timecop.travel(Time.now+1)
|
|
65
66
|
get "/test_login", :username => 'gizmo', :password => 'blabla'
|
|
66
67
|
User.find_by_username('gizmo').lock_expires_at.to_s.should == unlock_date.to_s
|
|
67
68
|
end
|
|
@@ -12,16 +12,16 @@ end
|
|
|
12
12
|
|
|
13
13
|
describe 'MyApp' do
|
|
14
14
|
before(:all) do
|
|
15
|
-
ActiveRecord::Migrator.migrate("#{APP_ROOT}/db/migrate/
|
|
16
|
-
sorcery_reload!([:
|
|
17
|
-
sorcery_controller_property_set(:
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
ActiveRecord::Migrator.migrate("#{APP_ROOT}/db/migrate/external")
|
|
16
|
+
sorcery_reload!([:external])
|
|
17
|
+
sorcery_controller_property_set(:external_providers, [:facebook])
|
|
18
|
+
sorcery_controller_external_property_set(:facebook, :key, "eYVNBjBDi33aa9GkA3w")
|
|
19
|
+
sorcery_controller_external_property_set(:facebook, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
|
|
20
|
+
sorcery_controller_external_property_set(:facebook, :callback_url, "http://blabla.com")
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
after(:all) do
|
|
24
|
-
ActiveRecord::Migrator.rollback("#{APP_ROOT}/db/migrate/
|
|
24
|
+
ActiveRecord::Migrator.rollback("#{APP_ROOT}/db/migrate/external")
|
|
25
25
|
end
|
|
26
26
|
# ----------------- OAuth -----------------------
|
|
27
27
|
describe Sinatra::Application, "with OAuth features" do
|
|
@@ -35,29 +35,30 @@ describe 'MyApp' do
|
|
|
35
35
|
Authentication.delete_all
|
|
36
36
|
end
|
|
37
37
|
|
|
38
|
-
it "
|
|
38
|
+
it "login_at redirects correctly" do
|
|
39
39
|
create_new_user
|
|
40
|
-
get "/
|
|
40
|
+
get "/login_at_test2"
|
|
41
41
|
last_response.should be_a_redirect
|
|
42
|
-
last_response.should redirect_to("http://myapi.com/oauth/authorize?client_id=key&redirect_uri=http%3A%2F%2Fblabla.com&scope=email%2Coffline_access&type=web_server")
|
|
42
|
+
#last_response.should redirect_to("http://myapi.com/oauth/authorize?client_id=key&redirect_uri=http%3A%2F%2Fblabla.com&scope=email%2Coffline_access&type=web_server")
|
|
43
|
+
last_response.should redirect_to("http://myapi.com/oauth/authorize?client_id=key&redirect_uri=http%3A%2F%2Fblabla.com&scope=email%2Coffline_access&response_type=code")
|
|
43
44
|
end
|
|
44
45
|
|
|
45
|
-
it "'
|
|
46
|
+
it "'login_from' logins if user exists" do
|
|
46
47
|
sorcery_model_property_set(:authentications_class, Authentication)
|
|
47
48
|
create_new_external_user(:facebook)
|
|
48
|
-
get "/
|
|
49
|
+
get "/test_login_from2"
|
|
49
50
|
last_response.body.should == "Success!"
|
|
50
51
|
end
|
|
51
52
|
|
|
52
|
-
it "'
|
|
53
|
+
it "'login_from' fails if user doesn't exist" do
|
|
53
54
|
sorcery_model_property_set(:authentications_class, Authentication)
|
|
54
55
|
create_new_user
|
|
55
|
-
get "/
|
|
56
|
+
get "/test_login_from2"
|
|
56
57
|
last_response.body.should == "Failed!"
|
|
57
58
|
end
|
|
58
59
|
end
|
|
59
60
|
|
|
60
|
-
describe Sinatra::Application, "'
|
|
61
|
+
describe Sinatra::Application, "'create_from'" do
|
|
61
62
|
before(:each) do
|
|
62
63
|
stub_all_oauth2_requests!
|
|
63
64
|
User.delete_all
|
|
@@ -66,7 +67,7 @@ describe 'MyApp' do
|
|
|
66
67
|
|
|
67
68
|
it "should create a new user" do
|
|
68
69
|
sorcery_model_property_set(:authentications_class, Authentication)
|
|
69
|
-
|
|
70
|
+
sorcery_controller_external_property_set(:facebook, :user_info_mapping, {:username => "name"})
|
|
70
71
|
lambda do
|
|
71
72
|
get "/test_create_from_provider", :provider => "facebook"
|
|
72
73
|
end.should change(User, :count).by(1)
|
|
@@ -75,7 +76,7 @@ describe 'MyApp' do
|
|
|
75
76
|
|
|
76
77
|
it "should support nested attributes" do
|
|
77
78
|
sorcery_model_property_set(:authentications_class, Authentication)
|
|
78
|
-
|
|
79
|
+
sorcery_controller_external_property_set(:facebook, :user_info_mapping, {:username => "hometown/name"})
|
|
79
80
|
lambda do
|
|
80
81
|
get "/test_create_from_provider", :provider => "facebook"
|
|
81
82
|
end.should change(User, :count).by(1)
|
|
@@ -86,11 +87,11 @@ describe 'MyApp' do
|
|
|
86
87
|
describe Sinatra::Application, "OAuth with User Activation features" do
|
|
87
88
|
before(:all) do
|
|
88
89
|
ActiveRecord::Migrator.migrate("#{APP_ROOT}/db/migrate/activation")
|
|
89
|
-
sorcery_reload!([:user_activation,:
|
|
90
|
-
sorcery_controller_property_set(:
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
90
|
+
sorcery_reload!([:user_activation,:external], :user_activation_mailer => ::SorceryMailer)
|
|
91
|
+
sorcery_controller_property_set(:external_providers, [:facebook])
|
|
92
|
+
sorcery_controller_external_property_set(:facebook, :key, "eYVNBjBDi33aa9GkA3w")
|
|
93
|
+
sorcery_controller_external_property_set(:facebook, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
|
|
94
|
+
sorcery_controller_external_property_set(:facebook, :callback_url, "http://blabla.com")
|
|
94
95
|
end
|
|
95
96
|
|
|
96
97
|
after(:all) do
|
|
@@ -18,19 +18,19 @@ end
|
|
|
18
18
|
|
|
19
19
|
describe Sinatra::Application do
|
|
20
20
|
before(:all) do
|
|
21
|
-
ActiveRecord::Migrator.migrate("#{APP_ROOT}/db/migrate/
|
|
22
|
-
sorcery_reload!([:
|
|
23
|
-
sorcery_controller_property_set(:
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
ActiveRecord::Migrator.migrate("#{APP_ROOT}/db/migrate/external")
|
|
22
|
+
sorcery_reload!([:external])
|
|
23
|
+
sorcery_controller_property_set(:external_providers, [:twitter])
|
|
24
|
+
sorcery_controller_external_property_set(:twitter, :key, "eYVNBjBDi33aa9GkA3w")
|
|
25
|
+
sorcery_controller_external_property_set(:twitter, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
|
|
26
|
+
sorcery_controller_external_property_set(:twitter, :callback_url, "http://blabla.com")
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
after(:all) do
|
|
30
|
-
ActiveRecord::Migrator.rollback("#{APP_ROOT}/db/migrate/
|
|
30
|
+
ActiveRecord::Migrator.rollback("#{APP_ROOT}/db/migrate/external")
|
|
31
31
|
end
|
|
32
32
|
# ----------------- OAuth -----------------------
|
|
33
|
-
describe Sinatra::Application, "'
|
|
33
|
+
describe Sinatra::Application, "'login_from'" do
|
|
34
34
|
|
|
35
35
|
before(:each) do
|
|
36
36
|
stub_all_oauth_requests!
|
|
@@ -41,9 +41,9 @@ describe Sinatra::Application do
|
|
|
41
41
|
Authentication.delete_all
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
-
it "
|
|
44
|
+
it "login_at_test redirects correctly" do
|
|
45
45
|
create_new_user
|
|
46
|
-
get "/
|
|
46
|
+
get "/login_at_test"
|
|
47
47
|
last_response.should be_a_redirect
|
|
48
48
|
last_response.should redirect_to("http://myapi.com/oauth/authorize?oauth_callback=http%3A%2F%2Fblabla.com&oauth_token=")
|
|
49
49
|
end
|
|
@@ -51,19 +51,19 @@ describe Sinatra::Application do
|
|
|
51
51
|
it "logins if user exists" do
|
|
52
52
|
sorcery_model_property_set(:authentications_class, Authentication)
|
|
53
53
|
create_new_external_user(:twitter)
|
|
54
|
-
get '/
|
|
54
|
+
get '/test_login_from', :oauth_verifier => "blablaRERASDFcxvSDFA"
|
|
55
55
|
last_response.body.should == "Success!"
|
|
56
56
|
end
|
|
57
57
|
|
|
58
|
-
it "'
|
|
58
|
+
it "'login_from' fails if user doesn't exist" do
|
|
59
59
|
sorcery_model_property_set(:authentications_class, Authentication)
|
|
60
60
|
create_new_user
|
|
61
|
-
get
|
|
61
|
+
get '/test_login_from', :oauth_verifier => "blablaRERASDFcxvSDFA"
|
|
62
62
|
last_response.body.should == "Failed!"
|
|
63
63
|
end
|
|
64
64
|
end
|
|
65
65
|
|
|
66
|
-
describe Sinatra::Application, "'
|
|
66
|
+
describe Sinatra::Application, "'create_from'" do
|
|
67
67
|
before(:each) do
|
|
68
68
|
stub_all_oauth_requests!
|
|
69
69
|
User.delete_all
|
|
@@ -72,7 +72,7 @@ describe Sinatra::Application do
|
|
|
72
72
|
|
|
73
73
|
it "should create a new user" do
|
|
74
74
|
sorcery_model_property_set(:authentications_class, Authentication)
|
|
75
|
-
|
|
75
|
+
sorcery_controller_external_property_set(:twitter, :user_info_mapping, {:username => "screen_name"})
|
|
76
76
|
lambda do
|
|
77
77
|
get :test_create_from_provider, :provider => "twitter"
|
|
78
78
|
end.should change(User, :count).by(1)
|
|
@@ -81,7 +81,7 @@ describe Sinatra::Application do
|
|
|
81
81
|
|
|
82
82
|
it "should support nested attributes" do
|
|
83
83
|
sorcery_model_property_set(:authentications_class, Authentication)
|
|
84
|
-
|
|
84
|
+
sorcery_controller_external_property_set(:twitter, :user_info_mapping, {:username => "status/text"})
|
|
85
85
|
lambda do
|
|
86
86
|
get :test_create_from_provider, :provider => "twitter"
|
|
87
87
|
end.should change(User, :count).by(1)
|
|
@@ -92,7 +92,7 @@ describe Sinatra::Application do
|
|
|
92
92
|
describe Sinatra::Application, "OAuth with User Activation features" do
|
|
93
93
|
before(:all) do
|
|
94
94
|
ActiveRecord::Migrator.migrate("#{APP_ROOT}/db/migrate/activation")
|
|
95
|
-
sorcery_reload!([:user_activation,:
|
|
95
|
+
sorcery_reload!([:user_activation,:external], :user_activation_mailer => ::SorceryMailer)
|
|
96
96
|
end
|
|
97
97
|
|
|
98
98
|
after(:all) do
|
|
@@ -10,6 +10,10 @@ describe Sinatra::Application do
|
|
|
10
10
|
create_new_user
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
+
after(:each) do
|
|
14
|
+
Timecop.return
|
|
15
|
+
end
|
|
16
|
+
|
|
13
17
|
it "should not reset session before session timeout" do
|
|
14
18
|
session[:user_id] = User.first.id
|
|
15
19
|
get "/test_should_be_logged_in"
|
|
@@ -19,7 +23,7 @@ describe Sinatra::Application do
|
|
|
19
23
|
it "should reset session after session timeout" do
|
|
20
24
|
get "/test_login", :username => 'gizmo', :password => 'secret'
|
|
21
25
|
session[:user_id].should_not be_nil
|
|
22
|
-
|
|
26
|
+
Timecop.travel(Time.now+0.6)
|
|
23
27
|
get "/test_should_be_logged_in"
|
|
24
28
|
last_response.should be_a_redirect
|
|
25
29
|
end
|
|
@@ -29,10 +33,10 @@ describe Sinatra::Application do
|
|
|
29
33
|
sorcery_controller_property_set(:session_timeout,2)
|
|
30
34
|
sorcery_controller_property_set(:session_timeout_from_last_action, true)
|
|
31
35
|
get "/test_login", :username => 'gizmo', :password => 'secret'
|
|
32
|
-
|
|
36
|
+
Timecop.travel(Time.now+1)
|
|
33
37
|
get "/test_should_be_logged_in"
|
|
34
38
|
session[:user_id].should_not be_nil
|
|
35
|
-
|
|
39
|
+
Timecop.travel(Time.now+1)
|
|
36
40
|
get "/test_should_be_logged_in"
|
|
37
41
|
session[:user_id].should_not be_nil
|
|
38
42
|
last_response.should be_ok
|
|
@@ -42,7 +46,7 @@ describe Sinatra::Application do
|
|
|
42
46
|
sorcery_controller_property_set(:session_timeout,0.5)
|
|
43
47
|
sorcery_controller_property_set(:session_timeout_from_last_action, true)
|
|
44
48
|
get "/test_login", :username => 'gizmo', :password => 'secret'
|
|
45
|
-
|
|
49
|
+
Timecop.travel(Time.now+0.6)
|
|
46
50
|
get "/test_should_be_logged_in"
|
|
47
51
|
session[:user_id].should be_nil
|
|
48
52
|
last_response.should be_a_redirect
|
data/spec/sinatra/spec/spec.opts
CHANGED
|
@@ -3,6 +3,7 @@ $: << APP_ROOT # for model reloading
|
|
|
3
3
|
|
|
4
4
|
require 'rack/test'
|
|
5
5
|
require 'rspec'
|
|
6
|
+
require 'timecop'
|
|
6
7
|
|
|
7
8
|
# set test environment
|
|
8
9
|
set :environment, :test
|
|
@@ -36,7 +37,7 @@ require File.join(File.dirname(__FILE__), '..','user')
|
|
|
36
37
|
require File.join(File.dirname(__FILE__), '..','authentication')
|
|
37
38
|
|
|
38
39
|
class TestUser < ActiveRecord::Base
|
|
39
|
-
|
|
40
|
+
authenticates_with_sorcery!
|
|
40
41
|
end
|
|
41
42
|
|
|
42
43
|
class TestMailer < ActionMailer::Base
|
|
@@ -31,7 +31,7 @@ describe "Crypto Providers wrappers" do
|
|
|
31
31
|
|
|
32
32
|
before(:all) do
|
|
33
33
|
@digest = 'Noam Ben-Ari'
|
|
34
|
-
|
|
34
|
+
Sorcery::CryptoProviders::SHA1.stretches.times {@digest = Digest::SHA1.hexdigest(@digest)}
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
after(:each) do
|
|
@@ -61,7 +61,7 @@ describe "Crypto Providers wrappers" do
|
|
|
61
61
|
|
|
62
62
|
before(:all) do
|
|
63
63
|
@digest = 'Noam Ben-Ari'
|
|
64
|
-
|
|
64
|
+
Sorcery::CryptoProviders::SHA256.stretches.times {@digest = Digest::SHA256.hexdigest(@digest)}
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
after(:each) do
|
|
@@ -91,7 +91,7 @@ describe "Crypto Providers wrappers" do
|
|
|
91
91
|
|
|
92
92
|
before(:all) do
|
|
93
93
|
@digest = 'Noam Ben-Ari'
|
|
94
|
-
|
|
94
|
+
Sorcery::CryptoProviders::SHA512.stretches.times {@digest = Digest::SHA512.hexdigest(@digest)}
|
|
95
95
|
end
|
|
96
96
|
|
|
97
97
|
after(:each) do
|
|
@@ -153,7 +153,8 @@ describe "Crypto Providers wrappers" do
|
|
|
153
153
|
describe Sorcery::CryptoProviders::BCrypt do
|
|
154
154
|
|
|
155
155
|
before(:all) do
|
|
156
|
-
|
|
156
|
+
Sorcery::CryptoProviders::BCrypt.cost = 1
|
|
157
|
+
@digest = BCrypt::Password.create('Noam Ben-Ari', :cost => Sorcery::CryptoProviders::BCrypt.cost)
|
|
157
158
|
end
|
|
158
159
|
|
|
159
160
|
after(:each) do
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
2
2
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
3
3
|
|
|
4
|
-
require 'simplecov'
|
|
5
|
-
SimpleCov.root File.join(File.dirname(__FILE__), '..', 'lib')
|
|
6
|
-
SimpleCov.start
|
|
7
|
-
|
|
4
|
+
# require 'simplecov'
|
|
5
|
+
# SimpleCov.root File.join(File.dirname(__FILE__), '..', 'lib')
|
|
6
|
+
# SimpleCov.start
|
|
8
7
|
|
|
9
8
|
require 'rspec'
|
|
10
9
|
require 'sorcery'
|