def test_task_objects_buggy(task): """ Test that all `Task`-like objects are persistable """ with NamedTemporaryFile(prefix='gc3libs.', suffix='.tmp') as tmp: store = make_store("sqlite://%s" % tmp.name) id = store.save(task) store.load(id)
def check_task(task): fd, tmpfile = tempfile.mkstemp() store = make_store("sqlite://%s" % tmpfile) try: id = store.save(task) store.load(id) finally: os.remove(tmpfile)
def test_task_objects_buggy(task): """ Test that all `Task`-like objects are persistable """ fd, tmpfile = tempfile.mkstemp() store = make_store("sqlite://%s" % tmpfile) try: id = store.save(task) store.load(id) finally: os.remove(tmpfile)
def setUp(self): fd, tmpfile = tempfile.mkstemp() os.remove(tmpfile) self.table_name = tmpfile.split('/')[-1] try: self.db_url = Url('mysql://*****:*****@localhost/gc3') self.store = make_store(self.db_url, table_name=self.table_name) except sqlalchemy.exc.OperationalError: raise SkipTest("Cannot connect to MySQL database.") # create a connection to the database self.conn = self.store._engine.connect()
def test_sql_injection(self): """Test if the `SqlStore` class is vulnerable to SQL injection.""" storetemp = make_store(self.db_url, table_name='sql_injection_test', extra_fields={ sqlalchemy.Column('extra', sqlalchemy.VARCHAR(length=128)): GET.extra, }) obj = SimpleTask() # obligatory XKCD citation ;-) # Ric, you can't just "cite" XKCD without inserting a # reference: http://xkcd.com/327/ obj.extra = "Robert'); DROPT TABLE sql_injection_test; --" id_ = storetemp.save(obj) obj2 = storetemp.load(id_) self.conn.execute('drop table sql_injection_test') assert obj.execution.state == obj2.execution.state
def setUp(self): fd, tmpfile = tempfile.mkstemp() os.remove(tmpfile) self.table_name = tmpfile.split('/')[-1] try: self.db_url = Url('mysql://*****:*****@localhost/gc3') self.store = make_store(self.db_url, table_name=self.table_name) except sqlalchemy.exc.OperationalError: pytest.mark.skip("Cannot connect to MySQL database.") # create a connection to the database self.conn = self.store._engine.connect() yield self.conn.execute('drop table `%s`' % self.table_name) self.conn.close()
def test_sql_injection(self): """Test if the `SqlStore` class is vulnerable to SQL injection.""" storetemp = make_store( self.db_url, table_name='sql_injection_test', extra_fields={ sqlalchemy.Column('extra', sqlalchemy.VARCHAR(length=128)): GET.extra, }) obj = SimpleTask() # obligatory XKCD citation ;-) # Ric, you can't just "cite" XKCD without inserting a # reference: http://xkcd.com/327/ obj.extra = "Robert'); DROPT TABLE sql_injection_test; --" id_ = storetemp.save(obj) obj2 = storetemp.load(id_) self.conn.execute('drop table sql_injection_test') assert obj.execution.state == obj2.execution.state
def setUp(self): # generate random table name from string import ascii_letters as letters import random self.table_name = 'test_' + (''.join( random.choice(letters) for _ in range(10))) try: self.db_url = Url('mysql://*****:*****@localhost/gc3') self.store = make_store(self.db_url, table_name=self.table_name) except sqlalchemy.exc.OperationalError: pytest.mark.skip("Cannot connect to MySQL database.") # create a connection to the database self.conn = self.store._engine.connect() yield self.conn.execute('drop table `%s`' % self.table_name) self.conn.close()
def setUp(self): self.path = tempfile.mktemp(dir='.') self.jobs_dir = os.path.abspath(self.path+'.jobs') # create old-style session self.index_csv = self.path + '.csv' # Load the old store store_url = "file://%s" % self.jobs_dir oldstore = make_store(store_url) # save something in it self.test_task_id = oldstore.save(_PStruct(a=1, b='foo')) jobidfile = open(self.index_csv, 'w') jobline = { 'jobname': 'test', 'persistent_id': self.test_task_id, 'state': 'UNKNOWN', 'info': '', } csv.DictWriter( jobidfile, ['jobname', 'persistent_id', 'state', 'info'], extrasaction='ignore').writerow(jobline) jobidfile.close() # create new-style session self.sess = Session(self.path)
def _make_store(self, **kwargs): return make_store(self.db_url, table_name='another_store', **kwargs)
def _make_store(self, **kwargs): return make_store(self.db_url, **kwargs)
def _make_store(self, url, **kwargs): self.db_url = url self.store = make_store(url, **kwargs) self.c = self.store._engine.connect()
def _make_store(self, **kwargs): return make_store(self.db_url, table_name=self.table_name, **kwargs)