2017-08-25 19:43:34 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# Import Python libs
|
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
# Import Salt libs
|
|
|
|
import salt.config
|
|
|
|
import salt.master
|
|
|
|
|
|
|
|
# Import Salt Testing Libs
|
|
|
|
from tests.support.unit import TestCase
|
|
|
|
from tests.support.mock import (
|
|
|
|
patch,
|
|
|
|
MagicMock,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class ClearFuncsTestCase(TestCase):
|
|
|
|
'''
|
|
|
|
TestCase for salt.master.ClearFuncs class
|
|
|
|
'''
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
opts = salt.config.master_config(None)
|
|
|
|
self.clear_funcs = salt.master.ClearFuncs(opts, {})
|
|
|
|
|
2017-09-22 18:34:06 +00:00
|
|
|
# runner tests
|
|
|
|
|
2017-08-25 19:43:34 +00:00
|
|
|
def test_runner_token_not_authenticated(self):
|
|
|
|
'''
|
|
|
|
Asserts that a TokenAuthenticationError is returned when the token can't authenticate.
|
|
|
|
'''
|
2017-12-13 22:31:04 +00:00
|
|
|
mock_ret = {'error': {'name': 'TokenAuthenticationError',
|
|
|
|
'message': 'Authentication failure of type "token" occurred.'}}
|
|
|
|
ret = self.clear_funcs.runner({'token': 'asdfasdfasdfasdf'})
|
2017-08-25 19:43:34 +00:00
|
|
|
self.assertDictEqual(mock_ret, ret)
|
|
|
|
|
|
|
|
def test_runner_token_authorization_error(self):
|
|
|
|
'''
|
|
|
|
Asserts that a TokenAuthenticationError is returned when the token authenticates, but is
|
|
|
|
not authorized.
|
|
|
|
'''
|
2017-12-13 22:31:04 +00:00
|
|
|
token = 'asdfasdfasdfasdf'
|
|
|
|
clear_load = {'token': token, 'fun': 'test.arg'}
|
|
|
|
mock_token = {'token': token, 'eauth': 'foo', 'name': 'test'}
|
|
|
|
mock_ret = {'error': {'name': 'TokenAuthenticationError',
|
|
|
|
'message': 'Authentication failure of type "token" occurred '
|
|
|
|
'for user test.'}}
|
2017-08-25 19:43:34 +00:00
|
|
|
|
|
|
|
with patch('salt.auth.LoadAuth.authenticate_token', MagicMock(return_value=mock_token)), \
|
|
|
|
patch('salt.auth.LoadAuth.get_auth_list', MagicMock(return_value=[])):
|
|
|
|
ret = self.clear_funcs.runner(clear_load)
|
|
|
|
|
|
|
|
self.assertDictEqual(mock_ret, ret)
|
|
|
|
|
|
|
|
def test_runner_token_salt_invocation_error(self):
|
|
|
|
'''
|
|
|
|
Asserts that a SaltInvocationError is returned when the token authenticates, but the
|
|
|
|
command is malformed.
|
|
|
|
'''
|
2017-12-13 22:31:04 +00:00
|
|
|
token = 'asdfasdfasdfasdf'
|
|
|
|
clear_load = {'token': token, 'fun': 'badtestarg'}
|
|
|
|
mock_token = {'token': token, 'eauth': 'foo', 'name': 'test'}
|
|
|
|
mock_ret = {'error': {'name': 'SaltInvocationError',
|
|
|
|
'message': 'A command invocation error occurred: Check syntax.'}}
|
2017-08-25 19:43:34 +00:00
|
|
|
|
|
|
|
with patch('salt.auth.LoadAuth.authenticate_token', MagicMock(return_value=mock_token)), \
|
2017-09-25 19:37:38 +00:00
|
|
|
patch('salt.auth.LoadAuth.get_auth_list', MagicMock(return_value=['testing'])):
|
2017-08-25 19:43:34 +00:00
|
|
|
ret = self.clear_funcs.runner(clear_load)
|
|
|
|
|
|
|
|
self.assertDictEqual(mock_ret, ret)
|
|
|
|
|
|
|
|
def test_runner_eauth_not_authenticated(self):
|
|
|
|
'''
|
|
|
|
Asserts that an EauthAuthenticationError is returned when the user can't authenticate.
|
|
|
|
'''
|
2017-12-13 22:31:04 +00:00
|
|
|
mock_ret = {'error': {'name': 'EauthAuthenticationError',
|
|
|
|
'message': 'Authentication failure of type "eauth" occurred for '
|
|
|
|
'user UNKNOWN.'}}
|
|
|
|
ret = self.clear_funcs.runner({'eauth': 'foo'})
|
2017-08-25 19:43:34 +00:00
|
|
|
self.assertDictEqual(mock_ret, ret)
|
|
|
|
|
|
|
|
def test_runner_eauth_authorization_error(self):
|
|
|
|
'''
|
|
|
|
Asserts that an EauthAuthenticationError is returned when the user authenticates, but is
|
|
|
|
not authorized.
|
|
|
|
'''
|
2017-12-13 22:31:04 +00:00
|
|
|
clear_load = {'eauth': 'foo', 'username': 'test', 'fun': 'test.arg'}
|
|
|
|
mock_ret = {'error': {'name': 'EauthAuthenticationError',
|
|
|
|
'message': 'Authentication failure of type "eauth" occurred for '
|
|
|
|
'user test.'}}
|
2017-08-25 19:43:34 +00:00
|
|
|
with patch('salt.auth.LoadAuth.authenticate_eauth', MagicMock(return_value=True)), \
|
|
|
|
patch('salt.auth.LoadAuth.get_auth_list', MagicMock(return_value=[])):
|
|
|
|
ret = self.clear_funcs.runner(clear_load)
|
|
|
|
|
|
|
|
self.assertDictEqual(mock_ret, ret)
|
|
|
|
|
2017-09-25 16:54:32 +00:00
|
|
|
def test_runner_eauth_salt_invocation_error(self):
|
2017-08-25 19:43:34 +00:00
|
|
|
'''
|
|
|
|
Asserts that an EauthAuthenticationError is returned when the user authenticates, but the
|
|
|
|
command is malformed.
|
|
|
|
'''
|
2017-12-13 22:31:04 +00:00
|
|
|
clear_load = {'eauth': 'foo', 'username': 'test', 'fun': 'bad.test.arg.func'}
|
|
|
|
mock_ret = {'error': {'name': 'SaltInvocationError',
|
|
|
|
'message': 'A command invocation error occurred: Check syntax.'}}
|
2017-08-25 19:43:34 +00:00
|
|
|
with patch('salt.auth.LoadAuth.authenticate_eauth', MagicMock(return_value=True)), \
|
2017-09-25 16:54:32 +00:00
|
|
|
patch('salt.auth.LoadAuth.get_auth_list', MagicMock(return_value=['testing'])):
|
2017-08-25 19:43:34 +00:00
|
|
|
ret = self.clear_funcs.runner(clear_load)
|
|
|
|
|
|
|
|
self.assertDictEqual(mock_ret, ret)
|
|
|
|
|
|
|
|
def test_runner_user_not_authenticated(self):
|
|
|
|
'''
|
|
|
|
Asserts that an UserAuthenticationError is returned when the user can't authenticate.
|
|
|
|
'''
|
2017-12-13 22:31:04 +00:00
|
|
|
mock_ret = {'error': {'name': 'UserAuthenticationError',
|
|
|
|
'message': 'Authentication failure of type "user" occurred'}}
|
2017-08-25 19:43:34 +00:00
|
|
|
ret = self.clear_funcs.runner({})
|
|
|
|
self.assertDictEqual(mock_ret, ret)
|
|
|
|
|
2017-09-22 18:34:06 +00:00
|
|
|
# wheel tests
|
|
|
|
|
2017-08-25 19:43:34 +00:00
|
|
|
def test_wheel_token_not_authenticated(self):
|
|
|
|
'''
|
|
|
|
Asserts that a TokenAuthenticationError is returned when the token can't authenticate.
|
|
|
|
'''
|
2017-12-13 22:31:04 +00:00
|
|
|
mock_ret = {'error': {'name': 'TokenAuthenticationError',
|
|
|
|
'message': 'Authentication failure of type "token" occurred.'}}
|
|
|
|
ret = self.clear_funcs.wheel({'token': 'asdfasdfasdfasdf'})
|
2017-08-25 19:43:34 +00:00
|
|
|
self.assertDictEqual(mock_ret, ret)
|
|
|
|
|
|
|
|
def test_wheel_token_authorization_error(self):
|
|
|
|
'''
|
|
|
|
Asserts that a TokenAuthenticationError is returned when the token authenticates, but is
|
|
|
|
not authorized.
|
|
|
|
'''
|
2017-12-13 22:31:04 +00:00
|
|
|
token = 'asdfasdfasdfasdf'
|
|
|
|
clear_load = {'token': token, 'fun': 'test.arg'}
|
|
|
|
mock_token = {'token': token, 'eauth': 'foo', 'name': 'test'}
|
|
|
|
mock_ret = {'error': {'name': 'TokenAuthenticationError',
|
|
|
|
'message': 'Authentication failure of type "token" occurred '
|
|
|
|
'for user test.'}}
|
2017-08-25 19:43:34 +00:00
|
|
|
|
|
|
|
with patch('salt.auth.LoadAuth.authenticate_token', MagicMock(return_value=mock_token)), \
|
|
|
|
patch('salt.auth.LoadAuth.get_auth_list', MagicMock(return_value=[])):
|
|
|
|
ret = self.clear_funcs.wheel(clear_load)
|
|
|
|
|
|
|
|
self.assertDictEqual(mock_ret, ret)
|
|
|
|
|
|
|
|
def test_wheel_token_salt_invocation_error(self):
|
|
|
|
'''
|
|
|
|
Asserts that a SaltInvocationError is returned when the token authenticates, but the
|
|
|
|
command is malformed.
|
|
|
|
'''
|
2017-12-13 22:31:04 +00:00
|
|
|
token = 'asdfasdfasdfasdf'
|
|
|
|
clear_load = {'token': token, 'fun': 'badtestarg'}
|
|
|
|
mock_token = {'token': token, 'eauth': 'foo', 'name': 'test'}
|
|
|
|
mock_ret = {'error': {'name': 'SaltInvocationError',
|
|
|
|
'message': 'A command invocation error occurred: Check syntax.'}}
|
2017-08-25 19:43:34 +00:00
|
|
|
|
|
|
|
with patch('salt.auth.LoadAuth.authenticate_token', MagicMock(return_value=mock_token)), \
|
2017-09-25 16:54:32 +00:00
|
|
|
patch('salt.auth.LoadAuth.get_auth_list', MagicMock(return_value=['testing'])):
|
2017-08-25 19:43:34 +00:00
|
|
|
ret = self.clear_funcs.wheel(clear_load)
|
|
|
|
|
|
|
|
self.assertDictEqual(mock_ret, ret)
|
|
|
|
|
|
|
|
def test_wheel_eauth_not_authenticated(self):
|
|
|
|
'''
|
|
|
|
Asserts that an EauthAuthenticationError is returned when the user can't authenticate.
|
|
|
|
'''
|
2017-12-13 22:31:04 +00:00
|
|
|
mock_ret = {'error': {'name': 'EauthAuthenticationError',
|
|
|
|
'message': 'Authentication failure of type "eauth" occurred for '
|
|
|
|
'user UNKNOWN.'}}
|
|
|
|
ret = self.clear_funcs.wheel({'eauth': 'foo'})
|
2017-08-25 19:43:34 +00:00
|
|
|
self.assertDictEqual(mock_ret, ret)
|
|
|
|
|
|
|
|
def test_wheel_eauth_authorization_error(self):
|
|
|
|
'''
|
|
|
|
Asserts that an EauthAuthenticationError is returned when the user authenticates, but is
|
|
|
|
not authorized.
|
|
|
|
'''
|
2017-12-13 22:31:04 +00:00
|
|
|
clear_load = {'eauth': 'foo', 'username': 'test', 'fun': 'test.arg'}
|
|
|
|
mock_ret = {'error': {'name': 'EauthAuthenticationError',
|
|
|
|
'message': 'Authentication failure of type "eauth" occurred for '
|
|
|
|
'user test.'}}
|
2017-08-25 19:43:34 +00:00
|
|
|
with patch('salt.auth.LoadAuth.authenticate_eauth', MagicMock(return_value=True)), \
|
|
|
|
patch('salt.auth.LoadAuth.get_auth_list', MagicMock(return_value=[])):
|
|
|
|
ret = self.clear_funcs.wheel(clear_load)
|
|
|
|
|
|
|
|
self.assertDictEqual(mock_ret, ret)
|
|
|
|
|
2017-09-25 16:54:32 +00:00
|
|
|
def test_wheel_eauth_salt_invocation_error(self):
|
2017-08-25 19:43:34 +00:00
|
|
|
'''
|
|
|
|
Asserts that an EauthAuthenticationError is returned when the user authenticates, but the
|
|
|
|
command is malformed.
|
|
|
|
'''
|
2017-12-13 22:31:04 +00:00
|
|
|
clear_load = {'eauth': 'foo', 'username': 'test', 'fun': 'bad.test.arg.func'}
|
|
|
|
mock_ret = {'error': {'name': 'SaltInvocationError',
|
|
|
|
'message': 'A command invocation error occurred: Check syntax.'}}
|
2017-08-25 19:43:34 +00:00
|
|
|
with patch('salt.auth.LoadAuth.authenticate_eauth', MagicMock(return_value=True)), \
|
2017-09-25 16:54:32 +00:00
|
|
|
patch('salt.auth.LoadAuth.get_auth_list', MagicMock(return_value=['testing'])):
|
2017-08-25 19:43:34 +00:00
|
|
|
ret = self.clear_funcs.wheel(clear_load)
|
|
|
|
|
|
|
|
self.assertDictEqual(mock_ret, ret)
|
|
|
|
|
|
|
|
def test_wheel_user_not_authenticated(self):
|
|
|
|
'''
|
|
|
|
Asserts that an UserAuthenticationError is returned when the user can't authenticate.
|
|
|
|
'''
|
2017-12-13 22:31:04 +00:00
|
|
|
mock_ret = {'error': {'name': 'UserAuthenticationError',
|
|
|
|
'message': 'Authentication failure of type "user" occurred'}}
|
2017-08-25 19:43:34 +00:00
|
|
|
ret = self.clear_funcs.wheel({})
|
|
|
|
self.assertDictEqual(mock_ret, ret)
|
2017-09-22 18:34:06 +00:00
|
|
|
|
|
|
|
# publish tests
|
|
|
|
|
|
|
|
def test_publish_user_is_blacklisted(self):
|
|
|
|
'''
|
2017-12-10 16:22:17 +00:00
|
|
|
Asserts that an AuthorizationError is returned when the user has been blacklisted.
|
2017-09-22 18:34:06 +00:00
|
|
|
'''
|
2017-12-10 16:22:17 +00:00
|
|
|
mock_ret = {'error': {'name': 'AuthorizationError',
|
|
|
|
'message': 'Authorization error occurred.'}}
|
2017-09-22 18:34:06 +00:00
|
|
|
with patch('salt.acl.PublisherACL.user_is_blacklisted', MagicMock(return_value=True)):
|
2017-12-10 16:22:17 +00:00
|
|
|
self.assertEqual(mock_ret, self.clear_funcs.publish({'user': 'foo', 'fun': 'test.arg'}))
|
2017-09-22 18:34:06 +00:00
|
|
|
|
|
|
|
def test_publish_cmd_blacklisted(self):
|
|
|
|
'''
|
2017-12-10 16:22:17 +00:00
|
|
|
Asserts that an AuthorizationError is returned when the command has been blacklisted.
|
2017-09-22 18:34:06 +00:00
|
|
|
'''
|
2017-12-10 16:22:17 +00:00
|
|
|
mock_ret = {'error': {'name': 'AuthorizationError',
|
|
|
|
'message': 'Authorization error occurred.'}}
|
2017-09-22 18:34:06 +00:00
|
|
|
with patch('salt.acl.PublisherACL.user_is_blacklisted', MagicMock(return_value=False)), \
|
|
|
|
patch('salt.acl.PublisherACL.cmd_is_blacklisted', MagicMock(return_value=True)):
|
2017-12-10 16:22:17 +00:00
|
|
|
self.assertEqual(mock_ret, self.clear_funcs.publish({'user': 'foo', 'fun': 'test.arg'}))
|
2017-09-22 18:34:06 +00:00
|
|
|
|
|
|
|
def test_publish_token_not_authenticated(self):
|
|
|
|
'''
|
2017-12-10 16:22:17 +00:00
|
|
|
Asserts that an AuthenticationError is returned when the token can't authenticate.
|
2017-09-22 18:34:06 +00:00
|
|
|
'''
|
2017-12-10 16:22:17 +00:00
|
|
|
mock_ret = {'error': {'name': 'AuthenticationError',
|
|
|
|
'message': 'Authentication error occurred.'}}
|
2017-12-13 22:31:04 +00:00
|
|
|
load = {'user': 'foo', 'fun': 'test.arg', 'tgt': 'test_minion',
|
|
|
|
'kwargs': {'token': 'asdfasdfasdfasdf'}}
|
2017-09-22 18:34:06 +00:00
|
|
|
with patch('salt.acl.PublisherACL.user_is_blacklisted', MagicMock(return_value=False)), \
|
|
|
|
patch('salt.acl.PublisherACL.cmd_is_blacklisted', MagicMock(return_value=False)):
|
2017-12-10 16:22:17 +00:00
|
|
|
self.assertEqual(mock_ret, self.clear_funcs.publish(load))
|
2017-09-22 18:34:06 +00:00
|
|
|
|
|
|
|
def test_publish_token_authorization_error(self):
|
|
|
|
'''
|
2017-12-10 16:22:17 +00:00
|
|
|
Asserts that an AuthorizationError is returned when the token authenticates, but is not
|
2017-09-22 18:34:06 +00:00
|
|
|
authorized.
|
|
|
|
'''
|
2017-12-13 22:31:04 +00:00
|
|
|
token = 'asdfasdfasdfasdf'
|
|
|
|
load = {'user': 'foo', 'fun': 'test.arg', 'tgt': 'test_minion',
|
|
|
|
'arg': 'bar', 'kwargs': {'token': token}}
|
|
|
|
mock_token = {'token': token, 'eauth': 'foo', 'name': 'test'}
|
2017-12-10 16:22:17 +00:00
|
|
|
mock_ret = {'error': {'name': 'AuthorizationError',
|
|
|
|
'message': 'Authorization error occurred.'}}
|
2017-09-22 18:34:06 +00:00
|
|
|
|
|
|
|
with patch('salt.acl.PublisherACL.user_is_blacklisted', MagicMock(return_value=False)), \
|
|
|
|
patch('salt.acl.PublisherACL.cmd_is_blacklisted', MagicMock(return_value=False)), \
|
|
|
|
patch('salt.auth.LoadAuth.authenticate_token', MagicMock(return_value=mock_token)), \
|
|
|
|
patch('salt.auth.LoadAuth.get_auth_list', MagicMock(return_value=[])):
|
2017-12-10 16:22:17 +00:00
|
|
|
self.assertEqual(mock_ret, self.clear_funcs.publish(load))
|
2017-09-22 18:34:06 +00:00
|
|
|
|
|
|
|
def test_publish_eauth_not_authenticated(self):
|
|
|
|
'''
|
2017-12-10 16:22:17 +00:00
|
|
|
Asserts that an AuthenticationError is returned when the user can't authenticate.
|
2017-09-22 18:34:06 +00:00
|
|
|
'''
|
2017-12-13 22:31:04 +00:00
|
|
|
load = {'user': 'test', 'fun': 'test.arg', 'tgt': 'test_minion',
|
|
|
|
'kwargs': {'eauth': 'foo'}}
|
2017-12-10 16:22:17 +00:00
|
|
|
mock_ret = {'error': {'name': 'AuthenticationError',
|
|
|
|
'message': 'Authentication error occurred.'}}
|
2017-09-22 18:34:06 +00:00
|
|
|
with patch('salt.acl.PublisherACL.user_is_blacklisted', MagicMock(return_value=False)), \
|
|
|
|
patch('salt.acl.PublisherACL.cmd_is_blacklisted', MagicMock(return_value=False)):
|
2017-12-10 16:22:17 +00:00
|
|
|
self.assertEqual(mock_ret, self.clear_funcs.publish(load))
|
2017-09-22 18:34:06 +00:00
|
|
|
|
|
|
|
def test_publish_eauth_authorization_error(self):
|
|
|
|
'''
|
2017-12-10 16:22:17 +00:00
|
|
|
Asserts that an AuthorizationError is returned when the user authenticates, but is not
|
2017-09-22 18:34:06 +00:00
|
|
|
authorized.
|
|
|
|
'''
|
2017-12-13 22:31:04 +00:00
|
|
|
load = {'user': 'test', 'fun': 'test.arg', 'tgt': 'test_minion',
|
|
|
|
'kwargs': {'eauth': 'foo'}, 'arg': 'bar'}
|
2017-12-10 16:22:17 +00:00
|
|
|
mock_ret = {'error': {'name': 'AuthorizationError',
|
|
|
|
'message': 'Authorization error occurred.'}}
|
2017-09-22 18:34:06 +00:00
|
|
|
with patch('salt.acl.PublisherACL.user_is_blacklisted', MagicMock(return_value=False)), \
|
|
|
|
patch('salt.acl.PublisherACL.cmd_is_blacklisted', MagicMock(return_value=False)), \
|
|
|
|
patch('salt.auth.LoadAuth.authenticate_eauth', MagicMock(return_value=True)), \
|
|
|
|
patch('salt.auth.LoadAuth.get_auth_list', MagicMock(return_value=[])):
|
2017-12-10 16:22:17 +00:00
|
|
|
self.assertEqual(mock_ret, self.clear_funcs.publish(load))
|
2017-09-22 18:34:06 +00:00
|
|
|
|
|
|
|
def test_publish_user_not_authenticated(self):
|
|
|
|
'''
|
2017-12-10 16:22:17 +00:00
|
|
|
Asserts that an AuthenticationError is returned when the user can't authenticate.
|
2017-09-22 18:34:06 +00:00
|
|
|
'''
|
2017-12-13 22:31:04 +00:00
|
|
|
load = {'user': 'test', 'fun': 'test.arg', 'tgt': 'test_minion'}
|
2017-12-10 16:22:17 +00:00
|
|
|
mock_ret = {'error': {'name': 'AuthenticationError',
|
|
|
|
'message': 'Authentication error occurred.'}}
|
2017-09-22 18:34:06 +00:00
|
|
|
with patch('salt.acl.PublisherACL.user_is_blacklisted', MagicMock(return_value=False)), \
|
|
|
|
patch('salt.acl.PublisherACL.cmd_is_blacklisted', MagicMock(return_value=False)):
|
2017-12-10 16:22:17 +00:00
|
|
|
self.assertEqual(mock_ret, self.clear_funcs.publish(load))
|
2017-09-22 18:34:06 +00:00
|
|
|
|
|
|
|
def test_publish_user_authenticated_missing_auth_list(self):
|
|
|
|
'''
|
2017-12-10 16:22:17 +00:00
|
|
|
Asserts that an AuthenticationError is returned when the user has an effective user id and is
|
2017-09-22 18:34:06 +00:00
|
|
|
authenticated, but the auth_list is empty.
|
|
|
|
'''
|
2017-12-13 22:31:04 +00:00
|
|
|
load = {'user': 'test', 'fun': 'test.arg', 'tgt': 'test_minion',
|
|
|
|
'kwargs': {'user': 'test'}, 'arg': 'foo'}
|
2017-12-10 16:22:17 +00:00
|
|
|
mock_ret = {'error': {'name': 'AuthenticationError',
|
|
|
|
'message': 'Authentication error occurred.'}}
|
2017-09-22 18:34:06 +00:00
|
|
|
with patch('salt.acl.PublisherACL.user_is_blacklisted', MagicMock(return_value=False)), \
|
|
|
|
patch('salt.acl.PublisherACL.cmd_is_blacklisted', MagicMock(return_value=False)), \
|
|
|
|
patch('salt.auth.LoadAuth.authenticate_key', MagicMock(return_value='fake-user-key')), \
|
|
|
|
patch('salt.utils.master.get_values_of_matching_keys', MagicMock(return_value=[])):
|
2017-12-10 16:22:17 +00:00
|
|
|
self.assertEqual(mock_ret, self.clear_funcs.publish(load))
|
2017-09-22 18:34:06 +00:00
|
|
|
|
|
|
|
def test_publish_user_authorization_error(self):
|
|
|
|
'''
|
2017-12-10 16:22:17 +00:00
|
|
|
Asserts that an AuthorizationError is returned when the user authenticates, but is not
|
2017-09-22 18:34:06 +00:00
|
|
|
authorized.
|
|
|
|
'''
|
2017-12-13 22:31:04 +00:00
|
|
|
load = {'user': 'test', 'fun': 'test.arg', 'tgt': 'test_minion',
|
|
|
|
'kwargs': {'user': 'test'}, 'arg': 'foo'}
|
2017-12-10 16:22:17 +00:00
|
|
|
mock_ret = {'error': {'name': 'AuthorizationError',
|
|
|
|
'message': 'Authorization error occurred.'}}
|
2017-09-22 18:34:06 +00:00
|
|
|
with patch('salt.acl.PublisherACL.user_is_blacklisted', MagicMock(return_value=False)), \
|
|
|
|
patch('salt.acl.PublisherACL.cmd_is_blacklisted', MagicMock(return_value=False)), \
|
|
|
|
patch('salt.auth.LoadAuth.authenticate_key', MagicMock(return_value='fake-user-key')), \
|
|
|
|
patch('salt.utils.master.get_values_of_matching_keys', MagicMock(return_value=['test'])), \
|
|
|
|
patch('salt.utils.minions.CkMinions.auth_check', MagicMock(return_value=False)):
|
2017-12-10 16:22:17 +00:00
|
|
|
self.assertEqual(mock_ret, self.clear_funcs.publish(load))
|