Skip to content

Commit

Permalink
Fixes #38006 - Allow extension of list of packages
Browse files Browse the repository at this point in the history
with scap contents
  • Loading branch information
adamruzicka committed Nov 12, 2024
1 parent 02f6bba commit adab592
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
19 changes: 12 additions & 7 deletions lib/foreman_openscap/bulk_upload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,26 @@ def initialize
@result = OpenStruct.new(:errors => [], :results => [])
end

def files_from_guide
`rpm -ql scap-security-guide | grep ds.xml`.split
def security_guide_packages
%w(scap-security-guide)
end

def scap_guide_installed?
`rpm -qa | grep scap-security-guide`.present?
def files_from_guide(package)
`rpm -ql #{package} | grep ds.xml`.split
end

def package_installed?(package)
`rpm -qa | grep #{package}`.present?
end

def upload_from_scap_guide
unless scap_guide_installed?
@result.errors.push(_("Can't find scap-security-guide RPM, are you sure it is installed on your server?"))
package = security_guide_packages.find { |p| package_installed? p }
unless package
@result.errors.push(_("Can't find #{security_guide_packages.join(' or ')} RPM(s), are you sure it is installed on your server?"))
return @result
end

upload_from_files(files_from_guide, true)
upload_from_files(files_from_guide(package), true)
end

def upload_from_files(files_array, from_scap_guide = false)
Expand Down
2 changes: 1 addition & 1 deletion test/lib/foreman_openscap/bulk_upload_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class BulkUploadTest < ActiveSupport::TestCase
upload = ForemanOpenscap::BulkUpload.new
upload.stubs(:scap_guide_installed?).returns(false)
res = upload.upload_from_scap_guide
assert_equal "Can't find scap-security-guide RPM, are you sure it is installed on your server?", res.errors.first
assert_equal "Can't find scap-security-guide RPM(s), are you sure it is installed on your server?", res.errors.first
end

test 'should upload files from guide' do
Expand Down

0 comments on commit adab592

Please sign in to comment.