mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #26975 from whiteinge/rest_cherrypy-integration
Remove mocks from rest_cherrypy integration tests; fix groups check bug
This commit is contained in:
commit
67be01f5fe
3 changed files with 10 additions and 49 deletions
|
@ -1438,7 +1438,7 @@ class Login(LowDataAdapter):
|
|||
perms = eauth.get(token['name'], [])
|
||||
perms.extend(eauth.get('*', []))
|
||||
|
||||
if 'groups' in token:
|
||||
if 'groups' in token and token['groups'] is not False:
|
||||
user_groups = set(token['groups'])
|
||||
eauth_groups = set([i.rstrip('%') for i in eauth.keys() if i.endswith('%')])
|
||||
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
# coding: utf-8
|
||||
|
||||
# Import salttesting libs
|
||||
from salttesting import mock
|
||||
from salttesting.unit import skipIf
|
||||
from salttesting.helpers import ensure_in_syspath
|
||||
ensure_in_syspath('../../../')
|
||||
|
||||
from salt.exceptions import EauthAuthenticationError
|
||||
from tests.utils import BaseRestCherryPyTest
|
||||
|
||||
# Import 3rd-party libs
|
||||
|
@ -57,26 +55,10 @@ class TestLogin(BaseRestCherryPyTest):
|
|||
('password', 'saltdev'),
|
||||
('eauth', 'auto'))
|
||||
|
||||
@mock.patch('salt.auth.Resolver', autospec=True)
|
||||
def setUp(self, Resolver, *args, **kwargs):
|
||||
super(TestLogin, self).setUp(*args, **kwargs)
|
||||
|
||||
self.app.salt.auth.Resolver = Resolver
|
||||
self.Resolver = Resolver
|
||||
|
||||
def test_good_login(self):
|
||||
'''
|
||||
Test logging in
|
||||
'''
|
||||
# Mock mk_token for a positive return
|
||||
self.Resolver.return_value.mk_token.return_value = {
|
||||
'token': '6d1b722e',
|
||||
'start': 1363805943.776223,
|
||||
'expire': 1363849143.776224,
|
||||
'name': 'saltdev',
|
||||
'eauth': 'auto',
|
||||
}
|
||||
|
||||
body = urlencode(self.auth_creds)
|
||||
request, response = self.request('/login', method='POST', body=body,
|
||||
headers={
|
||||
|
@ -89,9 +71,6 @@ class TestLogin(BaseRestCherryPyTest):
|
|||
'''
|
||||
Test logging in
|
||||
'''
|
||||
# Mock mk_token for a negative return
|
||||
self.Resolver.return_value.mk_token.return_value = {}
|
||||
|
||||
body = urlencode({'totally': 'invalid_creds'})
|
||||
request, response = self.request('/login', method='POST', body=body,
|
||||
headers={
|
||||
|
@ -114,7 +93,7 @@ class TestLogin(BaseRestCherryPyTest):
|
|||
|
||||
class TestRun(BaseRestCherryPyTest):
|
||||
auth_creds = (
|
||||
('username', 'saltdev'),
|
||||
('username', 'saltdev_auto'),
|
||||
('password', 'saltdev'),
|
||||
('eauth', 'auto'))
|
||||
|
||||
|
@ -131,14 +110,10 @@ class TestRun(BaseRestCherryPyTest):
|
|||
cmd = dict(self.low, **dict(self.auth_creds))
|
||||
body = urlencode(cmd)
|
||||
|
||||
# Mock the interaction with Salt so we can focus on the API.
|
||||
with mock.patch.object(self.app.salt.netapi.NetapiClient, 'run',
|
||||
return_value=True):
|
||||
request, response = self.request('/run', method='POST', body=body,
|
||||
headers={
|
||||
'content-type': 'application/x-www-form-urlencoded'
|
||||
})
|
||||
|
||||
request, response = self.request('/run', method='POST', body=body,
|
||||
headers={
|
||||
'content-type': 'application/x-www-form-urlencoded'
|
||||
})
|
||||
self.assertEqual(response.status, '200 OK')
|
||||
|
||||
def test_run_bad_login(self):
|
||||
|
@ -148,14 +123,10 @@ class TestRun(BaseRestCherryPyTest):
|
|||
cmd = dict(self.low, **{'totally': 'invalid_creds'})
|
||||
body = urlencode(cmd)
|
||||
|
||||
# Mock the interaction with Salt so we can focus on the API.
|
||||
with mock.patch.object(self.app.salt.netapi.NetapiClient, 'run',
|
||||
side_effect=EauthAuthenticationError('Oh noes!')):
|
||||
request, response = self.request('/run', method='POST', body=body,
|
||||
headers={
|
||||
'content-type': 'application/x-www-form-urlencoded'
|
||||
})
|
||||
|
||||
request, response = self.request('/run', method='POST', body=body,
|
||||
headers={
|
||||
'content-type': 'application/x-www-form-urlencoded'
|
||||
})
|
||||
self.assertEqual(response.status, '401 Unauthorized')
|
||||
|
||||
|
||||
|
@ -168,20 +139,10 @@ class TestWebhookDisableAuth(BaseRestCherryPyTest):
|
|||
},
|
||||
}
|
||||
|
||||
@mock.patch('salt.utils.event.get_event', autospec=True)
|
||||
def setUp(self, get_event, *args, **kwargs):
|
||||
super(TestWebhookDisableAuth, self).setUp(*args, **kwargs)
|
||||
|
||||
self.app.salt.utils.event.get_event = get_event
|
||||
self.get_event = get_event
|
||||
|
||||
def test_webhook_noauth(self):
|
||||
'''
|
||||
Auth can be disabled for requests to the webhook URL
|
||||
'''
|
||||
# Mock fire_event() since we're only testing auth here.
|
||||
self.get_event.return_value.fire_event.return_value = True
|
||||
|
||||
body = urlencode({'foo': 'Foo!'})
|
||||
request, response = self.request('/hook', method='POST', body=body,
|
||||
headers={
|
Loading…
Add table
Reference in a new issue