示例#1
0
def test_positive_change_session(admin_user, non_admin_user, target_sat):
    """Change from existing session to a different session

    :id: b6ea6f3c-fcbd-4e7b-97bd-f3e0e6b9da8f

    :Steps:

        1. Set use_sessions
        2. Authenticate, assert credentials are not demanded
           on next command run
        3. Login as a different user

    :CaseImportance: High

    :expectedresults: The session is altered

    """
    result = configure_sessions(target_sat)
    assert result == 0, 'Failed to configure hammer sessions'
    AuthLogin.basic({'username': admin_user['login'], 'password': password})
    result = Auth.with_user().status()
    assert LOGEDIN_MSG.format(admin_user['login']) in result[0]['message']
    # list organizations without supplying credentials
    assert User.with_user().list()
    AuthLogin.basic({
        'username': non_admin_user['login'],
        'password': password
    })
    result = Auth.with_user().status()
    assert LOGEDIN_MSG.format(non_admin_user['login']) in result[0]['message']
    assert User.with_user().list()
示例#2
0
    def test_negative_no_permissions(self):
        """Attempt to execute command out of user's permissions

        :id: 756f666f-270a-4b02-b587-a2ab09b7d46c

        :expectedresults: Command is not executed

        """
        result = configure_sessions()
        self.assertEqual(result, 0, 'Failed to configure hammer sessions')
        AuthLogin.basic({'username': self.uname_viewer, 'password': self.password})
        result = Auth.with_user().status()
        self.assertIn(LOGEDIN_MSG.format(self.uname_viewer), result[0]['message'])
        # try to update user from viewer's session
        with self.assertRaises(CLIReturnCodeError):
            User.with_user().update({'login': self.uname_admin, 'new-login': gen_string('alpha')})
示例#3
0
def _update_test_user(cls_or_instance, options=None):
    """Helper function which updates test user stored on a class or
    instance.
    """
    options = options or {}
    options['id'] = cls_or_instance.user['id']
    user_cmd = User.with_user(cls_or_instance.login, cls_or_instance.password)
    return user_cmd.update(options)
示例#4
0
def _update_test_user(cls_or_instance, options=None):
    """Helper function which updates test user stored on a class or
    instance.
    """
    options = options or {}
    options['id'] = cls_or_instance.user['id']
    user_cmd = User.with_user(cls_or_instance.login, cls_or_instance.password)
    return user_cmd.update(options)
示例#5
0
    def test_negative_no_permissions(self):
        """Attempt to execute command out of user's permissions

        :id: 756f666f-270a-4b02-b587-a2ab09b7d46c

        :expectedresults: Command is not executed

        """
        result = configure_sessions()
        self.assertEqual(result, 0, 'Failed to configure hammer sessions')
        Auth.login({'username': self.uname_viewer, 'password': self.password})
        result = Auth.with_user().status()
        self.assertIn(
            LOGEDIN_MSG.format(self.uname_viewer),
            result[0][u'message']
        )
        # try to update user from viewer's session
        with self.assertRaises(CLIReturnCodeError):
            User.with_user().update({
                'login': self.uname_admin,
                'new-login': gen_string('alpha'),
            })
示例#6
0
def test_negative_no_permissions(admin_user, non_admin_user):
    """Attempt to execute command out of user's permissions

    :id: 756f666f-270a-4b02-b587-a2ab09b7d46c

    :expectedresults: Command is not executed

    """
    result = configure_sessions()
    assert result == 0, 'Failed to configure hammer sessions'
    AuthLogin.basic({
        'username': non_admin_user['login'],
        'password': password
    })
    result = Auth.with_user().status()
    assert LOGEDIN_MSG.format(non_admin_user['login']) in result[0]['message']
    # try to update user from viewer's session
    with pytest.raises(CLIReturnCodeError):
        User.with_user().update({
            'login': admin_user['login'],
            'new-login': gen_string('alpha')
        })
示例#7
0
def _test_user_info(cls_or_instance):
    """Helper function which fetch test user data stored on a class or
    instance.
    """
    user_cmd = User.with_user(cls_or_instance.login, cls_or_instance.password)
    return user_cmd.info({'id': cls_or_instance.user['id']})
示例#8
0
    def test_system_admin_role_end_to_end(self):
        """Test System admin role with a end to end workflow

        :id: da6b3549-d1cf-44fc-869f-08d15d407fa2

        :steps:

            1. Create a System admin role user1
            2. Login with the user1 and change global settings
                "Out of sync interval" to 31
            3. Create user2 with system admin role
            4. Login with user2 to create a Organization
            5. Clone a Org-admin role
            6. Edit the Architecture Filter and search name  =  x86_64
            7. Create a User with Cloned Org admin
            8. Login with user.

        :expectedresults:

            1. User should be assigned with System Admin role.
            2. User with sys admin role should be able to update settings
            3. User with sys admin role should be able to create users and
                assign Organizations to them.
            4. System Admin role should be able to create Organization admins
            5. User with sys admin role should be able to edit filters on roles

        :CaseLevel: System
        """
        org = make_org()
        location = make_location()
        common_pass = gen_string('alpha')
        role = Role.info({'name': 'System admin'})
        system_admin_1 = make_user(
            {
                'password': common_pass,
                'organization-ids': org['id'],
                'location-ids': location['id'],
            }
        )
        User.add_role({'id': system_admin_1['id'], 'role-id': role['id']})
        Settings.with_user(username=system_admin_1['login'], password=common_pass).set(
            {'name': "outofsync_interval", 'value': "32"}
        )
        sync_time = Settings.list({'search': 'name=outofsync_interval'})[0]
        # Asserts if the setting was updated successfully
        assert '32' == sync_time['value']

        # Create another System Admin user using the first one
        system_admin = User.with_user(
            username=system_admin_1['login'], password=common_pass
        ).create(
            {
                'auth-source-id': 1,
                'firstname': gen_string('alpha'),
                'lastname': gen_string('alpha'),
                'login': gen_string('alpha'),
                'mail': '{}@example.com'.format(gen_string('alpha')),
                'password': common_pass,
                'organizations': org['name'],
                'role-ids': role['id'],
                'locations': location['name'],
            }
        )
        # Create the Org Admin user
        org_role = Role.with_user(username=system_admin['login'], password=common_pass).clone(
            {
                'name': 'Organization admin',
                'new-name': gen_string('alpha'),
                'organization-ids': org['id'],
                'location-ids': location['id'],
            }
        )
        org_admin = User.with_user(username=system_admin['login'], password=common_pass).create(
            {
                'auth-source-id': 1,
                'firstname': gen_string('alpha'),
                'lastname': gen_string('alpha'),
                'login': gen_string('alpha'),
                'mail': '{}@example.com'.format(gen_string('alpha')),
                'password': common_pass,
                'organizations': org['name'],
                'role-ids': org_role['id'],
                'location-ids': location['id'],
            }
        )
        # Assert if the cloning was successful
        assert org_role['id'] is not None
        org_role_filters = Role.filters({'id': org_role['id']})
        search_filter = None
        for arch_filter in org_role_filters:
            if arch_filter['resource-type'] == 'Architecture':
                search_filter = arch_filter
                break
        Filter.with_user(username=system_admin['login'], password=common_pass).update(
            {'role-id': org_role['id'], 'id': arch_filter['id'], 'search': 'name=x86_64'}
        )
        # Asserts if the filter is updated
        assert 'name=x86_64' in Filter.info({'id': search_filter['id']}).values()
        org_admin = User.with_user(username=system_admin['login'], password=common_pass).info(
            {'id': org_admin['id']}
        )
        # Asserts Created Org Admin
        assert org_role['name'] in org_admin['roles']
        assert org['name'] in org_admin['organizations']
示例#9
0
def _test_user_info(cls_or_instance):
    """Helper function which fetch test user data stored on a class or
    instance.
    """
    user_cmd = User.with_user(cls_or_instance.login, cls_or_instance.password)
    return user_cmd.info({'id': cls_or_instance.user['id']})
示例#10
0
    def test_system_admin_role_end_to_end(self):
        """Test System admin role with a end to end workflow

        :id: da6b3549-d1cf-44fc-869f-08d15d407fa2

        :steps:

            1. Create a System admin role user1
            2. Login with the user1 and change global settings
                "Out of sync interval" to 31
            3. Create user2 with system admin role
            4. Login with user2 to create a Organization
            5. Clone a Org-admin role
            6. Edit the Architecture Filter and search name  =  x86_64
            7. Create a User with Cloned Org admin
            8. Login with user.

        :expectedresults:

            1. User should be assigned with System Admin role.
            2. User with sys admin role should be able to update settings
            3. User with sys admin role should be able to create users and
                assign Organizations to them.
            4. System Admin role should be able to create Organization admins
            5. User with sys admin role should be able to edit filters on roles

        :CaseLevel: System
        """
        org = make_org()
        location = make_location()
        common_pass = gen_string('alpha')
        role = Role.info({'name': 'System admin'})
        system_admin_1 = make_user({
            'password': common_pass,
            'organization-ids': org['id'],
            'location-ids': location['id']
            })
        User.add_role({
            'id': system_admin_1['id'],
            'role-id': role['id']
            })
        Settings.with_user(
            username=system_admin_1['login'],
            password=common_pass).set({
                'name': "outofsync_interval",
                'value': "32"
                })
        sync_time = Settings.list({
            'search': 'name=outofsync_interval'
            })[0]
        # Asserts if the setting was updated successfully
        self.assertEqual('32', sync_time['value'])

        # Create another System Admin user using the first one
        system_admin = User.with_user(
                username=system_admin_1['login'],
                password=common_pass).create({
                    u'auth-source-id': 1,
                    u'firstname': gen_string('alpha'),
                    u'lastname': gen_string('alpha'),
                    u'login': gen_string('alpha'),
                    u'mail': '{0}@example.com'.format(gen_string('alpha')),
                    u'password': common_pass,
                    u'organizations': org['name'],
                    u'role-ids': role['id'],
                    u'locations': location['name']
                    })
        # Create the Org Admin user
        org_role = Role.with_user(
            username=system_admin['login'],
            password=common_pass).clone({
                'name': 'Organization admin',
                'new-name': gen_string('alpha'),
                'organization-ids': org['id'],
                'location-ids': location['id']
                })
        org_admin = User.with_user(
                username=system_admin['login'],
                password=common_pass).create({
                    u'auth-source-id': 1,
                    u'firstname': gen_string('alpha'),
                    u'lastname': gen_string('alpha'),
                    u'login': gen_string('alpha'),
                    u'mail': '{0}@example.com'.format(gen_string('alpha')),
                    u'password': common_pass,
                    u'organizations': org['name'],
                    u'role-ids': org_role['id'],
                    u'location-ids': location['id']
                    })
        # Assert if the cloning was successful
        self.assertIsNotNone(org_role['id'])
        org_role_filters = Role.filters({'id': org_role['id']})
        search_filter = None
        for arch_filter in org_role_filters:
            if arch_filter['resource-type'] == 'Architecture':
                search_filter = arch_filter
                break
        Filter.with_user(
            username=system_admin['login'],
            password=common_pass).update({
                'role-id': org_role['id'],
                'id': arch_filter['id'],
                'search': 'name=x86_64'
                })
        # Asserts if the filter is updated
        self.assertIn('name=x86_64',
                      Filter.info({
                          'id': search_filter['id']
                            }).values()
                      )
        org_admin = User.with_user(
            username=system_admin['login'],
            password=common_pass).info({'id': org_admin['id']})
        # Asserts Created Org Admin
        self.assertIn(org_role['name'], org_admin['roles'])
        self.assertIn(org['name'], org_admin['organizations'])