authlogic 3.6.0 → 3.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c557e744965cb622f19c7b32421c8a6a7d35be45
4
- data.tar.gz: 603d34bc61e526d460501e1417e176d559b2dbcb
3
+ metadata.gz: ee7fbd1206c6811c02b24031d294e7a0e3fa7634
4
+ data.tar.gz: c5e73e04f59d43d50056bc7cff2633d94f85758f
5
5
  SHA512:
6
- metadata.gz: 699ca0bd6ec372e1705e2b74de803026cf04b9a620f17fcceaf88de768639188c5237e2ea876db4725f0002813c22e22752cc1d8b3d3ee36d21dbeed32a0fc1f
7
- data.tar.gz: e70bca58e4aae93d5a8e412a1d774c80331f3fa4b2687e1db07a7c0c366a58b7de1ac97b11b343773ce92ff71337fd08cd906ec7119179dba893ff932ead4202
6
+ metadata.gz: 742e52297bce1666457ccf15415855bb0e29469f43abd62416744f5b2f440cdb739c487a6ffbedb3e9fe7f6c1577f1d9df4d46d9498de35147b5d18c2375da62
7
+ data.tar.gz: 57f380fb34a5f86dbd92558de49f145df515a57c8983e9cbcb5e024b1bc47d47cd5bc979de7861acb1f1e4076a35dc1461d8d7c9356096ee9e2d2e7e8b17942d
@@ -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
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "authlogic"
6
- s.version = "3.6.0"
6
+ s.version = "3.6.1"
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["Ben Johnson"]
9
9
  s.email = ["bjohnson@binarylogic.com"]
@@ -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 mroe than one account.
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
- # sessin with the model id. You just need to tell Authlogic to do this by passing
49
- # this option.
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
@@ -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 - 13 in length.
9
- # The decisions behind this regular expression were made by analyzing the list of top-level domains
10
- # maintained by IANA and by reading this website: http://www.regular-expressions.info/email.html,
11
- # which is an excellent resource for regular expressions.
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,13})'
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,13})'
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 test_scoping
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
- refute binary_logic.user_sessions.find
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
- set_session_for(ben)
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
@@ -1,6 +1,6 @@
1
1
  class Company < ActiveRecord::Base
2
2
  authenticates_many :employee_sessions
3
- authenticates_many :user_sessions
3
+ authenticates_many :user_sessions, scope_cookies: true
4
4
  has_many :employees, :dependent => :destroy
5
5
  has_many :users, :dependent => :destroy
6
6
  end
@@ -199,9 +199,28 @@ class ActiveSupport::TestCase
199
199
  controller.request_content_type = nil
200
200
  end
201
201
 
202
- def set_session_for(user)
203
- controller.session["user_credentials"] = user.persistence_token
204
- controller.session["user_credentials_id"] = user.id
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.0
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-04-28 00:00:00.000000000 Z
11
+ date: 2017-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord