Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ONYX-41894 : Fix exclude - not exclude sub string in recourse name #2864

Open
wants to merge 1 commit into
base: conjur-cloud
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/models/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def search account: nil, kind: nil, owner: nil, offset: nil, limit: nil, search:
exclude = exclude.split(',')
exclude.each do |item|
# scope is exclude when the resource id is like the item
scope = scope.exclude(Sequel.like(:resource_id, "%#{item}%"))
# client who gives exclude param should write the prefix id just after the account
scope = scope.exclude(Sequel.like(:resource_id, "#{account}"+":#{item}%"))
end
end

Expand Down
26 changes: 18 additions & 8 deletions cucumber/api/features/resource_list.feature
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ Feature: List resources with various types of filtering
cucumber:user:alice successfully listed resources with parameters: {:account=>"cucumber", :kind=>"test-resource", :count=>"true"}
"""

################
# exclude param
################

@acceptance
Scenario: The resource list is excluded for all directories.
Given I create a new resource called "target-resource-0"
Expand All @@ -235,7 +239,7 @@ Feature: List resources with various types of filtering
@acceptance
Scenario: The resource list is excluded for a specific directory.
Given I create a new resource called "target-resource-0"
When I successfully GET "/resources/cucumber/test-resource?exclude=target-resource-0"
When I successfully GET "/resources/cucumber/test-resource?exclude=test-resource:target-resource-0"
Then the resource list should not include the newest resource

@acceptance
Expand All @@ -249,7 +253,7 @@ Feature: List resources with various types of filtering
Given I create a new resource called "target-resource-0"
And I create a new resource called "target-resource-1"
And I create a new resource called "target-resource-2"
When I successfully GET "/resources/cucumber/test-resource?exclude=target-resource-0,target-resource-1,target-resource-2"
When I successfully GET "/resources/cucumber/test-resource?exclude=test-resource:target-resource-0,test-resource:target-resource-1,test-resource:target-resource-2"
Then I receive 3 resources

@acceptance
Expand All @@ -265,7 +269,7 @@ Feature: List resources with various types of filtering
And I create a new resource called "target-resource-1"
And I create a new resource called "target-resource-2"
# resources created, either in background and this scenario, are under test-resource directory
When I successfully GET "/resources/cucumber/test-resource?exclude=test-resource,target-resource-0"
When I successfully GET "/resources/cucumber/test-resource?exclude=test-resource,test-resource:target-resource-0"
Then the result is empty

@acceptance
Expand All @@ -276,20 +280,26 @@ Feature: List resources with various types of filtering

@acceptance
Scenario: The resource list is excluded for special-character directory.
Given I create a new resource called "target-resource-./:;<=>?_`{|}]'()*+,-@#"
When I successfully GET "/resources/cucumber/test-resource?exclude=resource-./:;<=>?_`{|}]'()*+,-@#"
Given I create a new resource called "resource-./:;<=>?_`{|}]'()*+,-@#"
When I successfully GET "/resources/cucumber/test-resource?exclude=test-resource:resource-./:;<=>?_`{|}]'()*+,-@#"
Then the resource list should not include the newest resource

@acceptance
Scenario: The resource list is excluded and search a resource.
Given I create a new resource called "target-resource-0"
And I create a new resource called "find-me"
When I successfully GET "/resources/cucumber/test-resource?exclude=target-resource-0&search=find-me"
When I successfully GET "/resources/cucumber/test-resource?exclude=test-resource:target-resource-0&search=find-me"
Then the resource list should include the newest resource

@acceptance
Scenario: The resource list is excluded and search a resource.
Given I create a new resource called "target-resource-0"
And I create a new resource called "find-me"
When I successfully GET "/resources/cucumber/test-resource?exclude=target-resource-0&search=target-resource-0"
Then the result is empty
When I successfully GET "/resources/cucumber/test-resource?exclude=test-resource:target-resource-0&search=test-resource:target-resource-0"
Then the result is empty

@acceptance
Scenario: The resource list is not excluded for sub string input of a resource.
Given I create a new resource called "target-resource-0"
When I successfully GET "/resources/cucumber/test-resource?exclude=resource"
Then the resource list should be include the all resources