2015-02-20 13:46:09 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
2018-05-28 21:13:12 +00:00
|
|
|
:codeauthor: Jayesh Kariya <jayeshk@saltstack.com>
|
2015-02-20 13:46:09 +00:00
|
|
|
'''
|
|
|
|
|
|
|
|
# Import Python Libs
|
2018-01-24 20:47:14 +00:00
|
|
|
from __future__ import absolute_import, unicode_literals, print_function
|
2015-02-20 13:46:09 +00:00
|
|
|
|
|
|
|
# Import Salt Testing Libs
|
2017-03-21 18:27:29 +00:00
|
|
|
from tests.support.mixins import LoaderModuleMockMixin
|
|
|
|
from tests.support.unit import TestCase
|
2017-02-27 13:58:07 +00:00
|
|
|
from tests.support.mock import (
|
2015-02-20 13:46:09 +00:00
|
|
|
MagicMock,
|
|
|
|
patch
|
|
|
|
)
|
|
|
|
|
|
|
|
# Import Salt Libs
|
2017-03-21 17:15:36 +00:00
|
|
|
import salt.modules.win_autoruns as win_autoruns
|
2015-02-20 13:46:09 +00:00
|
|
|
|
|
|
|
KEY = ['HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Run',
|
|
|
|
'HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Run /reg:64',
|
|
|
|
'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run']
|
|
|
|
|
|
|
|
|
2017-03-21 18:27:29 +00:00
|
|
|
class WinAutorunsTestCase(TestCase, LoaderModuleMockMixin):
|
2015-02-20 13:46:09 +00:00
|
|
|
'''
|
|
|
|
Test cases for salt.modules.win_autoruns
|
|
|
|
'''
|
2017-03-21 18:27:29 +00:00
|
|
|
def setup_loader_modules(self):
|
|
|
|
return {win_autoruns: {}}
|
|
|
|
|
2015-02-20 13:46:09 +00:00
|
|
|
# 'list_' function tests: 1
|
|
|
|
|
|
|
|
def test_list(self):
|
|
|
|
'''
|
|
|
|
Test if it enables win_autoruns the service on the server
|
|
|
|
'''
|
2017-04-10 13:00:57 +00:00
|
|
|
with patch('os.listdir', MagicMock(return_value=[])):
|
|
|
|
ret = {KEY[0]: ['SALT'], KEY[1]: ['SALT'], KEY[2]: ['SALT']}
|
|
|
|
mock = MagicMock(return_value='Windows 7')
|
|
|
|
with patch.dict(win_autoruns.__grains__, {'osfullname': mock}):
|
|
|
|
mock = MagicMock(return_value='SALT')
|
|
|
|
with patch.dict(win_autoruns.__salt__, {'cmd.run': mock}):
|
|
|
|
self.assertDictEqual(win_autoruns.list_(), ret)
|