Skip to content

Commit a5ab35b

Browse files
committed
Add tests for LIKE metacharacter escaping (backslash, underscore)
Expand selector_resource_guids filtering tests to cover all three LIKE metacharacters: %, _, and backslash.
1 parent 79f0da9 commit a5ab35b

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

spec/request/access_rules_spec.rb

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,12 +399,28 @@ def expected_rule_json(rule)
399399
end
400400

401401
describe 'filtering by selector_resource_guids' do
402-
it 'does not match unintended rows when guid contains LIKE wildcards' do
402+
it 'escapes % so it does not act as a LIKE wildcard' do
403403
get '/v3/access_rules?selector_resource_guids=%25', nil, admin_header
404404

405405
expect(last_response.status).to eq(200)
406406
parsed = Oj.load(last_response.body)
407-
# Should not match all rows via SQL wildcard; % is escaped
407+
expect(parsed['resources'].length).to eq(0)
408+
end
409+
410+
it 'escapes _ so it does not act as a LIKE single-char wildcard' do
411+
get '/v3/access_rules?selector_resource_guids=cf_app', nil, admin_header
412+
413+
expect(last_response.status).to eq(200)
414+
parsed = Oj.load(last_response.body)
415+
# _ would match any single char (e.g. "cf:app"), but escaped it matches literal "_"
416+
expect(parsed['resources'].length).to eq(0)
417+
end
418+
419+
it 'escapes backslash so it does not act as a LIKE escape character' do
420+
get '/v3/access_rules?selector_resource_guids=cf%5Capp', nil, admin_header
421+
422+
expect(last_response.status).to eq(200)
423+
parsed = Oj.load(last_response.body)
408424
expect(parsed['resources'].length).to eq(0)
409425
end
410426
end

0 commit comments

Comments
 (0)