def test_custom_schema(self): query = 'SELECT * FROM custom_table;' assert validate_osquery_query(query) is False try: # This is a bit hacky, but it clears the mock DB so the next call # will re-create it. osquery_mock_db.db = None current_app.config['DOORMAN_EXTRA_SCHEMA'].append( 'CREATE TABLE custom_table (id INTEGER);' ) assert validate_osquery_query(query) is True finally: # Remove final entry from the config. current_app.config['DOORMAN_EXTRA_SCHEMA'] = \ current_app.config['DOORMAN_EXTRA_SCHEMA'][:-1]
def test_bad_table(self): query = 'SELECT * FROM a_table_that_does_not_exist;' assert validate_osquery_query(query) is False
def test_syntax_error(self): query = 'SELECT * FROM' assert validate_osquery_query(query) is False
def test_complex_validate(self): # From Facebook's blog post: https://code.facebook.com/posts/844436395567983/introducing-osquery/ query = 'SELECT DISTINCT process.name, listening.port, listening.address, process.pid FROM processes AS process JOIN listening_ports AS listening ON process.pid = listening.pid;' assert validate_osquery_query(query) is True
def test_simple_validate(self): query = 'SELECT * FROM osquery_info;' assert validate_osquery_query(query) is True
def __call__(self, form, field): if not validate_osquery_query(field.data): raise ValidationError(self.message)
def __call__(self, form, field): if not validate_osquery_query(field.data): raise ValidationError(self.message)