Changeset: e914f4efd580 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=e914f4efd580 Removed Files: sql/test/Users/Tests/changeSchemaUser.reqtests sql/test/Users/Tests/createSetUp.sql sql/test/Users/Tests/createSetUp.test Modified Files: sql/test/Users/Tests/All sql/test/Users/Tests/changeSchemaUser.SQL.py Branch: default Log Message:
cleaned up - removed all dependencies on createSetUp - all tests in this dir are now stand-alone diffs (197 lines): diff --git a/sql/test/Users/Tests/All b/sql/test/Users/Tests/All --- a/sql/test/Users/Tests/All +++ b/sql/test/Users/Tests/All @@ -1,17 +1,16 @@ -function_privs -role -table -table_privs -unknown_user -withGrantOption -grantMonetdb +changePasswordUser +changeSchemaUser columnRights -changePasswordUser copyinto -schemaRights -metadataConsistency createUserRollback -userCallFunction +function_privs +grantMonetdb +metadataConsistency renameUser -createSetUp -changeSchemaUser +role +schemaRights +table_privs +table +unknown_user +userCallFunction +withGrantOption diff --git a/sql/test/Users/Tests/changeSchemaUser.SQL.py b/sql/test/Users/Tests/changeSchemaUser.SQL.py --- a/sql/test/Users/Tests/changeSchemaUser.SQL.py +++ b/sql/test/Users/Tests/changeSchemaUser.SQL.py @@ -1,57 +1,56 @@ ### -# Change the default schema of a user (possible). -# Change the default schema of a user to an unexisting schema (not possible). -# Change the default schema for an unexisting user (not possible). -# Drop a user that owns a schema (not possible). +# Tests for schema assignments and changes for users ### from MonetDBtesting.sqltest import SQLTestCase -with SQLTestCase() as tc: - tc.connect(username="monetdb", password="monetdb") - tc.execute('ALTER USER "april" SET SCHEMA library').assertSucceeded() - tc.execute('ALTER USER "april2" SET SCHEMA library; --no such user').assertFailed() - tc.execute('ALTER USER "april" SET SCHEMA library2; --no such schema').assertFailed() +with SQLTestCase() as mdb: + mdb.connect(username="monetdb", password="monetdb") + mdb.execute("CREATE SCHEMA library;").assertSucceeded() + mdb.execute("CREATE TABLE library.orders(price int, name VARCHAR(100));").assertSucceeded() - tc.connect(username="april", password="april") - tc.execute('SELECT * from bank.accounts; --no such table.').assertSucceeded() - tc.execute('SELECT * from library.orders; --not enough privileges.').assertFailed() + mdb.execute("CREATE ROLE bankAdmin;").assertSucceeded() + mdb.execute("CREATE SCHEMA bank AUTHORIZATION bankAdmin;").assertSucceeded() + mdb.execute("CREATE TABLE bank.accounts(nr int, name VARCHAR(100));").assertSucceeded() - tc.connect(username="monetdb", password="monetdb") - tc.execute('ALTER USER "april" SET SCHEMA bank;').assertSucceeded() - tc.execute('CREATE SCHEMA forAlice AUTHORIZATION april;').assertSucceeded() - tc.execute('DROP user april;').assertFailed() + mdb.execute("CREATE USER april WITH PASSWORD 'april' name 'april' schema bank;").assertSucceeded() + mdb.execute("GRANT ALL ON bank.accounts to april;").assertSucceeded() + mdb.execute("GRANT bankAdmin to april;").assertSucceeded() -# import os, sys -# try: -# from MonetDBtesting import process -# except ImportError: -# import process + # Check that change the default schema for an unexisting user is not possible. + mdb.execute('ALTER USER "april2" SET SCHEMA library;').assertFailed(err_code="42M32", err_message="ALTER USER: no such user 'april2'") + # Check that change the default schema of a user to an unexisting schema is not possible. + mdb.execute('ALTER USER "april" SET SCHEMA library2;').assertFailed(err_code="3F000", err_message="ALTER USER: no such schema 'library2'") -# 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() + with SQLTestCase() as tc: + # Check that the admin can change the default schema of a user, and + # this will take effect the next time this user logs-in. + tc.connect(username="april", password="april") + tc.execute("SELECT current_schema;").assertDataResultMatch([('bank',)]) + tc.execute('SELECT * from accounts;').assertSucceeded() + mdb.execute('ALTER USER "april" SET SCHEMA library').assertSucceeded() + tc.connect(username="april", password="april") + tc.execute("SELECT current_schema;").assertDataResultMatch([('library',)]) -# sql_test_client('monetdb', 'monetdb', input="""\ -# ALTER USER "april" SET SCHEMA library; -# ALTER USER "april2" SET SCHEMA library; --no such user -# ALTER USER "april" SET SCHEMA library2; --no such schema -# """) + # Check that after the schema change, the user no longer has direct access to tables in schema 'bank' + tc.execute('SELECT * from accounts;').assertFailed(err_code="42S02", err_message="SELECT: no such table 'accounts'") + # Check that after the schema change, the user still doesn't have access to tables in schema 'library' + tc.execute('SELECT * from library.orders;').assertFailed(err_code="42000", err_message="SELECT: access denied for april to table 'library.orders'") -# # This is the new april, so these operations should fail. -# sql_test_client('april', 'april', input="""\ -# SELECT * from bank.accounts; --no such table. -# SELECT * from library.orders; --not enough privileges. -# """) - + # Check that drop a user that owns a schema is not possible. + mdb.connect(username="monetdb", password="monetdb") + mdb.execute('ALTER USER "april" SET SCHEMA bank;').assertSucceeded() + mdb.execute('CREATE SCHEMA forAlice AUTHORIZATION april;').assertSucceeded() + mdb.execute('DROP user april;').assertFailed(err_code="M1M05", err_message="DROP USER: 'april' owns a schema") -# sql_test_client('monetdb', 'monetdb', input="""\ -# ALTER USER "april" SET SCHEMA bank; -# CREATE SCHEMA forAlice AUTHORIZATION april; -# DROP user april; -# """) + # clean up + mdb.execute('DROP TABLE library.orders;').assertSucceeded() + mdb.execute('DROP TABLE bank.accounts;').assertSucceeded() + mdb.execute('ALTER USER "april" SET SCHEMA sys;').assertSucceeded() + mdb.execute('DROP SCHEMA forAlice;').assertSucceeded() + mdb.execute('DROP SCHEMA bank;').assertSucceeded() + mdb.execute('DROP SCHEMA library;').assertSucceeded() + mdb.execute('DROP USER april;').assertSucceeded() + mdb.execute('DROP ROLE bankAdmin;').assertSucceeded() - diff --git a/sql/test/Users/Tests/changeSchemaUser.reqtests b/sql/test/Users/Tests/changeSchemaUser.reqtests deleted file mode 100644 --- a/sql/test/Users/Tests/changeSchemaUser.reqtests +++ /dev/null @@ -1,1 +0,0 @@ -createSetUp diff --git a/sql/test/Users/Tests/createSetUp.sql b/sql/test/Users/Tests/createSetUp.sql deleted file mode 100644 --- a/sql/test/Users/Tests/createSetUp.sql +++ /dev/null @@ -1,14 +0,0 @@ -CREATE SCHEMA library; -CREATE TABLE library.orders(price int, name VARCHAR(100)); - -CREATE ROLE bankAdmin; -CREATE SCHEMA bank AUTHORIZATION bankAdmin; -CREATE TABLE bank.accounts(nr int, name VARCHAR(100)); -CREATE TABLE bank.loans(nr int, amount int); - -CREATE USER alice WITH PASSWORD 'alice' name 'alice' schema library; -CREATE USER april WITH PASSWORD 'april' name 'april' schema bank; - -GRANT ALL ON bank.accounts to april; -GRANT bankAdmin to april; - diff --git a/sql/test/Users/Tests/createSetUp.test b/sql/test/Users/Tests/createSetUp.test deleted file mode 100644 --- a/sql/test/Users/Tests/createSetUp.test +++ /dev/null @@ -1,31 +0,0 @@ -statement ok -CREATE SCHEMA library - -statement ok -CREATE TABLE library.orders(price int, name VARCHAR(100)) - -statement ok -CREATE ROLE bankAdmin - -statement ok -CREATE SCHEMA bank AUTHORIZATION bankAdmin - -statement ok -CREATE TABLE bank.accounts(nr int, name VARCHAR(100)) - -statement ok -CREATE TABLE bank.loans(nr int, amount int) - -statement ok -CREATE USER alice WITH PASSWORD 'alice' name 'alice' schema library - -statement ok -CREATE USER april WITH PASSWORD 'april' name 'april' schema bank - -statement ok -GRANT ALL ON bank.accounts to april - -statement ok -GRANT bankAdmin to april - - _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list