Skip to content

fix: double quotes will be trimmed from the search token - #8035

Merged
rhafer merged 3 commits into
masterfrom
fix/graph_double_quote_handling
Dec 20, 2023
Merged

rhafer merged 3 commits into
masterfrom
fix/graph_double_quote_handling

Conversation

@jvillafanez

Copy link
Copy Markdown
Member

Description

Search terms from the graph API can be enclosed with double quotes. The double quotes are intended to prevent the interpretation of some tokens from the parser. However, the parser doesn't remove the double quotes.
This PR will remove those double quotes.

As a practical example, searching by email (such as [email protected]) can give problems because the @ char is interpreted as a different token (likely as a parameter alias, although I'm not fully sure). With this PR, you can search it by enclosing the email in double quotes, like $search="[email protected]" (note that url-encoding might be needed)

Related Issue

#7990

Motivation and Context

Allow searching users by email

How Has This Been Tested?

Manually tested via API, running something like curl -vk -ueinstein:relativity https://localhost:9200/graph/v1.0/users?%24search=%22marie%40example.org%22

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • Tests only (no source changes)

Checklist:

  • Code changes
  • Unit tests added
  • Acceptance tests added
  • Documentation ticket raised:

@jvillafanez jvillafanez self-assigned this Dec 20, 2023
@update-docs

update-docs Bot commented Dec 20, 2023

Copy link
Copy Markdown

Thanks for opening this pull request! The maintainers of this repository would appreciate it if you would create a changelog item based on your changes.

@rhafer rhafer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. Just a minor nitpick. Feel free to ignore.

Comment thread services/graph/pkg/identity/odata.go Outdated
searchValue := req.Search.Tree.Token.Value
if strings.HasPrefix(searchValue, "\"") && strings.HasSuffix(searchValue, "\"") {
searchValue = strings.Trim(searchValue, "\"")
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: I guess in this case you can just call strings.Trim unconditionally. There is no need for the HasPrefix and HasSuffix calls. Or am I missing something?

The OData parser will already choke on strings that only contain a single double quote.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The OData parser will already choke on strings that only contain a single double quote.

I thought it was still possible. I'll remove the condition.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How are we dealing the same with single quotes?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think single quotes have a completely different meaning here and are handled by the OData parser. In this case, as far as I understand the odata specs, using single quotes here won't even work. (our parsers doesn't allow it here at least https://github.com/CiscoM31/godata)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does a user (the one who is on the keyboard...) know this difference...?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The user shouldn't need to worry about quoting at all.

The UI/client which is constructing the query should know the difference, yes.

@rhafer rhafer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, actually I think I overlooked something. We still have minimum search length check in https://github.com/owncloud/ocis/blob/master/services/graph/pkg/service/v0/users.go#L226.
Where check of the length of the possibly quoted string. I think we need to adjust that. Otherwise it would be simple to circumvent that limit (or at least reduce it by 2) by just adding quotes.

@jvillafanez
jvillafanez force-pushed the fix/graph_double_quote_handling branch from cb78ef4 to 70f2e75 Compare December 20, 2023 15:06
@jvillafanez

Copy link
Copy Markdown
Member Author

Refactored the code a bit. The tests should pass now.
I'll manually retest the code just to make sure it works with the changes.

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Passed Quality Gate passed

The SonarCloud Quality Gate passed, but some issues were introduced.

2 New issues
0 Security Hotspots
54.5% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

@jvillafanez

Copy link
Copy Markdown
Member Author

I'll manually retest the code just to make sure it works with the changes.

Checked. Looks good now.

@rhafer
rhafer merged commit 1bcc559 into master Dec 20, 2023
@delete-merged-branch
delete-merged-branch Bot deleted the fix/graph_double_quote_handling branch December 20, 2023 16:24
@micbar

micbar commented Dec 20, 2023 •

Copy link
Copy Markdown
Contributor

I would love it to see a unit test for that 😍

@rhafer

rhafer commented Dec 21, 2023

Copy link
Copy Markdown
Contributor

I would love it to see a unit test for that 😍

They are part of #8050 now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants