Exemplo n.º 1
0
    def __init__(self, session_id=None, **kwargs):
        '''
        Creation of a WekeSession instance
        '''
        RamSession.__init__(self, id=session_id, **kwargs)

        self.setdefault('timed_out', True)
        self.setdefault('expiration_time', None)
        self.setdefault('control_token', None)
        return
Exemplo n.º 2
0
    def __init__(self, session_id=None, **kwargs):
        '''
        Creation of a WekeSession instance
        '''
        RamSession.__init__(self, id=session_id, **kwargs)

        self.setdefault('timed_out', True)
        self.setdefault('expiration_time', None)
        self.setdefault('control_token', None)
        return
Exemplo n.º 3
0
    def test_fill(self):
        sess_mock = RamSession()
        with patch('cherrypy.session', sess_mock, create=True):
            data = {'a': 'b'}
            for _ in range(5):
                self._post("/foo", data)
                self.assertJsonBody(data)
                self.assertStatus(201)
                self.assertHeader(
                    'Content-Type', 'application/vnd.ceph.api.v{}+json'.format(
                        DEFAULT_VERSION))

            self._get("/foo")
            self.assertStatus('200 OK')
            self.assertHeader(
                'Content-Type',
                'application/vnd.ceph.api.v{}+json'.format(DEFAULT_VERSION))
            self.assertJsonBody([data] * 5)

            self._put('/foo/0', {'newdata': 'newdata'})
            self.assertStatus('200 OK')
            self.assertHeader(
                'Content-Type',
                'application/vnd.ceph.api.v{}+json'.format(DEFAULT_VERSION))
            self.assertJsonBody({'newdata': 'newdata', 'key': '0'})
    def test_requires_authentication(self):

        username = '******'
        password = '******'
        session_id = 1
        user_id = 1
        token = auth.gen_auth_token(username, password, user_id, session_id)

        cherrypy.session = RamSession()
        cherrypy.session.id = 1

        cherrypy.session['user'] = {
            'id': user_id,
            'username': username,
            'auth': True,
            'token': token
        }

        self.getPage('/')
        print(self.body)
        self.assertStatus(401)

        headers = [('Authorization', token)]

        self.getPage('/', headers=headers)
        print(self.body)
        self.assertStatus(200)
Exemplo n.º 5
0
    def transactional_setup_method(self):
        self.simulator_controller = SimulatorController()
        self.test_user = TestFactory.create_user('SimulationController_User')
        self.test_project = TestFactory.create_project(
            self.test_user, "SimulationController_Project")
        TvbProfile.current.web.RENDER_HTML = False
        self.session_stored_simulator = SimulatorAdapterModel()

        self.sess_mock = RamSession()
        self.sess_mock[KEY_USER] = self.test_user
        self.sess_mock[KEY_PROJECT] = self.test_project

        cherrypy.request.method = "POST"
Exemplo n.º 6
0
    def transactional_setup_method(self):
        self.simulator_controller = SimulatorController()
        self.test_user = TestFactory.create_user('SimulationController_User')
        self.test_project = TestFactory.create_project(self.test_user, "SimulationController_Project")
        connectivity = TestFactory.import_zip_connectivity(self.test_user, self.test_project)

        self.session_stored_simulator = SimulatorAdapterModel()
        self.session_stored_simulator.connectivity = UUID(connectivity.gid)

        self.sess_mock = RamSession()
        self.sess_mock[KEY_USER] = self.test_user
        self.sess_mock[KEY_PROJECT] = self.test_project

        cherrypy.request.method = "POST"
Exemplo n.º 7
0
    def test_good_login(self):

        cherrypy.session = RamSession()

        self.getPage('/login', method='POST', body='username=test1&password=test1pw')

        self.assertStatus(200)

        body = json.loads(self.body.decode('utf-8'))

        assert body['session'] == cherrypy.session.id

        assert cherrypy.session['user']['id'] == 1
        assert cherrypy.session['user']['username'] == 'test1'
        assert cherrypy.session['user']['auth'] == True
        assert cherrypy.session['user']['token'] == body['token']

        del cherrypy.session
Exemplo n.º 8
0
    def test_good_session(self,mock):

        cherrypy.session = RamSession()


        user = cherrypy.tools.db.session.query(UserDao).filter(UserDao.id == 2).first()



        token = gen_auth_token('test2', user.password, 2, cherrypy.session.id)
        cherrypy.session['user'] = {} 
        cherrypy.session['user']['id'] = 2
        cherrypy.session['user']['username'] = '******'
        cherrypy.session['user']['auth'] = True
        cherrypy.session['user']['token'] = token

        self.getPage('/session', method='POST', headers=[('Authorization', token)])
        print('GOOD SESSION: %s' % self.body)
        self.assertStatus(204)

        del cherrypy.session
Exemplo n.º 9
0
    def test_fill(self):
        sess_mock = RamSession()
        with patch('cherrypy.session', sess_mock, create=True):
            data = {'a': 'b'}
            for _ in range(5):
                self._post("/foo", data)
                self.assertJsonBody(data)
                self.assertStatus(201)
                self.assertHeader('Content-Type',
                                  APIVersion.DEFAULT.to_mime_type())

            self._get("/foo")
            self.assertStatus('200 OK')
            self.assertHeader('Content-Type',
                              APIVersion.DEFAULT.to_mime_type())
            self.assertJsonBody([data] * 5)

            self._put('/foo/0', {'newdata': 'newdata'})
            self.assertStatus('200 OK')
            self.assertHeader('Content-Type',
                              APIVersion.DEFAULT.to_mime_type())
            self.assertJsonBody({'newdata': 'newdata', 'key': '0'})
Exemplo n.º 10
0
 def patch_session(self, username='******', barcode='100091', role=0xFF):
     sess_mock = RamSession()
     sess_mock['username'] = username
     sess_mock['barcode'] = barcode
     sess_mock['role'] = role
     return patch('cherrypy.session', sess_mock, create=True)
Exemplo n.º 11
0
 def patch_session_none(self):
     sess_mock = RamSession()
     return patch('cherrypy.session', sess_mock, create=True)
Exemplo n.º 12
0
def root(db):
    from cherrypy.lib.sessions import RamSession
    cherrypy.session = RamSession()
    cherrypy.request.login = None
    from odmf.webpage.root import Root
    return Root()