test: restricted QB
This commit is contained in:
parent
496e5b513b
commit
b64c03d83d
1 changed files with 39 additions and 0 deletions
|
|
@ -139,3 +139,42 @@ class TestServerScript(unittest.TestCase):
|
|||
|
||||
server_script.disabled = 1
|
||||
server_script.save()
|
||||
|
||||
def test_restricted_qb(self):
|
||||
todo = frappe.get_doc(doctype="ToDo", description="QbScriptTestNote")
|
||||
todo.insert()
|
||||
|
||||
script = frappe.get_doc(
|
||||
doctype='Server Script',
|
||||
name='test_qb_restrictions',
|
||||
script_type = 'API',
|
||||
api_method = 'test_qb_restrictions',
|
||||
allow_guest = 1,
|
||||
# whitelisted update
|
||||
script = f'''
|
||||
frappe.db.set_value("ToDo", "{todo.name}", "description", "safe")
|
||||
'''
|
||||
)
|
||||
script.insert()
|
||||
script.execute_method()
|
||||
|
||||
todo.reload()
|
||||
self.assertEqual(todo.description, "safe")
|
||||
|
||||
# unsafe update
|
||||
script.script = f"""
|
||||
todo = frappe.qb.DocType("ToDo")
|
||||
frappe.qb.update(todo).set(todo.description, "unsafe").where(todo.name == "{todo.name}").run()
|
||||
"""
|
||||
script.save()
|
||||
self.assertRaises(frappe.PermissionError, script.execute_method)
|
||||
todo.reload()
|
||||
self.assertEqual(todo.description, "safe")
|
||||
|
||||
# safe select
|
||||
script.script = f"""
|
||||
todo = frappe.qb.DocType("ToDo")
|
||||
frappe.qb.from_(todo).select(todo.name).where(todo.name == "{todo.name}").run()
|
||||
"""
|
||||
script.save()
|
||||
script.execute_method()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue