From 2a6a8b353b361e7539955b458666a90ee7489934 Mon Sep 17 00:00:00 2001 From: Chris Quamme Rhoden Date: Thu, 27 Aug 2020 21:05:50 -0400 Subject: [PATCH 1/3] Automatically stringify keys on index access of ResourceMap --- lib/prx_auth/resource_map.rb | 8 ++++++++ test/prx_auth/resource_map_test.rb | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/lib/prx_auth/resource_map.rb b/lib/prx_auth/resource_map.rb index 505240e..77b915b 100644 --- a/lib/prx_auth/resource_map.rb +++ b/lib/prx_auth/resource_map.rb @@ -37,6 +37,14 @@ def contains?(resource, namespace=nil, scope=nil) end end + def [](key) + super(key.to_s) + end + + def []=(key, value) + super(key.to_s, value) + end + def condense condensed_wildcard = @wildcard.condense condensed_map = Hash[map do |resource, list| diff --git a/test/prx_auth/resource_map_test.rb b/test/prx_auth/resource_map_test.rb index eb821be..d57ad50 100644 --- a/test/prx_auth/resource_map_test.rb +++ b/test/prx_auth/resource_map_test.rb @@ -169,4 +169,17 @@ def new_map(val) assert map.as_json.has_key?('*') end end + + describe '#[]' do + it 'automatically stringifies' do + refute_nil map[123] + end + end + + describe '#[]=' do + it 'automatically stringifies' do + map[789] = PrxAuth::ScopeList.new("") + refute_nil map["789"] + end + end end \ No newline at end of file From 950113ca9223e5e837c994ed0cfed8bde6a3e184 Mon Sep 17 00:00:00 2001 From: Chris Quamme Rhoden Date: Thu, 27 Aug 2020 21:06:12 -0400 Subject: [PATCH 2/3] Correctly recognize equality between ScopeLists --- lib/prx_auth/scope_list.rb | 4 ++++ test/prx_auth/scope_list_test.rb | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/prx_auth/scope_list.rb b/lib/prx_auth/scope_list.rb index da1a7e7..5c398bc 100644 --- a/lib/prx_auth/scope_list.rb +++ b/lib/prx_auth/scope_list.rb @@ -129,6 +129,10 @@ def &(other_list) self - (self - other_list) end + def ==(other) + condense.sort_by(&:to_s) == other.condense.sort_by(&:to_s) + end + private def symbolize(value) diff --git a/test/prx_auth/scope_list_test.rb b/test/prx_auth/scope_list_test.rb index e1b3e17..c2f098b 100644 --- a/test/prx_auth/scope_list_test.rb +++ b/test/prx_auth/scope_list_test.rb @@ -105,4 +105,15 @@ def new_list(val) assert !sl.contains?(:one) end end + + describe '==' do + + it 'is equal when they are functionally equal' do + assert_equal PrxAuth::ScopeList.new("foo ns:foo bar ns2:baz"), PrxAuth::ScopeList.new("ns2:baz bar foo") + end + + it 'is not equal when they are not functionally equal' do + refute_equal PrxAuth::ScopeList.new("foo bar"), PrxAuth::ScopeList.new("foo:bar bar:foo") + end + end end \ No newline at end of file From 86f8d1f7ac04f2ebca6ad98c9861e280719ac96f Mon Sep 17 00:00:00 2001 From: Chris Quamme Rhoden Date: Thu, 27 Aug 2020 21:08:20 -0400 Subject: [PATCH 3/3] Minor version bump --- lib/prx_auth/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/prx_auth/version.rb b/lib/prx_auth/version.rb index 5edadfa..2c4c4bf 100644 --- a/lib/prx_auth/version.rb +++ b/lib/prx_auth/version.rb @@ -1,3 +1,3 @@ module PrxAuth - VERSION = "1.2.1" + VERSION = "1.3.0" end