sorcery 0.7.4 → 0.7.5
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.
Potentially problematic release.
This version of sorcery might be problematic. Click here for more details.
- data/Gemfile.lock +2 -2
- data/README.rdoc +1 -1
- data/VERSION +1 -1
- data/lib/generators/sorcery/install_generator.rb +5 -3
- data/lib/generators/sorcery/templates/initializer.rb +25 -4
- data/lib/sorcery.rb +2 -0
- data/lib/sorcery/controller/submodules/external/protocols/oauth2.rb +17 -18
- data/lib/sorcery/controller/submodules/external/providers/github.rb +11 -3
- data/lib/sorcery/controller/submodules/external/providers/google.rb +89 -0
- data/lib/sorcery/controller/submodules/external/providers/liveid.rb +90 -0
- data/lib/sorcery/model.rb +17 -4
- data/lib/sorcery/model/adapters/active_record.rb +6 -1
- data/lib/sorcery/model/adapters/mongo_mapper.rb +6 -1
- data/lib/sorcery/model/adapters/mongoid.rb +6 -1
- data/lib/sorcery/model/submodules/activity_logging.rb +4 -4
- data/lib/sorcery/model/submodules/brute_force_protection.rb +5 -5
- data/lib/sorcery/model/submodules/reset_password.rb +4 -5
- data/lib/sorcery/model/submodules/user_activation.rb +1 -2
- data/sorcery.gemspec +4 -2
- data/spec/Gemfile.lock +3 -3
- data/spec/rails3/Gemfile +1 -2
- data/spec/rails3/Gemfile.lock +13 -14
- data/spec/rails3/app/controllers/application_controller.rb +26 -2
- data/spec/rails3/spec/controller_oauth2_spec.rb +111 -11
- data/spec/rails3/spec/controller_spec.rb +30 -2
- data/spec/rails3_mongo_mapper/Gemfile.lock +11 -11
- data/spec/rails3_mongo_mapper/spec/controller_spec.rb +34 -1
- data/spec/rails3_mongoid/Gemfile.lock +8 -8
- data/spec/rails3_mongoid/spec/controller_activity_logging_spec.rb +3 -3
- data/spec/rails3_mongoid/spec/controller_spec.rb +34 -1
- data/spec/shared_examples/user_reset_password_shared_examples.rb +9 -1
- data/spec/sorcery_crypto_providers_spec.rb +5 -1
- metadata +4 -2
@@ -7,8 +7,13 @@ module Sorcery
|
|
7
7
|
end
|
8
8
|
|
9
9
|
module ClassMethods
|
10
|
+
def column_name(attribute)
|
11
|
+
return "LOWER(#{attribute})" if (@sorcery_config.downcase_username_before_authenticating)
|
12
|
+
return "#{attribute}"
|
13
|
+
end
|
14
|
+
|
10
15
|
def find_by_credentials(credentials)
|
11
|
-
sql = @sorcery_config.username_attribute_names.map{|attribute|
|
16
|
+
sql = @sorcery_config.username_attribute_names.map{|attribute| column_name(attribute) + " = :login"}
|
12
17
|
where(sql.join(' OR '), :login => credentials[0]).first
|
13
18
|
end
|
14
19
|
|
@@ -19,9 +19,14 @@ module Sorcery
|
|
19
19
|
end
|
20
20
|
|
21
21
|
module ClassMethods
|
22
|
+
def credential_regex(credential)
|
23
|
+
return { :$regex => /^#{credential}$/i } if (@sorcery_config.downcase_username_before_authenticating)
|
24
|
+
return credential
|
25
|
+
end
|
26
|
+
|
22
27
|
def find_by_credentials(credentials)
|
23
28
|
@sorcery_config.username_attribute_names.each do |attribute|
|
24
|
-
@user = where(attribute => credentials[0]).first
|
29
|
+
@user = where(attribute => credential_regex(credentials[0])).first
|
25
30
|
break if @user
|
26
31
|
end
|
27
32
|
@user
|
@@ -14,9 +14,14 @@ module Sorcery
|
|
14
14
|
end
|
15
15
|
|
16
16
|
module ClassMethods
|
17
|
+
def credential_regex(credential)
|
18
|
+
return { :$regex => /^#{credential}$/i } if (@sorcery_config.downcase_username_before_authenticating)
|
19
|
+
return credential
|
20
|
+
end
|
21
|
+
|
17
22
|
def find_by_credentials(credentials)
|
18
23
|
@sorcery_config.username_attribute_names.each do |attribute|
|
19
|
-
@user = where(attribute => credentials[0]).first
|
24
|
+
@user = where(attribute => credential_regex(credentials[0])).first
|
20
25
|
break if @user
|
21
26
|
end
|
22
27
|
@user
|
@@ -39,12 +39,12 @@ module Sorcery
|
|
39
39
|
protected
|
40
40
|
|
41
41
|
def define_activity_logging_mongoid_fields
|
42
|
-
field sorcery_config.last_login_at_attribute_name, :type =>
|
43
|
-
field sorcery_config.last_logout_at_attribute_name, :type =>
|
44
|
-
field sorcery_config.last_activity_at_attribute_name, :type =>
|
42
|
+
field sorcery_config.last_login_at_attribute_name, :type => Time
|
43
|
+
field sorcery_config.last_logout_at_attribute_name, :type => Time
|
44
|
+
field sorcery_config.last_activity_at_attribute_name, :type => Time
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
50
|
-
end
|
50
|
+
end
|
@@ -38,12 +38,12 @@ module Sorcery
|
|
38
38
|
|
39
39
|
def define_brute_force_protection_mongoid_fields
|
40
40
|
field sorcery_config.failed_logins_count_attribute_name, :type => Integer
|
41
|
-
field sorcery_config.lock_expires_at_attribute_name, :type =>
|
41
|
+
field sorcery_config.lock_expires_at_attribute_name, :type => Time
|
42
42
|
end
|
43
43
|
|
44
44
|
def define_brute_force_protection_mongo_mapper_fields
|
45
45
|
key sorcery_config.failed_logins_count_attribute_name, Integer
|
46
|
-
key sorcery_config.lock_expires_at_attribute_name,
|
46
|
+
key sorcery_config.lock_expires_at_attribute_name, Time
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
@@ -54,7 +54,7 @@ module Sorcery
|
|
54
54
|
config = sorcery_config
|
55
55
|
return if !unlocked?
|
56
56
|
self.increment(config.failed_logins_count_attribute_name)
|
57
|
-
save!(:validate => false)
|
57
|
+
self.save!(:validate => false)
|
58
58
|
self.lock! if self.send(config.failed_logins_count_attribute_name) >= config.consecutive_login_retries_amount_limit
|
59
59
|
end
|
60
60
|
|
@@ -63,14 +63,14 @@ module Sorcery
|
|
63
63
|
def lock!
|
64
64
|
config = sorcery_config
|
65
65
|
self.send(:"#{config.lock_expires_at_attribute_name}=", Time.now.in_time_zone + config.login_lock_time_period)
|
66
|
-
self.save!(validate
|
66
|
+
self.save!(:validate => false)
|
67
67
|
end
|
68
68
|
|
69
69
|
def unlock!
|
70
70
|
config = sorcery_config
|
71
71
|
self.send(:"#{config.lock_expires_at_attribute_name}=", nil)
|
72
72
|
self.send(:"#{config.failed_logins_count_attribute_name}=", 0)
|
73
|
-
self.save!(validate
|
73
|
+
self.save!(:validate => false)
|
74
74
|
end
|
75
75
|
|
76
76
|
def unlocked?
|
@@ -72,13 +72,12 @@ module Sorcery
|
|
72
72
|
|
73
73
|
def define_reset_password_mongoid_fields
|
74
74
|
field sorcery_config.reset_password_token_attribute_name, :type => String
|
75
|
-
field sorcery_config.reset_password_token_expires_at_attribute_name, :type =>
|
76
|
-
field sorcery_config.reset_password_email_sent_at_attribute_name, :type =>
|
75
|
+
field sorcery_config.reset_password_token_expires_at_attribute_name, :type => Time
|
76
|
+
field sorcery_config.reset_password_email_sent_at_attribute_name, :type => Time
|
77
77
|
end
|
78
78
|
|
79
79
|
def define_reset_password_mongo_mapper_fields
|
80
80
|
key sorcery_config.reset_password_token_attribute_name, String
|
81
|
-
# no DateTime in MM
|
82
81
|
key sorcery_config.reset_password_token_expires_at_attribute_name, Time
|
83
82
|
key sorcery_config.reset_password_email_sent_at_attribute_name, Time
|
84
83
|
end
|
@@ -89,7 +88,7 @@ module Sorcery
|
|
89
88
|
def deliver_reset_password_instructions!
|
90
89
|
config = sorcery_config
|
91
90
|
# hammering protection
|
92
|
-
return if config.reset_password_time_between_emails && self.send(config.reset_password_email_sent_at_attribute_name) && self.send(config.reset_password_email_sent_at_attribute_name) > config.reset_password_time_between_emails.ago.utc
|
91
|
+
return false if config.reset_password_time_between_emails && self.send(config.reset_password_email_sent_at_attribute_name) && self.send(config.reset_password_email_sent_at_attribute_name) > config.reset_password_time_between_emails.ago.utc
|
93
92
|
self.send(:"#{config.reset_password_token_attribute_name}=", TemporaryToken.generate_random_token)
|
94
93
|
self.send(:"#{config.reset_password_token_expires_at_attribute_name}=", Time.now.in_time_zone + config.reset_password_expiration_period) if config.reset_password_expiration_period
|
95
94
|
self.send(:"#{config.reset_password_email_sent_at_attribute_name}=", Time.now.in_time_zone)
|
@@ -119,4 +118,4 @@ module Sorcery
|
|
119
118
|
end
|
120
119
|
end
|
121
120
|
end
|
122
|
-
end
|
121
|
+
end
|
@@ -84,7 +84,7 @@ module Sorcery
|
|
84
84
|
self.class_eval do
|
85
85
|
field sorcery_config.activation_state_attribute_name, :type => String
|
86
86
|
field sorcery_config.activation_token_attribute_name, :type => String
|
87
|
-
field sorcery_config.activation_token_expires_at_attribute_name, :type =>
|
87
|
+
field sorcery_config.activation_token_expires_at_attribute_name, :type => Time
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
@@ -92,7 +92,6 @@ module Sorcery
|
|
92
92
|
self.class_eval do
|
93
93
|
key sorcery_config.activation_state_attribute_name, String
|
94
94
|
key sorcery_config.activation_token_attribute_name, String
|
95
|
-
# no DateTime in MM
|
96
95
|
key sorcery_config.activation_token_expires_at_attribute_name, Time
|
97
96
|
end
|
98
97
|
end
|
data/sorcery.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "sorcery"
|
8
|
-
s.version = "0.7.
|
8
|
+
s.version = "0.7.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Noam Ben Ari"]
|
12
|
-
s.date = "2011-
|
12
|
+
s.date = "2011-11-11"
|
13
13
|
s.description = "Provides common authentication needs such as signing in/out, activating by email and resetting password."
|
14
14
|
s.email = "nbenari@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -45,6 +45,8 @@ Gem::Specification.new do |s|
|
|
45
45
|
"lib/sorcery/controller/submodules/external/protocols/oauth2.rb",
|
46
46
|
"lib/sorcery/controller/submodules/external/providers/facebook.rb",
|
47
47
|
"lib/sorcery/controller/submodules/external/providers/github.rb",
|
48
|
+
"lib/sorcery/controller/submodules/external/providers/google.rb",
|
49
|
+
"lib/sorcery/controller/submodules/external/providers/liveid.rb",
|
48
50
|
"lib/sorcery/controller/submodules/external/providers/twitter.rb",
|
49
51
|
"lib/sorcery/controller/submodules/http_basic_auth.rb",
|
50
52
|
"lib/sorcery/controller/submodules/remember_me.rb",
|
data/spec/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ../
|
3
3
|
specs:
|
4
|
-
sorcery (0.7.
|
4
|
+
sorcery (0.7.4)
|
5
5
|
bcrypt-ruby (~> 3.0.0)
|
6
6
|
oauth (~> 0.4.4)
|
7
7
|
oauth (~> 0.4.4)
|
@@ -66,7 +66,7 @@ GEM
|
|
66
66
|
oauth2 (0.4.1)
|
67
67
|
faraday (~> 0.6.1)
|
68
68
|
multi_json (>= 0.0.5)
|
69
|
-
polyglot (0.3.
|
69
|
+
polyglot (0.3.3)
|
70
70
|
rack (1.2.4)
|
71
71
|
rack-mount (0.6.14)
|
72
72
|
rack (>= 1.0.0)
|
@@ -112,7 +112,7 @@ GEM
|
|
112
112
|
treetop (1.4.10)
|
113
113
|
polyglot
|
114
114
|
polyglot (>= 0.3.1)
|
115
|
-
tzinfo (0.3.
|
115
|
+
tzinfo (0.3.31)
|
116
116
|
|
117
117
|
PLATFORMS
|
118
118
|
ruby
|
data/spec/rails3/Gemfile
CHANGED
@@ -5,8 +5,7 @@ gem 'sqlite3-ruby', :require => 'sqlite3'
|
|
5
5
|
gem "sorcery", '>= 0.1.0', :path => '../../'
|
6
6
|
|
7
7
|
group :development, :test do
|
8
|
-
gem
|
9
|
-
gem 'rspec-rails', "~> 2.5.0"
|
8
|
+
gem 'rspec-rails', "~> 2.7.0"
|
10
9
|
gem 'ruby-debug19'
|
11
10
|
gem 'simplecov', '>= 0.3.8', :require => false # Will install simplecov-html as a dependency
|
12
11
|
gem 'timecop'
|
data/spec/rails3/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ../../
|
3
3
|
specs:
|
4
|
-
sorcery (0.7.
|
4
|
+
sorcery (0.7.4)
|
5
5
|
bcrypt-ruby (~> 3.0.0)
|
6
6
|
oauth (~> 0.4.4)
|
7
7
|
oauth (~> 0.4.4)
|
@@ -68,7 +68,7 @@ GEM
|
|
68
68
|
oauth2 (0.4.1)
|
69
69
|
faraday (~> 0.6.1)
|
70
70
|
multi_json (>= 0.0.5)
|
71
|
-
polyglot (0.3.
|
71
|
+
polyglot (0.3.3)
|
72
72
|
rack (1.2.4)
|
73
73
|
rack-mount (0.6.14)
|
74
74
|
rack (>= 1.0.0)
|
@@ -88,19 +88,19 @@ GEM
|
|
88
88
|
rake (>= 0.8.7)
|
89
89
|
thor (~> 0.14.4)
|
90
90
|
rake (0.9.2.2)
|
91
|
-
rspec (2.
|
92
|
-
rspec-core (~> 2.
|
93
|
-
rspec-expectations (~> 2.
|
94
|
-
rspec-mocks (~> 2.
|
95
|
-
rspec-core (2.
|
96
|
-
rspec-expectations (2.
|
91
|
+
rspec (2.7.0)
|
92
|
+
rspec-core (~> 2.7.0)
|
93
|
+
rspec-expectations (~> 2.7.0)
|
94
|
+
rspec-mocks (~> 2.7.0)
|
95
|
+
rspec-core (2.7.1)
|
96
|
+
rspec-expectations (2.7.0)
|
97
97
|
diff-lcs (~> 1.1.2)
|
98
|
-
rspec-mocks (2.
|
99
|
-
rspec-rails (2.
|
98
|
+
rspec-mocks (2.7.0)
|
99
|
+
rspec-rails (2.7.0)
|
100
100
|
actionpack (~> 3.0)
|
101
101
|
activesupport (~> 3.0)
|
102
102
|
railties (~> 3.0)
|
103
|
-
rspec (~> 2.
|
103
|
+
rspec (~> 2.7.0)
|
104
104
|
ruby-debug-base19 (0.11.25)
|
105
105
|
columnize (>= 0.3.1)
|
106
106
|
linecache19 (>= 0.5.11)
|
@@ -123,7 +123,7 @@ GEM
|
|
123
123
|
treetop (1.4.10)
|
124
124
|
polyglot
|
125
125
|
polyglot (>= 0.3.1)
|
126
|
-
tzinfo (0.3.
|
126
|
+
tzinfo (0.3.31)
|
127
127
|
|
128
128
|
PLATFORMS
|
129
129
|
ruby
|
@@ -131,8 +131,7 @@ PLATFORMS
|
|
131
131
|
DEPENDENCIES
|
132
132
|
launchy (~> 2.0.5)
|
133
133
|
rails (= 3.0.3)
|
134
|
-
rspec (~> 2.
|
135
|
-
rspec-rails (~> 2.5.0)
|
134
|
+
rspec-rails (~> 2.7.0)
|
136
135
|
ruby-debug19
|
137
136
|
simplecov (>= 0.3.8)
|
138
137
|
sorcery (>= 0.1.0)!
|
@@ -9,7 +9,7 @@ class ApplicationController < ActionController::Base
|
|
9
9
|
|
10
10
|
def index
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
def some_action
|
14
14
|
render :nothing => true
|
15
15
|
end
|
@@ -18,7 +18,7 @@ class ApplicationController < ActionController::Base
|
|
18
18
|
@user = login(params[:username], params[:password])
|
19
19
|
render :text => ""
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
def test_auto_login
|
23
23
|
@user = User.find(:first)
|
24
24
|
auto_login(@user)
|
@@ -84,6 +84,14 @@ class ApplicationController < ActionController::Base
|
|
84
84
|
login_at(:github)
|
85
85
|
end
|
86
86
|
|
87
|
+
def login_at_test4
|
88
|
+
login_at(:google)
|
89
|
+
end
|
90
|
+
|
91
|
+
def login_at_test5
|
92
|
+
login_at(:liveid)
|
93
|
+
end
|
94
|
+
|
87
95
|
def test_login_from
|
88
96
|
if @user = login_from(:twitter)
|
89
97
|
redirect_to "bla", :notice => "Success!"
|
@@ -108,6 +116,22 @@ class ApplicationController < ActionController::Base
|
|
108
116
|
end
|
109
117
|
end
|
110
118
|
|
119
|
+
def test_login_from4
|
120
|
+
if @user = login_from(:google)
|
121
|
+
redirect_to "bla", :notice => "Success!"
|
122
|
+
else
|
123
|
+
redirect_to "blu", :alert => "Failed!"
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_login_from5
|
128
|
+
if @user = login_from(:liveid)
|
129
|
+
redirect_to "bla", :notice => "Success!"
|
130
|
+
else
|
131
|
+
redirect_to "blu", :alert => "Failed!"
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
111
135
|
def test_create_from_provider
|
112
136
|
provider = params[:provider]
|
113
137
|
login_from(provider)
|
@@ -2,26 +2,45 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
2
|
require File.expand_path(File.dirname(__FILE__) + '/../../shared_examples/controller_oauth2_shared_examples')
|
3
3
|
|
4
4
|
def stub_all_oauth2_requests!
|
5
|
-
|
6
|
-
OAuth2::
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
web_server = OAuth2::Strategy::WebServer.any_instance
|
6
|
+
access_token = mock(OAuth2::AccessToken)
|
7
|
+
access_token.stub(:token_param=)
|
8
|
+
access_token.stub(:get).and_return({
|
9
|
+
"id"=>"123",
|
10
|
+
"name"=>"Noam Ben Ari",
|
11
|
+
"first_name"=>"Noam",
|
12
|
+
"last_name"=>"Ben Ari",
|
13
|
+
"link"=>"http://www.facebook.com/nbenari1",
|
14
|
+
"hometown"=>{"id"=>"110619208966868", "name"=>"Haifa, Israel"},
|
15
|
+
"location"=>{"id"=>"106906559341067", "name"=>"Pardes Hanah, Hefa, Israel"},
|
16
|
+
"bio"=>"I'm a new daddy, and enjoying it!",
|
17
|
+
"gender"=>"male",
|
18
|
+
"email"=>"nbenari@gmail.com",
|
19
|
+
"timezone"=>2,
|
20
|
+
"locale"=>"en_US",
|
21
|
+
"languages"=>[{"id"=>"108405449189952", "name"=>"Hebrew"}, {"id"=>"106059522759137", "name"=>"English"}, {"id"=>"112624162082677", "name"=>"Russian"}],
|
22
|
+
"verified"=>true,
|
23
|
+
"updated_time"=>"2011-02-16T20:59:38+0000"}.to_json)
|
24
|
+
web_server.stub(:get_access_token).and_return(access_token)
|
12
25
|
end
|
13
26
|
|
14
27
|
describe ApplicationController do
|
15
28
|
before(:all) do
|
16
29
|
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/external")
|
17
30
|
sorcery_reload!([:external])
|
18
|
-
sorcery_controller_property_set(:external_providers, [:facebook, :github])
|
31
|
+
sorcery_controller_property_set(:external_providers, [:facebook, :github, :google, :liveid])
|
19
32
|
sorcery_controller_external_property_set(:facebook, :key, "eYVNBjBDi33aa9GkA3w")
|
20
33
|
sorcery_controller_external_property_set(:facebook, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
|
21
34
|
sorcery_controller_external_property_set(:facebook, :callback_url, "http://blabla.com")
|
22
35
|
sorcery_controller_external_property_set(:github, :key, "eYVNBjBDi33aa9GkA3w")
|
23
36
|
sorcery_controller_external_property_set(:github, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
|
24
37
|
sorcery_controller_external_property_set(:github, :callback_url, "http://blabla.com")
|
38
|
+
sorcery_controller_external_property_set(:google, :key, "eYVNBjBDi33aa9GkA3w")
|
39
|
+
sorcery_controller_external_property_set(:google, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
|
40
|
+
sorcery_controller_external_property_set(:google, :callback_url, "http://blabla.com")
|
41
|
+
sorcery_controller_external_property_set(:liveid, :key, "eYVNBjBDi33aa9GkA3w")
|
42
|
+
sorcery_controller_external_property_set(:liveid, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
|
43
|
+
sorcery_controller_external_property_set(:liveid, :callback_url, "http://blabla.com")
|
25
44
|
end
|
26
45
|
|
27
46
|
after(:all) do
|
@@ -43,7 +62,7 @@ describe ApplicationController do
|
|
43
62
|
create_new_user
|
44
63
|
get :login_at_test2
|
45
64
|
response.should be_a_redirect
|
46
|
-
response.should redirect_to("
|
65
|
+
response.should redirect_to("https://graph.facebook.com/oauth/authorize?client_id=#{::Sorcery::Controller::Config.facebook.key}&redirect_uri=http%3A%2F%2Fblabla.com&scope=email%2Coffline_access&response_type=code")
|
47
66
|
end
|
48
67
|
|
49
68
|
it "'login_from' logins if user exists" do
|
@@ -65,7 +84,7 @@ describe ApplicationController do
|
|
65
84
|
create_new_user
|
66
85
|
get :login_at_test3
|
67
86
|
response.should be_a_redirect
|
68
|
-
response.should redirect_to("
|
87
|
+
response.should redirect_to("https://github.com/login/oauth/authorize?client_id=#{::Sorcery::Controller::Config.github.key}&redirect_uri=http%3A%2F%2Fblabla.com&scope=&response_type=code")
|
69
88
|
end
|
70
89
|
|
71
90
|
it "'login_from' logins if user exists (github)" do
|
@@ -82,6 +101,50 @@ describe ApplicationController do
|
|
82
101
|
flash[:alert].should == "Failed!"
|
83
102
|
end
|
84
103
|
|
104
|
+
# provider: google
|
105
|
+
it "login_at redirects correctly (google)" do
|
106
|
+
create_new_user
|
107
|
+
get :login_at_test4
|
108
|
+
response.should be_a_redirect
|
109
|
+
response.should redirect_to("https://accounts.google.com/o/oauth2/auth?client_id=#{::Sorcery::Controller::Config.google.key}&redirect_uri=http%3A%2F%2Fblabla.com&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile&response_type=code")
|
110
|
+
end
|
111
|
+
|
112
|
+
it "'login_from' logins if user exists (google)" do
|
113
|
+
sorcery_model_property_set(:authentications_class, Authentication)
|
114
|
+
create_new_external_user(:google)
|
115
|
+
get :test_login_from4
|
116
|
+
flash[:notice].should == "Success!"
|
117
|
+
end
|
118
|
+
|
119
|
+
it "'login_from' fails if user doesn't exist (google)" do
|
120
|
+
sorcery_model_property_set(:authentications_class, Authentication)
|
121
|
+
create_new_user
|
122
|
+
get :test_login_from4
|
123
|
+
flash[:alert].should == "Failed!"
|
124
|
+
end
|
125
|
+
|
126
|
+
# provider: liveid
|
127
|
+
it "login_at redirects correctly (liveid)" do
|
128
|
+
create_new_user
|
129
|
+
get :login_at_test5
|
130
|
+
response.should be_a_redirect
|
131
|
+
response.should redirect_to("https://oauth.live.com/authorize?client_id=#{::Sorcery::Controller::Config.liveid.key}&redirect_uri=http%3A%2F%2Fblabla.com&scope=wl.basic%20wl.emails%20wl.offline_access&response_type=code")
|
132
|
+
end
|
133
|
+
|
134
|
+
it "'login_from' logins if user exists (liveid)" do
|
135
|
+
sorcery_model_property_set(:authentications_class, Authentication)
|
136
|
+
create_new_external_user(:liveid)
|
137
|
+
get :test_login_from5
|
138
|
+
flash[:notice].should == "Success!"
|
139
|
+
end
|
140
|
+
|
141
|
+
it "'login_from' fails if user doesn't exist (liveid)" do
|
142
|
+
sorcery_model_property_set(:authentications_class, Authentication)
|
143
|
+
create_new_user
|
144
|
+
get :test_login_from5
|
145
|
+
flash[:alert].should == "Failed!"
|
146
|
+
end
|
147
|
+
|
85
148
|
end
|
86
149
|
|
87
150
|
|
@@ -93,13 +156,20 @@ describe ApplicationController do
|
|
93
156
|
before(:all) do
|
94
157
|
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/activation")
|
95
158
|
sorcery_reload!([:user_activation,:external], :user_activation_mailer => ::SorceryMailer)
|
96
|
-
sorcery_controller_property_set(:external_providers, [:facebook, :github])
|
159
|
+
sorcery_controller_property_set(:external_providers, [:facebook, :github, :google, :liveid])
|
97
160
|
sorcery_controller_external_property_set(:facebook, :key, "eYVNBjBDi33aa9GkA3w")
|
98
161
|
sorcery_controller_external_property_set(:facebook, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
|
99
162
|
sorcery_controller_external_property_set(:facebook, :callback_url, "http://blabla.com")
|
100
163
|
sorcery_controller_external_property_set(:github, :key, "eYVNBjBDi33aa9GkA3w")
|
101
164
|
sorcery_controller_external_property_set(:github, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
|
102
165
|
sorcery_controller_external_property_set(:github, :callback_url, "http://blabla.com")
|
166
|
+
sorcery_controller_external_property_set(:google, :key, "eYVNBjBDi33aa9GkA3w")
|
167
|
+
sorcery_controller_external_property_set(:google, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
|
168
|
+
sorcery_controller_external_property_set(:google, :callback_url, "http://blabla.com")
|
169
|
+
sorcery_controller_external_property_set(:liveid, :key, "eYVNBjBDi33aa9GkA3w")
|
170
|
+
sorcery_controller_external_property_set(:liveid, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
|
171
|
+
sorcery_controller_external_property_set(:liveid, :callback_url, "http://blabla.com")
|
172
|
+
|
103
173
|
end
|
104
174
|
|
105
175
|
after(:all) do
|
@@ -138,5 +208,35 @@ describe ApplicationController do
|
|
138
208
|
@user.activate!
|
139
209
|
ActionMailer::Base.deliveries.size.should == old_size
|
140
210
|
end
|
211
|
+
|
212
|
+
# provider: google
|
213
|
+
it "should not send activation email to external users (google)" do
|
214
|
+
old_size = ActionMailer::Base.deliveries.size
|
215
|
+
create_new_external_user(:google)
|
216
|
+
ActionMailer::Base.deliveries.size.should == old_size
|
217
|
+
end
|
218
|
+
|
219
|
+
it "should not send external users an activation success email (google)" do
|
220
|
+
sorcery_model_property_set(:activation_success_email_method_name, nil)
|
221
|
+
create_new_external_user(:google)
|
222
|
+
old_size = ActionMailer::Base.deliveries.size
|
223
|
+
@user.activate!
|
224
|
+
ActionMailer::Base.deliveries.size.should == old_size
|
225
|
+
end
|
226
|
+
|
227
|
+
# provider: liveid
|
228
|
+
it "should not send activation email to external users (liveid)" do
|
229
|
+
old_size = ActionMailer::Base.deliveries.size
|
230
|
+
create_new_external_user(:liveid)
|
231
|
+
ActionMailer::Base.deliveries.size.should == old_size
|
232
|
+
end
|
233
|
+
|
234
|
+
it "should not send external users an activation success email (liveid)" do
|
235
|
+
sorcery_model_property_set(:activation_success_email_method_name, nil)
|
236
|
+
create_new_external_user(:liveid)
|
237
|
+
old_size = ActionMailer::Base.deliveries.size
|
238
|
+
@user.activate!
|
239
|
+
ActionMailer::Base.deliveries.size.should == old_size
|
240
|
+
end
|
141
241
|
end
|
142
242
|
end
|