simple_auth 3.1.0 → 3.1.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
  SHA256:
3
- metadata.gz: ba465a655d4336e0e400a40306644584f5dc0e9fd1be216272d12f9326e01467
4
- data.tar.gz: d92099b4d135f1e36c195996c14972ff6ad55e20c1d3e7d920909c3b525b11c5
3
+ metadata.gz: 4c6838ee76a4171f9949a217cb1071c3e419ff11b1c0bbf577ea05239ae2abb9
4
+ data.tar.gz: 84b753d0a73b218d694ec8cbce6159997a44d73c6c44f9b8338fdfbb67c8a734
5
5
  SHA512:
6
- metadata.gz: cbe00d05c29d18d067f4decc46ab3cd1a70d72cb6e8e6bd42f16f9601b4dea552f5b6b2d6504632b4a49f01458f9e313bfa60ee65785d019c7aadb2bd86b66da
7
- data.tar.gz: 71c868b0d198cf63139168545155eabe87f23cd4558f8f11e289a29917bca7fc196c6ce158a2da10c30d8922599889f9f8ed821e1872f5ea3d43c76d3fca2ba0
6
+ metadata.gz: 8f605bdc0caad8f2c605116a1e9c293dce9ff24fd45ef63abae8084b4cc7959d94a61691df43796fa14fb2e49efcddb519cf9f20ed3172511bc0062d3ed692f2
7
+ data.tar.gz: b40738c8f921ffd2bbd0a865948f816e6cf5ae125e7810a443d37a5925101bf4d03e3b55f35ca9ade4ce7003cddd1cd3fb576299ff0b8314a337e609d6b740e6
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # v3.1.1
2
+
3
+ - Catch exceptions related to record not found when session tries to load a
4
+ record from session. You can customize the recognized exceptions by adding the
5
+ error class to `SimpleAuth::Session.record_not_found_exceptions`.
6
+
1
7
  # v3.1.0
2
8
 
3
9
  - SimpleAuth now uses [GlobalID](https://github.com/rails/globalid) as the
data/README.md CHANGED
@@ -95,6 +95,14 @@ session[:user_id]
95
95
  If you need to locate a record using such value, you can do it by calling
96
96
  `GlobalID::Locator.locate(session[:user_id])`
97
97
 
98
+ Finally, only `ActiveRecord::RecordNotFound` errors are trapped by SimpleAuth
99
+ (when ActiveRecord is available). If you locator raises a different exception,
100
+ add the error class to the list of known exceptions.
101
+
102
+ ```ruby
103
+ SimpleAuth::Session.record_not_found_exceptions << CustomNotFoundRecordError
104
+ ```
105
+
98
106
  ### Logging out users
99
107
 
100
108
  Logging out a user is just as simple; all you have to do is calling the regular
@@ -5,5 +5,12 @@ module SimpleAuth
5
5
  generators do
6
6
  require "simple_auth/generator"
7
7
  end
8
+
9
+ config.after_initialize do
10
+ ActiveSupport.on_load(:active_record) do
11
+ SimpleAuth::Session.record_not_found_exceptions <<
12
+ ActiveRecord::RecordNotFound
13
+ end
14
+ end
8
15
  end
9
16
  end
@@ -2,6 +2,10 @@
2
2
 
3
3
  module SimpleAuth
4
4
  class Session
5
+ def self.record_not_found_exceptions
6
+ @record_not_found_exceptions ||= []
7
+ end
8
+
5
9
  def self.create(**kwargs)
6
10
  new(**kwargs)
7
11
  end
@@ -21,6 +25,8 @@ module SimpleAuth
21
25
  return unless record_id_from_session
22
26
 
23
27
  @record ||= GlobalID::Locator.locate(record_id_from_session)
28
+ rescue *Session.record_not_found_exceptions
29
+ nil
24
30
  end
25
31
 
26
32
  def record_key
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SimpleAuth
4
- VERSION = "3.1.0"
4
+ VERSION = "3.1.1"
5
5
  end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class SessionTest < Minitest::Test
6
+ test "returns nil for missing gid" do
7
+ User.delete_all
8
+ user = User.create!(password: "test", email: "john@example.com")
9
+ session_store = {}
10
+
11
+ SimpleAuth::Session.create(
12
+ scope: "user",
13
+ record: user,
14
+ session: session_store
15
+ )
16
+
17
+ user.destroy!
18
+
19
+ session = SimpleAuth::Session.create(
20
+ scope: "user",
21
+ session: session_store
22
+ )
23
+
24
+ assert_nil session.record
25
+ end
26
+
27
+ test "returns nil for missing gid (custom error)" do
28
+ not_found_error = Class.new(StandardError)
29
+ SimpleAuth::Session.record_not_found_exceptions << not_found_error
30
+
31
+ GlobalID::Locator.use :foo do |gid|
32
+ raise not_found_error, "record not found: #{gid}"
33
+ end
34
+
35
+ session = SimpleAuth::Session.create(
36
+ scope: "user",
37
+ session: {user_id: "gid://foo/User/1234"}
38
+ )
39
+
40
+ assert_nil session.record
41
+ end
42
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-08 00:00:00.000000000 Z
11
+ date: 2020-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: globalid
@@ -207,6 +207,7 @@ files:
207
207
  - test/support/dummy/config/routes.rb
208
208
  - test/support/schema.rb
209
209
  - test/test_helper.rb
210
+ - test/unit/session_test.rb
210
211
  homepage: http://rubygems.org/gems/simple_auth
211
212
  licenses: []
212
213
  metadata: {}
@@ -244,3 +245,4 @@ test_files:
244
245
  - test/support/dummy/config/routes.rb
245
246
  - test/support/schema.rb
246
247
  - test/test_helper.rb
248
+ - test/unit/session_test.rb