salt/tests/unit/perm_test.py

125 lines
3.4 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
'''
:codeauthor: :email:`Mike Place <mp@saltstack.com`
Tests to ensure that the file permissions are set correctly when
importing from the git repo.
'''
# Import python libs
import os
import stat
2014-03-23 18:20:42 +00:00
import pprint
# Import salt testing libs
from salttesting import TestCase
from salttesting.helpers import ensure_in_syspath
ensure_in_syspath('..')
from integration import CODE_DIR
2014-03-23 18:20:42 +00:00
EXEMPT_DIRS = []
EXEMPT_FILES = [
'debian/rules',
'doc/.scripts/compile-translation-catalogs',
'doc/.scripts/download-translation-catalog',
'doc/.scripts/setup-transifex-config',
'doc/.scripts/update-transifex-source-translations',
'pkg/arch/Makefile',
'pkg/arch/PKGBUILD',
'pkg/arch/PKGBUILD-git',
'pkg/arch/PKGBUILD-local',
'pkg/arch/git/PKGBUILD',
2014-03-24 17:02:23 +00:00
'pkg/rpm/build.py',
2014-03-23 18:20:42 +00:00
'pkg/rpm/salt-master',
'pkg/rpm/salt-minion',
'pkg/rpm/salt-syndic',
2014-03-29 01:26:02 +00:00
'pkg/shar/build_shar.sh',
2014-03-23 18:20:42 +00:00
'pkg/smartos/esky/install.sh',
'salt/templates/git/ssh-id-wrapper',
'scripts/salt',
'scripts/salt-call',
'scripts/salt-cloud',
'scripts/salt-cp',
'scripts/salt-key',
'scripts/salt-master',
'scripts/salt-minion',
'scripts/salt-run',
'scripts/salt-ssh',
'scripts/salt-syndic',
'setup.py',
'tests/integration/mockbin/su',
'tests/runtests.py',
2014-03-24 17:02:23 +00:00
'tests/saltsh.py',
2014-03-23 18:20:42 +00:00
]
IGNORE_PATHS = [
'.git',
'.wti',
'build',
'dist',
'salt.egg-info',
'.ropeproject',
]
class GitPermTestCase(TestCase):
def test_perms(self):
2014-03-23 18:20:42 +00:00
suspect_entries = []
for root, dirnames, filenames in os.walk(CODE_DIR, topdown=True):
for dirname in dirnames:
entry = os.path.relpath(
os.path.join(root, dirname), CODE_DIR
)
if entry in IGNORE_PATHS:
continue
skip_entry = False
for ignore_path in IGNORE_PATHS:
if entry.startswith(ignore_path):
skip_entry = True
break
if skip_entry:
continue
fn_mode = stat.S_IMODE(os.stat(entry).st_mode)
if fn_mode != 493 and entry not in EXEMPT_DIRS: # In octal! 493 == 0755
suspect_entries.append(entry)
for filename in filenames:
entry = os.path.relpath(
os.path.join(root, filename), CODE_DIR
)
if entry in IGNORE_PATHS:
continue
skip_entry = False
for ignore_path in IGNORE_PATHS:
if entry.startswith(ignore_path):
skip_entry = True
break
if skip_entry:
continue
fn_mode = stat.S_IMODE(os.stat(entry).st_mode)
if fn_mode != 420 and entry not in EXEMPT_FILES: # In octal! 420 == 0644
suspect_entries.append(entry)
try:
self.assertEqual(suspect_entries, [])
except AssertionError:
self.fail(
'Found file(s) with incorrect permissions:\n{0}'.format(
pprint.pformat(sorted(suspect_entries))
)
)
if __name__ == '__main__':
from integration import run_tests
run_tests(GitPermTestCase, needs_daemon=False)