Changeset: d2d362b286c5 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=d2d362b286c5 Removed Files: sql/test/BugTracker-2018/Tests/grant-role-not-idempotent.Bug-6660.stable.err sql/test/BugTracker-2018/Tests/grant-role-not-idempotent.Bug-6660.stable.out Modified Files: sql/test/BugTracker-2018/Tests/grant-role-not-idempotent.Bug-6660.SQL.py Branch: default Log Message:
converted & cleaned up diffs (136 lines): diff --git a/sql/test/BugTracker-2018/Tests/grant-role-not-idempotent.Bug-6660.SQL.py b/sql/test/BugTracker-2018/Tests/grant-role-not-idempotent.Bug-6660.SQL.py --- a/sql/test/BugTracker-2018/Tests/grant-role-not-idempotent.Bug-6660.SQL.py +++ b/sql/test/BugTracker-2018/Tests/grant-role-not-idempotent.Bug-6660.SQL.py @@ -1,67 +1,35 @@ -import sys, os, pymonetdb - -db = os.getenv("TSTDB") -port = int(os.getenv("MAPIPORT")) - -client1 = pymonetdb.connect(database=db, port=port, autocommit=True, username='monetdb', password='monetdb') -cur1 = client1.cursor() -cur1.execute('create user "mydummyuser" with password \'mydummyuser\' name \'mydummyuser\' schema "sys";') -cur1.close() -client1.close() +### +# Check that GRANT a ROLE to a USER once works, but GRANT it a second time is +# properly rejected with "GRANT: User '<usr>' already has ROLE '<role>'", +# which also prevents the related problems described in this bug, i.e. +# duplicate entries are created in sys.user_role and subsequent REVOKE +# doesn't work. +### -client1 = pymonetdb.connect(database=db, port=port, autocommit=True, username='mydummyuser', password='mydummyuser') -cur1 = client1.cursor() -try: - cur1.execute('set role "sysadmin"; --error') - sys.stderr.write("Exception expected") -except pymonetdb.DatabaseError as e: - if "Role (sysadmin) missing" not in str(e): - sys.stderr.write("Error: Role (sysadmin) missing") -cur1.close() -client1.close() +from MonetDBtesting.sqltest import SQLTestCase -client1 = pymonetdb.connect(database=db, port=port, autocommit=True, username='monetdb', password='monetdb') -cur1 = client1.cursor() -cur1.execute('select count(*) from "user_role" where "login_id" in (select "id" from "sys"."auths" where "name" = \'mydummyuser\');') -if cur1.fetchall() != [(0,)]: - sys.stderr.write('Expected result: [(0,)]') -cur1.execute('grant "sysadmin" to "mydummyuser";') -cur1.close() -client1.close() +with SQLTestCase() as mdb: + mdb.connect(username="monetdb", password="monetdb") + mdb.execute("create user mydummyuser with password 'mydummyuser' name 'mydummyuser' schema sys;").assertSucceeded() + + with SQLTestCase() as tc: + tc.connect(username="mydummyuser", password="mydummyuser") + tc.execute("set role sysadmin;").assertFailed(err_code="42000", err_message="Role (sysadmin) missing") -client1 = pymonetdb.connect(database=db, port=port, autocommit=True, username='mydummyuser', password='mydummyuser') -cur1 = client1.cursor() -cur1.execute('set role "sysadmin";') -cur1.close() -client1.close() + mdb.execute("select count(*) from user_role where login_id in (select id from sys.auths where name = 'mydummyuser');").assertDataResultMatch([(0,)]) + mdb.execute("grant sysadmin to mydummyuser;").assertSucceeded() + mdb.execute("select count(*) from user_role where login_id in (select id from sys.auths where name = 'mydummyuser');").assertDataResultMatch([(1,)]) + + tc.execute("set role sysadmin;").assertSucceeded() + + mdb.execute("grant sysadmin to mydummyuser;").assertFailed(err_code="M1M05", err_message="GRANT: User 'mydummyuser' already has ROLE 'sysadmin'") + mdb.execute("select count(*) from user_role where login_id in (select id from sys.auths where name = 'mydummyuser');").assertDataResultMatch([(1,)]) -client1 = pymonetdb.connect(database=db, port=port, autocommit=True, username='monetdb', password='monetdb') -cur1 = client1.cursor() -cur1.execute('select count(*) from "user_role" where "login_id" in (select "id" from "sys"."auths" where "name" = \'mydummyuser\');') -if cur1.fetchall() != [(1,)]: - sys.stderr.write('Expected result: [(1,)]') -try: - cur1.execute('grant "sysadmin" to "mydummyuser"; --error') - sys.stderr.write("Exception expected") -except pymonetdb.DatabaseError as e: - if "User 'mydummyuser' already has ROLE 'sysadmin'" not in str(e): - sys.stderr.write("Error: User 'mydummyuser' already has ROLE 'sysadmin'") -cur1.execute('select count(*) from "user_role" where "login_id" in (select "id" from "sys"."auths" where "name" = \'mydummyuser\');') -if cur1.fetchall() != [(1,)]: - sys.stderr.write('Expected result: [(1,)]') -cur1.execute('revoke "sysadmin" from "mydummyuser";') -cur1.execute('select count(*) from "user_role" where "login_id" in (select "id" from "sys"."auths" where "name" = \'mydummyuser\');') -if cur1.fetchall() != [(0,)]: - sys.stderr.write('Expected result: [(0,)]') -try: - cur1.execute('revoke "sysadmin" from "mydummyuser"; --error') - sys.stderr.write("Exception expected") -except pymonetdb.DatabaseError as e: - if "User 'mydummyuser' does not have ROLE 'sysadmin'" not in str(e): - sys.stderr.write("Error: User 'mydummyuser' does not have ROLE 'sysadmin'") -cur1.execute('select count(*) from "user_role" where "login_id" in (select "id" from "sys"."auths" where "name" = \'mydummyuser\');') -if cur1.fetchall() != [(0,)]: - sys.stderr.write('Expected result: [(0,)]') -cur1.execute('drop user "mydummyuser";') -cur1.close() -client1.close() + mdb.execute("revoke sysadmin from mydummyuser;").assertSucceeded() + mdb.execute("select count(*) from user_role where login_id in (select id from sys.auths where name = 'mydummyuser');").assertDataResultMatch([(0,)]) + + mdb.execute("revoke sysadmin from mydummyuser;").assertFailed(err_code="01006", err_message="REVOKE: User 'mydummyuser' does not have ROLE 'sysadmin'") + mdb.execute("select count(*) from user_role where login_id in (select id from sys.auths where name = 'mydummyuser');").assertDataResultMatch([(0,)]) + + # clean up + mdb.execute("drop user mydummyuser;").assertSucceeded() diff --git a/sql/test/BugTracker-2018/Tests/grant-role-not-idempotent.Bug-6660.stable.err b/sql/test/BugTracker-2018/Tests/grant-role-not-idempotent.Bug-6660.stable.err deleted file mode 100644 --- a/sql/test/BugTracker-2018/Tests/grant-role-not-idempotent.Bug-6660.stable.err +++ /dev/null @@ -1,12 +0,0 @@ -stderr of test 'grant-role-not-idempotent.Bug-6660` in directory 'sql/test/BugTracker-2018` itself: - - -# 17:35:19 > -# 17:35:19 > "/usr/bin/python2" "grant-role-not-idempotent.Bug-6660.py" "grant-role-not-idempotent.Bug-6660" -# 17:35:19 > - - -# 17:35:20 > -# 17:35:20 > "Done." -# 17:35:20 > - diff --git a/sql/test/BugTracker-2018/Tests/grant-role-not-idempotent.Bug-6660.stable.out b/sql/test/BugTracker-2018/Tests/grant-role-not-idempotent.Bug-6660.stable.out deleted file mode 100644 --- a/sql/test/BugTracker-2018/Tests/grant-role-not-idempotent.Bug-6660.stable.out +++ /dev/null @@ -1,12 +0,0 @@ -stdout of test 'grant-role-not-idempotent.Bug-6660` in directory 'sql/test/BugTracker-2018` itself: - - -# 17:35:19 > -# 17:35:19 > "/usr/bin/python2" "grant-role-not-idempotent.Bug-6660.py" "grant-role-not-idempotent.Bug-6660" -# 17:35:19 > - - -# 17:35:20 > -# 17:35:20 > "Done." -# 17:35:20 > - _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list