authlogic 3.6.0 → 3.6.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/authlogic.gemspec +1 -1
- data/lib/authlogic/authenticates_many/association.rb +4 -0
- data/lib/authlogic/authenticates_many/base.rb +5 -4
- data/lib/authlogic/regex.rb +7 -6
- data/test/acts_as_authentic_test/email_test.rb +4 -2
- data/test/authenticates_many_test.rb +21 -6
- data/test/libs/company.rb +1 -1
- data/test/test_helper.rb +22 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee7fbd1206c6811c02b24031d294e7a0e3fa7634
|
4
|
+
data.tar.gz: c5e73e04f59d43d50056bc7cff2633d94f85758f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 742e52297bce1666457ccf15415855bb0e29469f43abd62416744f5b2f440cdb739c487a6ffbedb3e9fe7f6c1577f1d9df4d46d9498de35147b5d18c2375da62
|
7
|
+
data.tar.gz: 57f380fb34a5f86dbd92558de49f145df515a57c8983e9cbcb5e024b1bc47d47cd5bc979de7861acb1f1e4076a35dc1461d8d7c9356096ee9e2d2e7e8b17942d
|
data/CHANGELOG.md
CHANGED
@@ -11,6 +11,19 @@
|
|
11
11
|
* Fixed
|
12
12
|
* None
|
13
13
|
|
14
|
+
## 3.6.1 2017-09-30
|
15
|
+
|
16
|
+
* Breaking Changes
|
17
|
+
* None
|
18
|
+
|
19
|
+
* Added
|
20
|
+
* None
|
21
|
+
|
22
|
+
* Fixed
|
23
|
+
* Allow tld up to 24 characters per https://data.iana.org/TLD/tlds-alpha-by-domain.txt
|
24
|
+
* [#561](https://github.com/binarylogic/authlogic/issues/561)
|
25
|
+
authenticates_many now works with scope_cookies:true
|
26
|
+
|
14
27
|
## 3.6.0 2017-04-28
|
15
28
|
|
16
29
|
* Added
|
data/authlogic.gemspec
CHANGED
@@ -19,6 +19,10 @@ module Authlogic
|
|
19
19
|
class Association
|
20
20
|
attr_accessor :klass, :find_options, :id
|
21
21
|
|
22
|
+
# - id: Usually `nil`, but if the `scope_cookies` option is used, then
|
23
|
+
# `id` is a string like "company_123". It may seem strange to refer
|
24
|
+
# to such a string as an "id", but the naming is intentional, and
|
25
|
+
# is derived from `Authlogic::Session::Id`.
|
22
26
|
def initialize(klass, find_options, id)
|
23
27
|
self.klass = klass
|
24
28
|
self.find_options = find_options
|
@@ -43,17 +43,18 @@ module Authlogic
|
|
43
43
|
# * <tt>scope_cookies:</tt> default: false
|
44
44
|
# By the nature of cookies they scope themselves if you are using subdomains to
|
45
45
|
# access accounts. If you aren't using subdomains you need to have separate
|
46
|
-
# cookies for each account, assuming a user is logging into
|
46
|
+
# cookies for each account, assuming a user is logging into more than one account.
|
47
47
|
# Authlogic can take care of this for you by prefixing the name of the cookie and
|
48
|
-
#
|
49
|
-
#
|
48
|
+
# session with the model id. Because it affects both cookies names and session keys,
|
49
|
+
# the name `scope_cookies` is misleading. Perhaps simply `scope` or `scoped`
|
50
|
+
# would have been better.
|
50
51
|
def authenticates_many(name, options = {})
|
51
52
|
options[:session_class] ||= name.to_s.classify.constantize
|
52
53
|
options[:relationship_name] ||= options[:session_class].klass_name.underscore.pluralize
|
53
54
|
class_eval <<-"end_eval", __FILE__, __LINE__
|
54
55
|
def #{name}
|
55
56
|
find_options = #{options[:find_options].inspect} || #{options[:relationship_name]}.where(nil)
|
56
|
-
@#{name} ||= Authlogic::AuthenticatesMany::Association.new(#{options[:session_class]}, find_options, #{options[:scope_cookies] ? "self.class.model_name.underscore + '_' + self.send(self.class.primary_key).to_s" : "nil"})
|
57
|
+
@#{name} ||= Authlogic::AuthenticatesMany::Association.new(#{options[:session_class]}, find_options, #{options[:scope_cookies] ? "self.class.model_name.name.underscore + '_' + self.send(self.class.primary_key).to_s" : "nil"})
|
57
58
|
end
|
58
59
|
end_eval
|
59
60
|
end
|
data/lib/authlogic/regex.rb
CHANGED
@@ -5,15 +5,16 @@ module Authlogic
|
|
5
5
|
#
|
6
6
|
# validates_format_of :my_email_field, :with => Authlogic::Regex.email
|
7
7
|
module Regex
|
8
|
-
# A general email regular expression. It allows top level domains (TLD) to be from 2 -
|
9
|
-
# The decisions behind this regular expression were made by analyzing
|
10
|
-
# maintained by IANA and by reading this website:
|
11
|
-
# which is an excellent resource for
|
8
|
+
# A general email regular expression. It allows top level domains (TLD) to be from 2 -
|
9
|
+
# 24 in length. The decisions behind this regular expression were made by analyzing
|
10
|
+
# the list of top-level domains maintained by IANA and by reading this website:
|
11
|
+
# http://www.regular-expressions.info/email.html, which is an excellent resource for
|
12
|
+
# regular expressions.
|
12
13
|
def self.email
|
13
14
|
@email_regex ||= begin
|
14
15
|
email_name_regex = '[A-Z0-9_\.&%\+\-\']+'
|
15
16
|
domain_head_regex = '(?:[A-Z0-9\-]+\.)+'
|
16
|
-
domain_tld_regex = '(?:[A-Z]{2,
|
17
|
+
domain_tld_regex = '(?:[A-Z]{2,25})'
|
17
18
|
/\A#{email_name_regex}@#{domain_head_regex}#{domain_tld_regex}\z/i
|
18
19
|
end
|
19
20
|
end
|
@@ -33,7 +34,7 @@ module Authlogic
|
|
33
34
|
@email_nonascii_regex ||= begin
|
34
35
|
email_name_regex = '[^[:cntrl:][@\[\]\^ \!\"#$\(\)*,/:;<=>\?`{|}~\\\]]+'
|
35
36
|
domain_head_regex = '(?:[^[:cntrl:][@\[\]\^ \!\"#$&\(\)*,/:;<=>\?`{|}~\\\_\.%\+\']]+\.)+'
|
36
|
-
domain_tld_regex = '(?:[^[:cntrl:][@\[\]\^ \!\"#$&\(\)*,/:;<=>\?`{|}~\\\_\.%\+\-\'0-9]]{2,
|
37
|
+
domain_tld_regex = '(?:[^[:cntrl:][@\[\]\^ \!\"#$&\(\)*,/:;<=>\?`{|}~\\\_\.%\+\-\'0-9]]{2,25})'
|
37
38
|
/\A#{email_name_regex}@#{domain_head_regex}#{domain_tld_regex}\z/
|
38
39
|
end
|
39
40
|
end
|
@@ -8,7 +8,8 @@ module ActsAsAuthenticTest
|
|
8
8
|
"damien+test1...etc..@mydomain.com",
|
9
9
|
"dakota.dux+1@gmail.com",
|
10
10
|
"dakota.d'ux@gmail.com",
|
11
|
-
"a&b@c.com"
|
11
|
+
"a&b@c.com",
|
12
|
+
"someuser@somedomain.travelersinsurance"
|
12
13
|
]
|
13
14
|
|
14
15
|
BAD_ASCII_EMAILS = [
|
@@ -16,7 +17,8 @@ module ActsAsAuthenticTest
|
|
16
17
|
"aaaaaaaaaaaaa",
|
17
18
|
"question?mark@gmail.com",
|
18
19
|
"backslash@g\\mail.com",
|
19
|
-
"<script>alert(123);</script>\nnobody@example.com"
|
20
|
+
"<script>alert(123);</script>\nnobody@example.com",
|
21
|
+
"someuser@somedomain.isreallytoolongandimeanreallytoolong"
|
20
22
|
]
|
21
23
|
|
22
24
|
# http://en.wikipedia.org/wiki/ISO/IEC_8859-1#Codepage_layout
|
@@ -1,16 +1,31 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class AuthenticatesManyTest < ActiveSupport::TestCase
|
4
|
-
def
|
5
|
-
zack = users(:zack)
|
6
|
-
ben = users(:ben)
|
4
|
+
def test_employee_sessions
|
7
5
|
binary_logic = companies(:binary_logic)
|
8
|
-
set_session_for(zack)
|
9
6
|
|
10
|
-
|
7
|
+
# Drew is a binary_logic employee, authentication succeeds
|
8
|
+
drew = employees(:drew)
|
9
|
+
set_session_for(drew)
|
10
|
+
assert binary_logic.employee_sessions.find
|
11
|
+
|
12
|
+
# Jennifer is not a binary_logic employee, authentication fails
|
13
|
+
jennifer = employees(:jennifer)
|
14
|
+
set_session_for(jennifer)
|
15
|
+
refute binary_logic.employee_sessions.find
|
16
|
+
end
|
11
17
|
|
12
|
-
|
18
|
+
def test_user_sessions
|
19
|
+
binary_logic = companies(:binary_logic)
|
13
20
|
|
21
|
+
# Ben is a binary_logic user, authentication succeeds
|
22
|
+
ben = users(:ben)
|
23
|
+
set_session_for(ben, binary_logic)
|
14
24
|
assert binary_logic.user_sessions.find
|
25
|
+
|
26
|
+
# Zack is not a binary_logic user, authentication fails
|
27
|
+
zack = users(:zack)
|
28
|
+
set_session_for(zack, binary_logic)
|
29
|
+
refute binary_logic.user_sessions.find
|
15
30
|
end
|
16
31
|
end
|
data/test/libs/company.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -199,9 +199,28 @@ class ActiveSupport::TestCase
|
|
199
199
|
controller.request_content_type = nil
|
200
200
|
end
|
201
201
|
|
202
|
-
def
|
203
|
-
|
204
|
-
|
202
|
+
def session_credentials_prefix(scope_record)
|
203
|
+
if scope_record.nil?
|
204
|
+
""
|
205
|
+
else
|
206
|
+
format(
|
207
|
+
"%s_%d_",
|
208
|
+
scope_record.class.model_name.name.underscore,
|
209
|
+
scope_record.id
|
210
|
+
)
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
# Sets the session variables that `record` (eg. a `User`) would have after
|
215
|
+
# logging in.
|
216
|
+
#
|
217
|
+
# If `record` belongs to an `authenticates_many` association that uses the
|
218
|
+
# `scope_cookies` option, then a `scope_record` can be provided.
|
219
|
+
def set_session_for(record, scope_record = nil)
|
220
|
+
prefix = session_credentials_prefix(scope_record)
|
221
|
+
record_class_name = record.class.model_name.name.underscore
|
222
|
+
controller.session["#{prefix}#{record_class_name}_credentials"] = record.persistence_token
|
223
|
+
controller.session["#{prefix}#{record_class_name}_credentials_id"] = record.id
|
205
224
|
end
|
206
225
|
|
207
226
|
def unset_session
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: authlogic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.6.
|
4
|
+
version: 3.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Johnson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|