示例#1
0
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)
示例#2
0
 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)
示例#3
0
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)
示例#4
0
    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()
示例#5
0
    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
示例#6
0
    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()
示例#7
0
    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
示例#8
0
    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()
示例#9
0
 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)
示例#10
0
 def _make_store(self, **kwargs):
     return make_store(self.db_url, table_name='another_store', **kwargs)
示例#11
0
 def _make_store(self, **kwargs):
     return make_store(self.db_url, **kwargs)
示例#12
0
 def _make_store(self, url, **kwargs):
     self.db_url = url
     self.store = make_store(url, **kwargs)
     self.c = self.store._engine.connect()
示例#13
0
 def _make_store(self, **kwargs):
     return make_store(self.db_url, table_name='another_store', **kwargs)
示例#14
0
 def _make_store(self, **kwargs):
     return make_store(self.db_url, **kwargs)
示例#15
0
 def _make_store(self, url, **kwargs):
     self.db_url = url
     self.store = make_store(url, **kwargs)
     self.c = self.store._engine.connect()
示例#16
0
 def _make_store(self, **kwargs):
     return make_store(self.db_url, table_name=self.table_name, **kwargs)
示例#17
0
 def _make_store(self, **kwargs):
     return make_store(self.db_url, table_name=self.table_name, **kwargs)