Skip to content

Commit

Permalink
Merge pull request #121 from kluein/main
Browse files Browse the repository at this point in the history
fix: allow attribute names starting with operator chars to be filtered
  • Loading branch information
pond authored Jun 12, 2024
2 parents 33c3ad9 + f503008 commit ea10c4e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/models/scimitar/lists/query_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class QueryParser

PAREN = /[\(\)]/.freeze
STR = /"(?:\\"|[^"])*"/.freeze
OP = /#{OPERATORS.keys.join('|')}/i.freeze
OP = /(?:#{OPERATORS.keys.join('|')})\b/i.freeze
WORD = /[\w\.]+/.freeze
SEP = /\s?/.freeze
NEXT_TOKEN = /\A(#{PAREN}|#{STR}|#{OP}|#{WORD})#{SEP}/.freeze
Expand Down
9 changes: 8 additions & 1 deletion spec/apps/dummy/app/models/mock_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def self.scim_attributes_map
#
organization: :organization,
department: :department,
primaryEmail: :scim_primary_email,
userGroups: [
{
list: :mock_groups,
Expand Down Expand Up @@ -124,9 +125,15 @@ def self.scim_queryable_attributes
'groups.value' => { column: MockGroup.arel_table[:id] },
'emails' => { columns: [ :work_email_address, :home_email_address ] },
'emails.value' => { columns: [ :work_email_address, :home_email_address ] },
'emails.type' => { ignore: true } # We can't filter on that; it'll just search all e-mails
'emails.type' => { ignore: true }, # We can't filter on that; it'll just search all e-mails
'primaryEmail' => { column: :scim_primary_email },
}
end

# reader
def scim_primary_email
work_email_address
end

include Scimitar::Resources::Mixin
end
3 changes: 2 additions & 1 deletion spec/apps/dummy/config/initializers/scimitar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def self.id
def self.scim_attributes
[
Scimitar::Schema::Attribute.new(name: 'organization', type: 'string'),
Scimitar::Schema::Attribute.new(name: 'department', type: 'string')
Scimitar::Schema::Attribute.new(name: 'department', type: 'string'),
Scimitar::Schema::Attribute.new(name: 'primaryEmail', type: 'string'),
]
end
end
Expand Down
9 changes: 9 additions & 0 deletions spec/models/scimitar/lists/query_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@
expect(%Q("O'Malley")).to eql(tree[2])
end

it "extended attribute equals" do
@instance.parse(%Q(primaryEmail eq "foo@bar.com"))

rpn = @instance.rpn
expect('primaryEmail').to eql(rpn[0])
expect(%Q("foo@bar.com")).to eql(rpn[1])
expect('eq').to eql(rpn[2])
end

it "user name starts with" do
@instance.parse(%Q(userName sw "J"))

Expand Down
3 changes: 2 additions & 1 deletion spec/models/scimitar/resources/mixin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ def self.scim_queryable_attributes

'urn:ietf:params:scim:schemas:extension:enterprise:2.0:User' => {
'organization' => 'SOMEORG',
'department' => nil
'department' => nil,
'primaryEmail' => instance.work_email_address
}
})
end
Expand Down

0 comments on commit ea10c4e

Please sign in to comment.