2015-09-03 15:33:19 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
|
2015-09-02 02:13:59 +00:00
|
|
|
require 'minitest/autorun'
|
|
|
|
require 'minitest/spec'
|
2015-09-04 18:24:38 +00:00
|
|
|
|
|
|
|
require 'simplecov'
|
|
|
|
SimpleCov.start do
|
|
|
|
add_filter '/test/'
|
|
|
|
add_group 'Resources', 'lib/resources'
|
|
|
|
add_group 'Matchers', 'lib/matchers'
|
|
|
|
add_group 'Backends', 'lib/vulcano/backend'
|
|
|
|
end
|
|
|
|
|
2015-09-02 02:13:59 +00:00
|
|
|
require 'vulcano/backend'
|
2015-09-10 09:20:06 +00:00
|
|
|
require 'vulcano/resource'
|
2015-09-03 15:33:19 +00:00
|
|
|
|
|
|
|
# loads a resource class and instantiates the class with the given arguments
|
|
|
|
def loadResource (resource, *args)
|
2015-09-06 18:27:40 +00:00
|
|
|
scriptpath = ::File.realpath(::File.dirname(__FILE__))
|
2015-09-05 15:40:02 +00:00
|
|
|
|
2015-09-03 15:33:19 +00:00
|
|
|
# create mock backend
|
2015-09-04 20:54:52 +00:00
|
|
|
conf = Vulcano::Backend.target_config({
|
|
|
|
quiet: true
|
|
|
|
})
|
2015-09-03 15:33:19 +00:00
|
|
|
backend_class = Vulcano::Backend.registry['mock']
|
2015-09-06 18:24:25 +00:00
|
|
|
@backend = backend_class.new(conf)
|
|
|
|
|
|
|
|
# create all mock files
|
|
|
|
local = Vulcano::Backend.registry['local'].new({})
|
|
|
|
mockfile = lambda { |x|
|
2015-09-06 18:27:40 +00:00
|
|
|
path = ::File.join(scriptpath, '/unit/mock/files', x)
|
2015-09-06 18:24:25 +00:00
|
|
|
local.file(path)
|
|
|
|
}
|
|
|
|
@backend.files = {
|
|
|
|
'/proc/net/bonding/bond0' => mockfile.('bond0'),
|
|
|
|
'/etc/ssh/ssh_config' => mockfile.('ssh_config'),
|
|
|
|
'/etc/ssh/sshd_config' => mockfile.('sshd_config'),
|
|
|
|
'/etc/passwd' => mockfile.('passwd'),
|
|
|
|
'/etc/ntp.conf' => mockfile.('ntp.conf'),
|
|
|
|
'/etc/login.defs' => mockfile.('login.defs'),
|
|
|
|
'/etc/security/limits.conf' => mockfile.('limits.conf'),
|
|
|
|
'/etc/inetd.conf' => mockfile.('inetd.conf'),
|
|
|
|
'/etc/group' => mockfile.('group'),
|
2015-09-10 09:20:06 +00:00
|
|
|
'/etc/audit/auditd.conf' => mockfile.('auditd.conf'),
|
|
|
|
'/etc/mysql/my.cnf' => mockfile.('mysql.conf'),
|
|
|
|
'/etc/mysql/mysql2.conf' => mockfile.('mysql2.conf')
|
2015-09-06 18:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# create all mock commands
|
|
|
|
cmd = lambda {|x|
|
2015-09-06 18:27:40 +00:00
|
|
|
stdout = ::File.read(::File.join(scriptpath, '/unit/mock/cmd/'+x))
|
2015-09-06 18:40:13 +00:00
|
|
|
@backend.mock_command( stdout, '', 0 )
|
2015-09-06 18:24:25 +00:00
|
|
|
}
|
|
|
|
@backend.commands = {
|
2015-09-08 22:05:05 +00:00
|
|
|
'ps aux' => cmd.call('ps-aux'),
|
|
|
|
'type win_secpol.cfg' => cmd.call('secedit-export'),
|
|
|
|
'secedit /export /cfg win_secpol.cfg' => cmd.call('success'),
|
|
|
|
'del win_secpol.cfg' => cmd.call('success'),
|
|
|
|
'su - root -c \'echo $PATH\'' => cmd.call('PATH'),
|
|
|
|
'(Get-Item \'Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Schedule\').GetValue(\'Start\')' => cmd.call('reg_schedule'),
|
|
|
|
'Auditpol /get /subcategory:\'User Account Management\' /r' => cmd.call('auditpol'),
|
|
|
|
'/sbin/auditctl -l' => cmd.call('auditctl'),
|
|
|
|
'yum -v repolist all' => cmd.call('yum-repolist-all'),
|
|
|
|
'dpkg -s curl' => cmd.call('dpkg-s-curl'),
|
|
|
|
'rpm -qia curl' => cmd.call('rpm-qia-curl'),
|
|
|
|
'pacman -Qi curl' => cmd.call('packman-qi-curl'),
|
2015-09-08 22:13:28 +00:00
|
|
|
'gem list --local -a -q ^rubocop$' => cmd.call('gem-list-local-a-q-rubocop'),
|
|
|
|
'npm ls -g --json bower' => cmd.call('npm-ls-g--json-bower'),
|
2015-09-10 11:35:15 +00:00
|
|
|
'pip show jinja2' => cmd.call('pip-show-jinja2'),
|
|
|
|
"Get-Package -Name 'Mozilla Firefox' | ConvertTo-Json" => cmd.call('get-package'),
|
2015-09-14 13:15:32 +00:00
|
|
|
"New-Object -Type PSObject | Add-Member -MemberType NoteProperty -Name Service -Value (Get-Service -Name dhcp| Select-Object -Property Name, DisplayName, Status) -PassThru | Add-Member -MemberType NoteProperty -Name WMI -Value (Get-WmiObject -Class Win32_Service | Where-Object {$_.Name -eq 'dhcp' -or $_.DisplayName -eq 'dhcp'} | Select-Object -Property StartMode) -PassThru | ConvertTo-Json" => cmd.call('get-service-dhcp'),
|
2015-09-06 18:24:25 +00:00
|
|
|
}
|
2015-09-03 15:33:19 +00:00
|
|
|
|
|
|
|
# load resource
|
|
|
|
@rclass = Vulcano::Resource.registry[resource]
|
|
|
|
|
|
|
|
# merge arguments
|
|
|
|
args = [@backend] | args
|
|
|
|
|
|
|
|
# initialize resource with backend and parameters
|
|
|
|
@resource = @rclass.new(*args)
|
|
|
|
end
|