Changeset: 0289341ab500 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=0289341ab500 Modified Files: sql/test/Users/Tests/grantRevokeAndGrantAgain.Bug-3765.SQL.py Branch: mtest Log Message:
convert tests for grantRevokeAndGrantAgain diffs (truncated from 343 to 300 lines): diff --git a/sql/test/Users/Tests/grantRevokeAndGrantAgain.Bug-3765.SQL.py b/sql/test/Users/Tests/grantRevokeAndGrantAgain.Bug-3765.SQL.py --- a/sql/test/Users/Tests/grantRevokeAndGrantAgain.Bug-3765.SQL.py +++ b/sql/test/Users/Tests/grantRevokeAndGrantAgain.Bug-3765.SQL.py @@ -5,132 +5,237 @@ # Assess that it is possible to regrant the revoked privilege. ### -import os, sys -try: - from MonetDBtesting import process -except ImportError: - import process +from MonetDBtesting.sqltest import SQLTestCase + +with SQLTestCase() as tc: + tc.connect(username="monetdb", password="monetdb") + tc.execute(""" + CREATE SCHEMA schemaTest; -def sql_test_client(user, passwd, input): - with process.client(lang="sql", user=user, passwd=passwd, communicate=True, - stdin=process.PIPE, stdout=process.PIPE, stderr=process.PIPE, - input=input, port=int(os.getenv("MAPIPORT"))) as c: - c.communicate() + CREATE USER user_delete with password 'delete' name 'user can only delete' schema schemaTest; + CREATE USER user_insert with password 'insert' name 'user can only insert' schema schemaTest; + CREATE USER user_update with password 'update' name 'user can only update' schema schemaTest; + CREATE USER user_select with password 'select' name 'user can only select' schema schemaTest; + + CREATE table schemaTest.testTable (v1 int, v2 int); + + INSERT into schemaTest.testTable values(1, 1); + INSERT into schemaTest.testTable values(2, 2); + INSERT into schemaTest.testTable values(3, 3); -sql_test_client('monetdb', 'monetdb', input="""\ -CREATE SCHEMA schemaTest; + -- Grant rights. + GRANT DELETE on table schemaTest.testTable to user_delete; + GRANT INSERT on table schemaTest.testTable to user_insert; + GRANT UPDATE on table schemaTest.testTable to user_update; + GRANT SELECT on table schemaTest.testTable to user_delete; + GRANT SELECT on table schemaTest.testTable to user_update; + GRANT SELECT on table schemaTest.testTable to user_select; + """).assertSucceeded() + -CREATE USER user_delete with password 'delete' name 'user can only delete' schema schemaTest; -CREATE USER user_insert with password 'insert' name 'user can only insert' schema schemaTest; -CREATE USER user_update with password 'update' name 'user can only update' schema schemaTest; -CREATE USER user_select with password 'select' name 'user can only select' schema schemaTest; + tc.connect(username="user_delete", password="delete") + tc.execute("DELETE FROM testTable where v1 = 2; -- should work").assertSucceeded() + tc.execute(""" + SELECT * FROM testTable; -- not enough privileges + UPDATE testTable set v1 = 2 where v2 = 7; -- not enough privileges + INSERT into testTable values (3, 3); -- not enough privileges + """).assertFailed() -CREATE table schemaTest.testTable (v1 int, v2 int); + tc.connect(username="user_update", password="update") + tc.execute("UPDATE testTable set v1 = 2 where v2 = 7;").assertSucceeded() + tc.execute(""" + SELECT * FROM testTable; -- not enough privileges + INSERT into testTable values (3, 3); -- not enough privileges + DELETE FROM testTable where v1 = 2; -- not enough privileges + """).assertFailed() -INSERT into schemaTest.testTable values(1, 1); -INSERT into schemaTest.testTable values(2, 2); -INSERT into schemaTest.testTable values(3, 3); + tc.connect(username="user_insert", password="insert") + tc.execute("INSERT into testTable values (3, 3);").assertSucceeded() + tc.execute(""" + SELECT * FROM testTable; -- not enough privileges + UPDATE testTable set v1 = 2 where v2 = 7; -- not enough privileges + DELETE FROM testTable where v1 = 2; -- not enough privileges + """).assertFailed() --- Grant rights. -GRANT DELETE on table schemaTest.testTable to user_delete; -GRANT INSERT on table schemaTest.testTable to user_insert; -GRANT UPDATE on table schemaTest.testTable to user_update; -GRANT SELECT on table schemaTest.testTable to user_delete; -GRANT SELECT on table schemaTest.testTable to user_update; -GRANT SELECT on table schemaTest.testTable to user_select; + tc.connect(username="user_select", password="select") + tc.execute("SELECT * FROM testTable;").assertSucceeded() + tc.execute(""" + SELECT * FROM testTable; -- not enough privileges + UPDATE testTable set v1 = 2 where v2 = 7; -- not enough privileges + DELETE FROM testTable where v1 = 2; -- not enough privileges + """).assertFailed() -""") + tc.connect(username="monetdb", password="monetdb") + tc.execute(""" + SELECT * FROM schemaTest.testTable; + REVOKE DELETE on schemaTest.testTable from user_delete; + REVOKE INSERT on schemaTest.testTable from user_insert; + REVOKE UPDATE on schemaTest.testTable from user_update; + REVOKE SELECT on schemaTest.testTable from user_select; + """).assertSucceeded() -sql_test_client('user_delete', 'delete', input="""\ -DELETE FROM testTable where v1 = 2; -- should work --- Check all the other privileges (they should fail). -SELECT * FROM testTable; -- not enough privileges -UPDATE testTable set v1 = 2 where v2 = 7; -- not enough privileges -INSERT into testTable values (3, 3); -- not enough privileges -""") + tc.connect(username='user_delete', password='delete') + tc.execute("DELETE from testTable where v2 = 666; -- not enough privileges").assertFailed() + + tc.connect(username='user_insert', password='insert') + tc.execute("INSERT into testTable values (666, 666); -- not enough privileges").assertFailed() + + tc.connect(username='user_update', password='update') + tc.execute("UPDATE testTable set v1 = 666 where v2 = 666; -- not enough privileges").assertFailed() + + tc.connect(username='monetdb', password='monetdb') + tc.execute("SELECT * from schemaTest.testTable;").assertSucceeded() -sql_test_client('user_update', 'update', input="""\ --- Check insert. -UPDATE testTable set v1 = 2 where v2 = 7; + tc.connect(username='monetdb', password='monetdb') + tc.execute(""" + SELECT * from schemaTest.testTable; --- Check all the other privileges (they should fail). -SELECT * FROM testTable; -- not enough privileges -INSERT into testTable values (3, 3); -- not enough privileges -DELETE FROM testTable where v1 = 2; -- not enough privileges -""") + -- Grant delete rights. + GRANT DELETE on table schemaTest.testTable to user_delete; + GRANT INSERT on table schemaTest.testTable to user_insert; + GRANT UPDATE on table schemaTest.testTable to user_update; + GRANT SELECT on table schemaTest.testTable to user_select; + """).assertSucceeded() + + tc.connect(username='user_delete', password='delete') + tc.execute("DELETE from testTable where v1 = 42; -- privilege granted").assertSucceeded() + + tc.connect(username='user_insert', password='insert') + tc.execute("INSERT into testTable values (42, 42); -- privilege granted").assertSucceeded() -sql_test_client('user_insert', 'insert', input="""\ --- Check insert. -INSERT into testTable values (3, 3); + tc.connect(username='user_update', password='update') + tc.execute("UPDATE testTable set v1 = 42 where v2 = 42; -- privilege granted").assertSucceeded() + + tc.connect(username='user_select', password='select') + tc.execute("SELECT * FROM testTable where v1 = 42; -- privilege granted").assertSucceeded() --- Check all the other privileges (they should fail). -SELECT * FROM testTable; -- not enough privileges -UPDATE testTable set v1 = 2 where v2 = 7; -- not enough privileges -DELETE FROM testTable where v1 = 2; -- not enough privileges -""") + # import os, sys + # try: + # from MonetDBtesting import process + # except ImportError: + # import process + + # def sql_test_client(user, passwd, input): + # with process.client(lang="sql", user=user, passwd=passwd, communicate=True, + # stdin=process.PIPE, stdout=process.PIPE, stderr=process.PIPE, + # input=input, port=int(os.getenv("MAPIPORT"))) as c: + # c.communicate() -sql_test_client('user_select', 'select', input="""\ --- Check insert. -SELECT * FROM testTable; + # sql_test_client('monetdb', 'monetdb', input="""\ + # CREATE SCHEMA schemaTest; + + # CREATE USER user_delete with password 'delete' name 'user can only delete' schema schemaTest; +# CREATE USER user_insert with password 'insert' name 'user can only insert' schema schemaTest; +# CREATE USER user_update with password 'update' name 'user can only update' schema schemaTest; +# CREATE USER user_select with password 'select' name 'user can only select' schema schemaTest; + +# CREATE table schemaTest.testTable (v1 int, v2 int); --- Check all the other privileges (they should fail). -INSERT into testTable values (3, 3); -- not enough privileges -UPDATE testTable set v1 = 2 where v2 = 7; -- not enough privileges -DELETE FROM testTable where v1 = 2; -- not enough privileges -""") +# INSERT into schemaTest.testTable values(1, 1); +# INSERT into schemaTest.testTable values(2, 2); +# INSERT into schemaTest.testTable values(3, 3); -sql_test_client('monetdb', 'monetdb', input="""\ -SELECT * FROM schemaTest.testTable; +# -- Grant rights. +# GRANT DELETE on table schemaTest.testTable to user_delete; +# GRANT INSERT on table schemaTest.testTable to user_insert; +# GRANT UPDATE on table schemaTest.testTable to user_update; +# GRANT SELECT on table schemaTest.testTable to user_delete; +# GRANT SELECT on table schemaTest.testTable to user_update; +# GRANT SELECT on table schemaTest.testTable to user_select; + +# """) + +# sql_test_client('user_delete', 'delete', input="""\ +# DELETE FROM testTable where v1 = 2; -- should work -REVOKE DELETE on schemaTest.testTable from user_delete; -REVOKE INSERT on schemaTest.testTable from user_insert; -REVOKE UPDATE on schemaTest.testTable from user_update; -REVOKE SELECT on schemaTest.testTable from user_select; -""") +# -- Check all the other privileges (they should fail). +# SELECT * FROM testTable; -- not enough privileges +# UPDATE testTable set v1 = 2 where v2 = 7; -- not enough privileges +# INSERT into testTable values (3, 3); -- not enough privileges +# """) + +# sql_test_client('user_update', 'update', input="""\ +# -- Check insert. +# UPDATE testTable set v1 = 2 where v2 = 7; -# Next four transitions should not be allowed. -sql_test_client('user_delete', 'delete', input="""\ -DELETE from testTable where v2 = 666; -- not enough privileges -""") +# -- Check all the other privileges (they should fail). +# SELECT * FROM testTable; -- not enough privileges +# INSERT into testTable values (3, 3); -- not enough privileges +# DELETE FROM testTable where v1 = 2; -- not enough privileges +# """) + +# sql_test_client('user_insert', 'insert', input="""\ +# -- Check insert. +# INSERT into testTable values (3, 3); -sql_test_client('user_insert', 'insert', input="""\ -INSERT into testTable values (666, 666); -- not enough privileges -""") +# -- Check all the other privileges (they should fail). +# SELECT * FROM testTable; -- not enough privileges +# UPDATE testTable set v1 = 2 where v2 = 7; -- not enough privileges +# DELETE FROM testTable where v1 = 2; -- not enough privileges +# """) -sql_test_client('user_update', 'update', input="""\ -UPDATE testTable set v1 = 666 where v2 = 666; -- not enough privileges -""") +# sql_test_client('user_select', 'select', input="""\ +# -- Check insert. +# SELECT * FROM testTable; -sql_test_client('user_select', 'select', input="""\ -SELECT * FROM testTable where v1 = 666; -- not enough privileges -""") -# +# -- Check all the other privileges (they should fail). +# INSERT into testTable values (3, 3); -- not enough privileges +# UPDATE testTable set v1 = 2 where v2 = 7; -- not enough privileges +# DELETE FROM testTable where v1 = 2; -- not enough privileges +# """) + +# sql_test_client('monetdb', 'monetdb', input="""\ +# SELECT * FROM schemaTest.testTable; -# Regrant the revoked permissions to the users. -sql_test_client('monetdb', 'monetdb', input="""\ -SELECT * from schemaTest.testTable; +# REVOKE DELETE on schemaTest.testTable from user_delete; +# REVOKE INSERT on schemaTest.testTable from user_insert; +# REVOKE UPDATE on schemaTest.testTable from user_update; +# REVOKE SELECT on schemaTest.testTable from user_select; +# """) --- Grant delete rights. -GRANT DELETE on table schemaTest.testTable to user_delete; -GRANT INSERT on table schemaTest.testTable to user_insert; -GRANT UPDATE on table schemaTest.testTable to user_update; -GRANT SELECT on table schemaTest.testTable to user_select; -""") +# # Next four transitions should not be allowed. +# sql_test_client('user_delete', 'delete', input="""\ +# DELETE from testTable where v2 = 666; -- not enough privileges +# """) + +# sql_test_client('user_insert', 'insert', input="""\ +# INSERT into testTable values (666, 666); -- not enough privileges +# """) + +# sql_test_client('user_update', 'update', input="""\ +# UPDATE testTable set v1 = 666 where v2 = 666; -- not enough privileges +# """) -# Next four transitions should be allowed. -sql_test_client('user_delete', 'delete', input="""\ _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list