def test_folder_permissions(image_based_manager):

    general_cfyuser_perms = '750 cfyuser adm'
    expected_permissions = {
        '/opt/manager': general_cfyuser_perms,
        '/opt/manager/resources': general_cfyuser_perms,
        '/opt/manager/snapshot_status': general_cfyuser_perms,
        '/opt/manager/scripts/load_permissions.py': general_cfyuser_perms,
        '/opt/manager/scripts/create_system_filters.py': general_cfyuser_perms,
        '/opt/mgmtworker/config': general_cfyuser_perms,
        '/opt/mgmtworker/work': general_cfyuser_perms,
        '/opt/mgmtworker/work': general_cfyuser_perms,
        '/opt/mgmtworker/env/plugins': general_cfyuser_perms,
        '/opt/mgmtworker/env/source_plugins': general_cfyuser_perms,
        '/var/log/cloudify/rest': general_cfyuser_perms,
        '/var/log/cloudify/rabbitmq': general_cfyuser_perms,
        '/var/log/cloudify/mgmtworker': general_cfyuser_perms,
        '/var/log/cloudify/amqp-postgres': general_cfyuser_perms,
        '/var/log/cloudify/execution-scheduler': general_cfyuser_perms,
        '/opt/cloudify/encryption/update-encryption-key': '550 root cfyuser',
    }

    for path in expected_permissions:
        output = image_based_manager.run_command(
            'stat -c "%a %U %G" {}'.format(path)).stdout
        assert expected_permissions[path] in output

@@ -44,762 +44,832 @@
 ager
+, logger
 ):%0A
-%0A
     
-general_cfyuser_perms = '750 cfyuser adm'%0A    expected_permissions = %7B%0A        '/opt/manager': general_cfyuser_perms,%0A        '/opt/manager/resources': general_cfyuser_perms,%0A        '/opt/manager/snapshot_status': general_cfyuser_perms,%0A        '/opt/manager/scripts/load_permissions.py': general_cfyuser_perms,%0A        '/opt/manager/scripts/create_system_filters.py': general_cfyuser_perms,%0A        '/opt/mgmtworker/config': general_cfyuser_perms,%0A        '/opt/mgmtworker/work': general_cfyuser_perms,%0A        '/opt/mgmtworker/work': general_cfyuser_perms,%0A        '/opt/mgmtworker/env/plugins': general_cfyuser_perms,%0A        '/opt/mgmtworker/env/source_plugins': general_cfyuser_perms,%0A        '/var/log/cloudify/rest': general_cfyus
+mode, user, group = _get_path_permissions(image_based_manager,%0A                                              '/opt/manager',%0A                                              logger)%0A%0A    assert user == 'cfyuser'%0A    assert group == 'cfyuser'%0A    # We require that /opt/manager not be world-accessible%0A    _check_file_mode(mode, expected_other_perms='0')%0A%0A%0Adef _get_path_permissions(manager, path, logger):%0A    perms = manager.run_command('stat -c %22%25a %25U %25G%22 %7B%7D'.format(path)).stdout%0A%0A    # The result should be something like %22750 cfyuser cfyuser%5Cn%22%0A    perms = perms.strip()%0A    mode, user, group = perms.split()%0A    logger.info('Path %25s has mode %25s, user %25s, group %25s',%0A                path, mode, user, group)%0A    return mode, user, group%0A%0A%0Adef _check_file_mode(mode,%0A                     expected_own
 er_perms
 ,%0A  
@@ -856,32 +856,37 @@
 cted_owner_perms
+=None
 ,%0A        '/var/
@@ -883,260 +883,220 @@
     
-'/var/log/cloudify/rabbitmq': general_cfyuser_perms,%0A        '/var/log/cloudify/mgmtworker': general_cfyuser_perms,%0A        '/var/log/cloudify/amqp-postgres': general_cfyuser_perms,%0A        '/var/log/cloudify/
+             expected_group_perms=None,%0A                     expected_other_perms=None):%0A    assert len(mode) == 3, %22File mode should have a length of 3%22%0A    owner, group, other = mode%0A    if 
 ex
+p
 ec
-ution-scheduler': general_cfyus
+ted_own
 er_perms
 ,%0A  
@@ -1091,17 +1091,17 @@
 er_perms
-,
+:
 %0A       
@@ -1105,278 +1105,189 @@
     
-'/opt/cloudify/encryption/update-encryption-key': '550 root cfyuser',%0A    %7D%0A%0A    for path in expected_permissions:%0A        output = image_based_manager.run_command(%0A            'stat -c %22%25a %25U %25G%22 %7B%7D'.format(path)).stdout%0A        assert expected_permissions%5Bpath%5D in output
+assert expected_owner_perms == owner%0A    if expected_group_perms:%0A        assert expected_group_perms == group%0A    if expected_other_perms:%0A        assert expected_other_perms == other
 %0A

Check desired folder permissions