diff --git a/lib/warden/jwt_auth.rb b/lib/warden/jwt_auth.rb index 4f41e80..5ea4396 100644 --- a/lib/warden/jwt_auth.rb +++ b/lib/warden/jwt_auth.rb @@ -19,6 +19,8 @@ module Warden module JWTAuth extend Dry::Configurable + module_function + def symbolize_keys(hash) hash.transform_keys(&:to_sym) end @@ -36,8 +38,6 @@ def constantize_values(hash) end end - module_function :constantize_values, :symbolize_keys, :upcase_first_items - # The secret used to encode the token setting :secret diff --git a/spec/support/shared_contexts/configuration.rb b/spec/support/shared_contexts/configuration.rb index 2adecf6..b773187 100644 --- a/spec/support/shared_contexts/configuration.rb +++ b/spec/support/shared_contexts/configuration.rb @@ -13,6 +13,7 @@ config.mappings = { user: Fixtures::UserRepo } config.token_header = 'Authorization' config.aud_header = 'TEST_AUD' + config.issuer = 'http://example.com' end end diff --git a/spec/warden/jwt_auth/strategy_spec.rb b/spec/warden/jwt_auth/strategy_spec.rb index a4898c7..89530c6 100644 --- a/spec/warden/jwt_auth/strategy_spec.rb +++ b/spec/warden/jwt_auth/strategy_spec.rb @@ -31,30 +31,25 @@ end end - context 'when issuer is configured' do - let(:token) { Warden::JWTAuth::TokenEncoder.new.call({ issuer: issuer }) } - let(:env) { { 'HTTP_AUTHORIZATION' => "Bearer #{token}" } } - let(:issuer) { 'http://example.com' } - let(:strategy) { described_class.new(env, :user) } + context 'when issuer claim is configured and it matches the configured issuer' do + it 'returns true' do + token = Warden::JWTAuth::TokenEncoder.new.call({ 'iss' => Warden::JWTAuth.config.issuer }) + env = { 'HTTP_AUTHORIZATION' => "Bearer #{token}" } - before do - Warden::JWTAuth.configure do |config| - config.issuer = issuer - end - end + strategy = described_class.new(env, :user) - context 'when the issuer claim matches the configured issuer' do - it 'returns true' do - expect(strategy).to be_valid - end + expect(strategy).to be_valid end + end - context 'when the issuer claim does not match the configured issuer' do - let(:token) { Warden::JWTAuth::TokenEncoder.new.call({ 'iss' => 'http://example.org' }) } + context "when issuer claim is configured and it doesn't match the configured issuer" do + it 'returns false' do + token = Warden::JWTAuth::TokenEncoder.new.call({ 'iss' => Warden::JWTAuth.config.issuer + 'aaa' }) + env = { 'HTTP_AUTHORIZATION' => "Bearer #{token}" } - it 'returns false' do - expect(strategy).not_to be_valid - end + strategy = described_class.new(env, :user) + + expect(strategy).not_to be_valid end end end