-
Notifications
You must be signed in to change notification settings - Fork 991
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #37978 - CVE-2024-8553 - Forbid strings as loader macros argument
- Loading branch information
1 parent
e83f674
commit 717f444
Showing
2 changed files
with
66 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
test/unit/foreman/renderer/scope/macros/loader_macros_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require 'test_helper' | ||
|
||
class LoaderMacrosTest < ActiveSupport::TestCase | ||
setup do | ||
host = FactoryBot.build_stubbed(:host) | ||
template = OpenStruct.new( | ||
name: 'Test', | ||
template: 'Test' | ||
) | ||
source = Foreman::Renderer::Source::Database.new( | ||
template | ||
) | ||
@scope = Class.new(Foreman::Renderer::Scope::Base) do | ||
include Foreman::Renderer::Scope::Macros::Base | ||
end.send(:new, source: source) | ||
end | ||
|
||
describe '#load_resources' do | ||
it 'should accept custom selects' do | ||
@scope.load_hosts(select: :id) | ||
@scope.load_hosts(select: [:id, :name]) | ||
end | ||
|
||
it 'should reject unacceptable selects' do | ||
assert_raises(ArgumentError) { @scope.load_hosts(select: 'a string value') } | ||
assert_raises(ArgumentError) { @scope.load_hosts(select: {:key => :value}) } | ||
assert_raises(ArgumentError) { @scope.load_hosts(select: [:mixed, 'array']) } | ||
error = assert_raises(ArgumentError) { @scope.load_hosts(select: 7) } | ||
assert_match /Value of 'select'/, error.message | ||
assert_match /load_hosts/, error.message | ||
assert_match /Symbol or Array of Symbols/, error.message | ||
end | ||
|
||
it 'should accept custom joins' do | ||
@scope.load_hosts(joins: :interfaces) | ||
@scope.load_hosts(joins: {:interfaces => :subnet}) | ||
@scope.load_hosts(joins: [:interfaces, :domain]) | ||
end | ||
|
||
it 'should reject unacceptable joins' do | ||
assert_raises(ArgumentError) { @scope.load_hosts(joins: 'a string value') } | ||
assert_raises(ArgumentError) { @scope.load_hosts(joins: [:mixed, 'array']) } | ||
error = assert_raises(ArgumentError) { @scope.load_hosts(joins: 7) } | ||
assert_match /Value of 'joins'/, error.message | ||
assert_match /load_hosts/, error.message | ||
assert_match /Symbol, Hash or Array of Symbols/, error.message | ||
end | ||
end | ||
end |