Пример #1
0
    def test_switch_mode_session(self):
        '''
            switch mode session and test if the requests on the session go through correctly
        '''
        switch_mode(user='******', password='******')
        session = rest.get_session()
        clear_session()
        switch_mode(password='******')
        try:
            rest.get('serviceengine')
        except Exception as e:
            logger.info("authentication error expected: " + str(e))
        else:
            assert 0, "Session is not getting updated based on password"
        switch_mode(session=session)
        rest.get('serviceengine')

        # REVIEW: Once session in mode is set, no further switch_mode works
        switch_mode(user='******', password='******')
        try:
            rest.get('serviceengine')
        except Exception as e:
            logger.info("authentication error expected: " + str(e))
        else:
            assert 0, "Once switched on session, no other switch mode works"
        clear_session(all_sessions=True)
Пример #2
0
    def test_switch_mode_user(self, create_new_user):
        '''
            Switch mode user and test if the session is updated correctly based on mode user
        '''
        switch_mode(user='******', password='******')
        se_1 = rest.get('serviceengine')
        session = rest.get_session()
        assert session.username == 'admin' and session.password == 'avi123'

        switch_mode(user='******')
        se_2 = rest.get('serviceengine')
        session = rest.get_session()
        assert se_1 == se_2
        assert session.username == 'test-user-1' and session.password == 'avi123'
        clear_session(all_sessions=True)
Пример #3
0
    def test_clear_session_basic(self):
        '''
            Basic usage of clear_session
        '''
        switch_mode(user='******', password='******')
        rest.get('serviceengine')
        config = get_config()
        session = rest.get_session()
        switch_mode(session=session)
        assert config.sessions and config.session

        clear_session()
        config = get_config()
        context_key = config.get_context_key()
        assert config.session is None and context_key not in config.sessions
Пример #4
0
 def test_session_expiry(self):
     '''
         Tests requests on expired sessions
     '''
     switch_mode(user='******', password='******')
     data = json.dumps({'api_idle_timeout': 1})
     rest.put('controllerproperties', data=data)
     clear_session()
     data_1 = rest.get('serviceengine')
     time.sleep(2 * 60)
     data_2 = rest.get('serviceengine')
     assert data_1 == data_2
     time.sleep(21 * 60)
     data_1 = rest.get('serviceengine')
     assert data_1 == data_2
Пример #5
0
    def test_switch_mode_password(self):
        '''
            switch mode password and test if the session is updated correctly based on mode password
        '''
        switch_mode(user='******', password='******')
        rest.get('serviceengine')
        session = rest.get_session()
        assert session.username == 'admin' and session.password == 'avi123'

        # REVIEW: switch_mode on password does nothing as of now
        switch_mode(password='******')
        try:
            rest.get('serviceengine')
        except Exception as e:
            logger.info("authentication error expected: " + str(e))
        else:
            assert 0, "Session is not getting updated based on password"
        clear_session()
Пример #6
0
    def test_get_session(self, create_new_user):
        '''
            Test get_session
                - Test if it returns the already created session if it exists
                - If there is no already created session, it should create a new session and return
        '''
        switch_mode(user='******', password='******')
        se_1 = rest.get('serviceengine')
        session_test_user = rest.get_session()

        switch_mode(user='******', password='******')
        rest.get('serviceengine')
        session = rest.get_session()
        assert session.username == 'admin' and session.password == 'avi123'

        switch_mode(user='******')
        se_2 = rest.get('serviceengine')
        session = rest.get_session()
        assert session is session_test_user and se_1 == se_2
        clear_session(all_sessions=True)
Пример #7
0
def create_new_user():
    switch_mode(user='******', password='******')
    clear_session()
    user_data = json.dumps({
        'full_name':
        'test-user-1',
        'is_active':
        True,
        'password':
        '******',
        'username':
        '******',
        'access': [{
            'role_ref': "/api/role/?name=System-Admin",
            'tenant_ref': "/api/tenant/?name=admin"
        }],
        'default_tenant_ref':
        "/api/tenant/?name=admin"
    })
    rest.post('user', data=user_data)
    clear_session()

    yield

    clear_session(all_sessions=True)
    switch_mode(user='******', password='******')
    rest.delete('user', name='test-user-1')
Пример #8
0
    def test_update_admin_user(self, create_new_user):
        '''
            Test update_admin_user
                - Test if it updates the user password correctly
                - Test if it updates the user password correctly when mode user is not the same as the passed username
        '''
        switch_mode(user='******', password='******')
        se_1 = rest.get('serviceengine')
        rest.update_admin_user('test-user-1', 'Test123', 'avi123')
        clear_session()

        # REVIEW:
        #   when the passed username to update_admin_user is not the same as mode user
        #       - update_admin_user fails
        #       - Also, sets wrong password on the mode
        # Should this be fixed?
        switch_mode(user='******', password='******')
        rest.update_admin_user('test-user-1', 'avi123', 'Test123')

        switch_mode(user='******', password='******')
        se_2 = rest.get('serviceengine')
        assert se_1 == se_2
Пример #9
0
    def test_clear_session_making_get_request(self):
        '''
            Test if get() requests work as expected after clearing sessions
        '''
        switch_mode(user='******', password='******')
        se_1 = rest.get('serviceengine')
        session = rest.get_session()

        switch_mode(password='******')
        # This should pass because it uses already created session
        se_2 = rest.get('serviceengine')
        assert se_1 == se_2
        clear_session()
        try:
            # This should fail during authentication(uses password Temp123)
            rest.get('serviceengine')
        except Exception as e:
            logger.info('Authentication failure expected: ' + str(e))
        else:
            assert 0, 'Sessions are not cleared, Still using password avi123'

        switch_mode(password='******')
        clear_session()
Пример #10
0
    def test_clear_session_making_get_request(self):
        '''
            test_clear_session_making_get_requests
                - Make a get request after clear_session and verify that the request uses mode user and password
        '''
        switch_mode(user='******', password='******')
        rest.get('serviceengine')
        session = rest.get_session()

        switch_mode(password='******')
        # This should pass because it uses already created session
        rest.get('serviceengine')
        clear_session()
        try:
            # This should fail during authentication(uses password Temp123)
            rest.get('serviceengine')
        except Exception as e:
            logger.info('Authentication failure expected: ' + str(e))
        else:
            assert 0, 'Sessions are not cleared, Still using password avi123'

        switch_mode(password='******')
        clear_session()
Пример #11
0
    def test_clear_session_two_users(self, create_new_user):
        '''
            test_clear_session_two_users
                - Test clear_session with two user sessions
                - When all_sessions=True is passed, all the existing sessions should be removed
        '''
        switch_mode(user='******', password='******')
        rest.get('serviceengine')
        config = get_config()
        context_key_admin = config.get_context_key()

        switch_mode(user='******', password='******')
        rest.get('serviceengine')
        context_key_test_user = config.get_context_key()

        assert context_key_test_user in config.sessions and context_key_admin in config.sessions
        clear_session()
        assert context_key_test_user not in config.sessions and context_key_admin in config.sessions
        rest.get('serviceengine')
        assert context_key_test_user in config.sessions and context_key_admin in config.sessions
        clear_session(all_sessions=True)
        assert context_key_test_user not in config.sessions and context_key_admin not in config.sessions
        clear_session(all_sessions=True)
Пример #12
0
    def test_clear_session_two_users(self, create_new_user):
        '''
            Test clear_session
                - By default, clear_session() clears the current mode's session
                - When all_sessions=True is passed, it should clear all existing sessions
        '''
        switch_mode(user='******', password='******')
        rest.get('serviceengine')
        config = get_config()
        context_key_admin = config.get_context_key()

        switch_mode(user='******', password='******')
        se_1 = rest.get('serviceengine')
        context_key_test_user = config.get_context_key()

        assert context_key_test_user in config.sessions and context_key_admin in config.sessions
        clear_session()
        assert context_key_test_user not in config.sessions and context_key_admin in config.sessions
        se_2 = rest.get('serviceengine')
        assert se_1 == se_2
        assert context_key_test_user in config.sessions and context_key_admin in config.sessions
        clear_session(all_sessions=True)
        assert context_key_test_user not in config.sessions and context_key_admin not in config.sessions
        clear_session(all_sessions=True)