-
Notifications
You must be signed in to change notification settings - Fork 65
/
scap_content_test.rb
49 lines (43 loc) · 2.4 KB
/
scap_content_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require 'test_plugin_helper'
class ScapContentTest < ActiveSupport::TestCase
setup do
@scap_file = File.new("#{ForemanOpenscap::Engine.root}/test/files/scap_contents/ssg-fedora-ds.xml", 'rb').read
end
context 'validate scap contents' do
test 'create scap content' do
scap_content = ForemanOpenscap::ScapContent.new(:title => 'Fedora', :scap_file => @scap_file)
assert(scap_content.valid?)
end
test 'should not allow title.length > 255' do
scap_content = ForemanOpenscap::ScapContent.new(:title => ("a" * 256), :scap_file => @scap_file)
refute(scap_content.valid?)
end
test 'scap content should fail if no openscap proxy' do
SmartProxy.stubs(:with_features).returns([])
scap_content = ForemanOpenscap::ScapContent.new(:title => 'Fedora', :scap_file => @scap_file)
refute(scap_content.save)
assert_includes(scap_content.errors.messages[:base], 'No proxy with OpenSCAP feature was found.')
end
test 'proxy_url should return the first available proxy it finds' do
available_proxy = SmartProxy.with_features('Openscap').first
unavailable_proxy = FactoryBot.create(:smart_proxy, :url => 'http://proxy.example.com:8443', :features => [FactoryBot.create(:feature, :name => 'Openscap')])
SmartProxy.expects(:with_features).with('Openscap').returns([unavailable_proxy, available_proxy])
SmartProxy.any_instance.expects(:ping).twice.returns(false).then.returns(true)
scap_content = ForemanOpenscap::ScapContent.new(:title => 'Fedora', :scap_file => @scap_file)
assert_equal(available_proxy.url, scap_content.proxy_url)
end
end
test 'should update profile title when fetching profiles from proxy' do
scap_content = FactoryBot.create(:scap_content)
scap_content.stubs(:fetch_profiles).returns({ "xccdf.test.profile" => "Changed title" })
scap_profile = FactoryBot.create(:scap_content_profile, :scap_content => scap_content, :profile_id => 'xccdf.test.profile', :title => "Original title")
scap_content.create_profiles
assert_equal scap_profile.reload.title, 'Changed title'
end
test 'should create profile when fetching profiles from proxy' do
scap_content = FactoryBot.create(:scap_content)
scap_content.stubs(:fetch_profiles).returns({ "xccdf.test.profile" => "My title" })
scap_content.create_profiles
assert scap_content.reload.scap_content_profiles.where(:title => 'My title').first
end
end