Skip to content

Commit

Permalink
Bugfix: maintain dashes and case during scope arithmetic
Browse files Browse the repository at this point in the history
  • Loading branch information
cqr committed Aug 11, 2020
1 parent 7dd5545 commit eb3f724
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
24 changes: 12 additions & 12 deletions lib/prx_auth/scope_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,15 @@ class ScopeList < Array
NAMESPACE_SEPARATOR = ':'
NO_NAMESPACE = :_

Entry = Struct.new(:namespace, :scope)
Entry = Struct.new(:namespace, :scope, :string)

class Entry
def equal?(other_entry)
def ==(other_entry)
namespace == other_entry.namespace && scope == other_entry.scope
end

def to_s
if namespaced?
"#{namespace}:#{scope}"
else
scope.to_s
end
string
end

def namespaced?
Expand All @@ -25,11 +21,15 @@ def namespaced?

def unnamespaced
if namespaced?
Entry.new(NO_NAMESPACE, scope)
Entry.new(NO_NAMESPACE, scope, string.split(':').last)
else
self
end
end

def inspect
"#<ScopeList::Entry \"#{to_s}\">"
end
end

def self.new(list)
Expand All @@ -47,21 +47,21 @@ def initialize(list)

parts = value.split(NAMESPACE_SEPARATOR, 2)
if parts.length == 2
push Entry.new(symbolize(parts[0]), symbolize(parts[1]))
push Entry.new(symbolize(parts[0]), symbolize(parts[1]), value)
else
push Entry.new(NO_NAMESPACE, symbolize(parts[0]))
push Entry.new(NO_NAMESPACE, symbolize(parts[0]), value)
end
end
end

def contains?(namespace, scope=nil)
entries = if scope.nil?
scope, namespace = namespace, NO_NAMESPACE
[Entry.new(namespace, symbolize(scope))]
[Entry.new(namespace, symbolize(scope), nil)]
else
scope = symbolize(scope)
namespace = symbolize(namespace)
[Entry.new(namespace, scope), Entry.new(NO_NAMESPACE, scope)]
[Entry.new(namespace, scope, nil), Entry.new(NO_NAMESPACE, scope, nil)]
end

entries.any? do |possible_match|
Expand Down
2 changes: 1 addition & 1 deletion lib/prx_auth/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module PrxAuth
VERSION = "1.2.0"
VERSION = "1.2.1"
end
9 changes: 9 additions & 0 deletions test/prx_auth/scope_list_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,17 @@ def new_list(val)
sl = new_list('one two') - nil
assert sl.contains?(:one) && sl.contains?(:two)
end

it 'maintains dashes and capitalization in the result' do
sl = new_list('The-Beginning the-middle the-end') - new_list('the-Middle')
assert sl.to_s == 'The-Beginning the-end'
end

end




describe '#+' do
it 'adds scopes' do
sl = new_list('one') + new_list('two')
Expand Down

0 comments on commit eb3f724

Please sign in to comment.