mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge branch '2015.5' into '2015.8'
Conflicts: - salt/modules/rh_service.py
This commit is contained in:
commit
e9abd2d420
4 changed files with 160 additions and 6 deletions
|
@ -288,6 +288,7 @@ def list_nodes(conn=None, call=None):
|
|||
for lxcc, linfos in six.iteritems(lxcs):
|
||||
info = {
|
||||
'id': lxcc,
|
||||
'name': lxcc, # required for cloud cache
|
||||
'image': None,
|
||||
'size': linfos['size'],
|
||||
'state': state.lower(),
|
||||
|
@ -338,7 +339,7 @@ def list_nodes_select(call=None):
|
|||
call = 'select'
|
||||
if not get_configured_provider():
|
||||
return
|
||||
info = ['id', 'image', 'size', 'state', 'public_ips', 'private_ips']
|
||||
info = ['id', 'name', 'image', 'size', 'state', 'public_ips', 'private_ips']
|
||||
return salt.utils.cloud.list_nodes_select(
|
||||
list_nodes_full(call='action'),
|
||||
__opts__.get('query.selection', info), call)
|
||||
|
|
|
@ -261,11 +261,15 @@ def state(
|
|||
fail.add(minion)
|
||||
failures[minion] = m_ret or 'Minion did not respond'
|
||||
continue
|
||||
for state_item in six.itervalues(m_ret):
|
||||
if state_item['changes']:
|
||||
changes[minion] = m_ret
|
||||
break
|
||||
else:
|
||||
try:
|
||||
for state_item in six.itervalues(m_ret):
|
||||
if 'changes' in state_item and state_item['changes']:
|
||||
changes[minion] = m_ret
|
||||
break
|
||||
else:
|
||||
no_change.add(minion)
|
||||
except AttributeError:
|
||||
log.error("m_ret did not have changes %s %s", type(m_ret), m_ret)
|
||||
no_change.add(minion)
|
||||
|
||||
if changes:
|
||||
|
|
141
tests/integration/netapi/rest_cherrypy/app_pam_test.py
Normal file
141
tests/integration/netapi/rest_cherrypy/app_pam_test.py
Normal file
|
@ -0,0 +1,141 @@
|
|||
# coding: utf-8
|
||||
'''
|
||||
Integration Tests for restcherry salt-api with pam eauth
|
||||
'''
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
import os
|
||||
|
||||
# Import salttesting libs
|
||||
from salttesting.unit import skipIf
|
||||
from salttesting.helpers import (
|
||||
ensure_in_syspath,
|
||||
destructiveTest)
|
||||
ensure_in_syspath('../../../')
|
||||
|
||||
from tests.utils import BaseRestCherryPyTest
|
||||
|
||||
# Import Salt Libs
|
||||
import integration
|
||||
import salt.utils
|
||||
|
||||
# Import 3rd-party libs
|
||||
# pylint: disable=import-error,unused-import
|
||||
from salt.ext.six.moves.urllib.parse import urlencode # pylint: disable=no-name-in-module
|
||||
try:
|
||||
import cherrypy
|
||||
HAS_CHERRYPY = True
|
||||
except ImportError:
|
||||
HAS_CHERRYPY = False
|
||||
# pylint: enable=import-error,unused-import
|
||||
|
||||
USERA = 'saltdev'
|
||||
USERA_PWD = 'saltdev'
|
||||
SET_USERA_PWD = '$6$SALTsalt$ZZFD90fKFWq8AGmmX0L3uBtS9fXL62SrTk5zcnQ6EkD6zoiM3kB88G1Zvs0xm/gZ7WXJRs5nsTBybUvGSqZkT.'
|
||||
|
||||
AUTH_CREDS = {
|
||||
'username': USERA,
|
||||
'password': USERA_PWD,
|
||||
'eauth': 'pam'}
|
||||
|
||||
|
||||
@skipIf(HAS_CHERRYPY is False, 'CherryPy not installed')
|
||||
class TestAuthPAM(BaseRestCherryPyTest, integration.ModuleCase):
|
||||
'''
|
||||
Test auth with pam using salt-api
|
||||
'''
|
||||
|
||||
@destructiveTest
|
||||
@skipIf(os.geteuid() != 0, 'You must be logged in as root to run this test')
|
||||
def setUp(self):
|
||||
super(TestAuthPAM, self).setUp()
|
||||
try:
|
||||
add_user = self.run_function('user.add', [USERA], createhome=False)
|
||||
add_pwd = self.run_function('shadow.set_password',
|
||||
[USERA, SET_USERA_PWD])
|
||||
self.assertTrue(add_user)
|
||||
self.assertTrue(add_pwd)
|
||||
user_list = self.run_function('user.list_users')
|
||||
self.assertIn(USERA, str(user_list))
|
||||
except AssertionError:
|
||||
self.run_function('user.delete', [USERA], remove=True)
|
||||
self.skipTest(
|
||||
'Could not add user or password, skipping test'
|
||||
)
|
||||
|
||||
def test_bad_pwd_pam_chsh_service(self):
|
||||
'''
|
||||
Test login while specifying chsh service with bad passwd
|
||||
This test ensures this PR is working correctly:
|
||||
https://github.com/saltstack/salt/pull/31826
|
||||
'''
|
||||
copyauth_creds = AUTH_CREDS.copy()
|
||||
copyauth_creds['service'] = 'chsh'
|
||||
copyauth_creds['password'] = 'wrong_password'
|
||||
body = urlencode(copyauth_creds)
|
||||
request, response = self.request('/login', method='POST', body=body,
|
||||
headers={
|
||||
'content-type': 'application/x-www-form-urlencoded'
|
||||
})
|
||||
self.assertEqual(response.status, '401 Unauthorized')
|
||||
|
||||
def test_bad_pwd_pam_login_service(self):
|
||||
'''
|
||||
Test login while specifying login service with bad passwd
|
||||
This test ensures this PR is working correctly:
|
||||
https://github.com/saltstack/salt/pull/31826
|
||||
'''
|
||||
copyauth_creds = AUTH_CREDS.copy()
|
||||
copyauth_creds['service'] = 'login'
|
||||
copyauth_creds['password'] = 'wrong_password'
|
||||
body = urlencode(copyauth_creds)
|
||||
request, response = self.request('/login', method='POST', body=body,
|
||||
headers={
|
||||
'content-type': 'application/x-www-form-urlencoded'
|
||||
})
|
||||
self.assertEqual(response.status, '401 Unauthorized')
|
||||
|
||||
def test_good_pwd_pam_chsh_service(self):
|
||||
'''
|
||||
Test login while specifying chsh service with good passwd
|
||||
This test ensures this PR is working correctly:
|
||||
https://github.com/saltstack/salt/pull/31826
|
||||
'''
|
||||
copyauth_creds = AUTH_CREDS.copy()
|
||||
copyauth_creds['service'] = 'chsh'
|
||||
body = urlencode(copyauth_creds)
|
||||
request, response = self.request('/login', method='POST', body=body,
|
||||
headers={
|
||||
'content-type': 'application/x-www-form-urlencoded'
|
||||
})
|
||||
self.assertEqual(response.status, '200 OK')
|
||||
|
||||
def test_good_pwd_pam_login_service(self):
|
||||
'''
|
||||
Test login while specifying login service with good passwd
|
||||
This test ensures this PR is working correctly:
|
||||
https://github.com/saltstack/salt/pull/31826
|
||||
'''
|
||||
copyauth_creds = AUTH_CREDS.copy()
|
||||
copyauth_creds['service'] = 'login'
|
||||
body = urlencode(copyauth_creds)
|
||||
request, response = self.request('/login', method='POST', body=body,
|
||||
headers={
|
||||
'content-type': 'application/x-www-form-urlencoded'
|
||||
})
|
||||
self.assertEqual(response.status, '200 OK')
|
||||
|
||||
@destructiveTest
|
||||
@skipIf(os.geteuid() != 0, 'You must be logged in as root to run this test')
|
||||
def tearDown(self):
|
||||
'''
|
||||
Clean up after tests. Delete user
|
||||
'''
|
||||
super(TestAuthPAM, self).tearDown()
|
||||
user_list = self.run_function('user.list_users')
|
||||
# Remove saltdev user
|
||||
if USERA in user_list:
|
||||
self.run_function('user.delete', [USERA], remove=True)
|
||||
#need to exit cherypy engine
|
||||
cherrypy.engine.exit()
|
|
@ -58,6 +58,14 @@ class BaseRestCherryPyTest(BaseCherryPyTestCase):
|
|||
'@runner',
|
||||
'.*',
|
||||
],
|
||||
},
|
||||
'pam': {
|
||||
'saltdev': [
|
||||
'@wheel',
|
||||
'@runner',
|
||||
'.*',
|
||||
],
|
||||
|
||||
}
|
||||
},
|
||||
'rest_cherrypy': {
|
||||
|
|
Loading…
Add table
Reference in a new issue