Skip to content

Commit

Permalink
Ignore empty refresh tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
tuwukee committed May 5, 2023
1 parent 3770354 commit 3db3814
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/jwt_sessions/store_adapters/redis_store_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ def all_refresh_tokens(namespace)
# to be able to properly initialize namespaced tokens extract their namespaces
# and pass down to fetch_refresh
token_namespace = namespace.to_s.empty? ? namespace_from_key(key) : namespace
acc[uid] = fetch_refresh(uid, token_namespace)
token_attrs = fetch_refresh(uid, token_namespace)
acc[uid] = token_attrs unless token_attrs.empty?
end
end

Expand Down
10 changes: 10 additions & 0 deletions test/units/jwt_sessions/test_session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,16 @@ def test_refresh_after_flush_namespaced_access_tokens
assert_equal access_token.expiration.to_s, refresh_token.access_expiration
end

def test_flush_namespaced_access_tokens_after_flush_namespaced
namespace = "test_namespace"
session = JWTSessions::Session.new(payload: payload, namespace: namespace)
session.login

assert_equal 1, session.flush_namespaced
# it should not throw an error
assert_equal 0, session.flush_namespaced_access_tokens
end

def test_flush_all
refresh_token = @session.instance_variable_get(:"@_refresh")
flushed_count = JWTSessions::Session.flush_all
Expand Down

0 comments on commit 3db3814

Please sign in to comment.