Fixed RESQL test cases for Roles module.

This commit is contained in:
Aditya Toshniwal 2020-08-28 18:22:25 +05:30 committed by Akshay Joshi
parent 3984544bdb
commit 11d5613866
11 changed files with 77 additions and 22 deletions

View File

@ -31,7 +31,7 @@ UNION ALL
array_to_string(array_agg(sql), E'\n') AS sql
FROM
(SELECT
'GRANT ' || array_to_string(array_agg(rolname), ', ') || ' TO ' || pg_catalog.quote_ident(pg_get_userbyid(%(rid)s::OID)) ||
'GRANT ' || array_to_string(array_agg(rolname order by rolname), ', ') || ' TO ' || pg_catalog.quote_ident(pg_get_userbyid(%(rid)s::OID)) ||
CASE WHEN admin_option THEN ' WITH ADMIN OPTION;' ELSE ';' END AS sql
FROM
(SELECT

View File

@ -7,7 +7,7 @@ ALTER ROLE "Role2_$%{}[]()&*^!@""'`\/#"
VALID UNTIL '2050-01-01T00:00:00+05:30'
PASSWORD 'xxxxxx';
GRANT pg_signal_backend TO "Role2_$%{}[]()&*^!@""'`\/#" WITH ADMIN OPTION;
GRANT pg_monitor TO "Role2_$%{}[]()&*^!@""'`\/#";
GRANT test_rolemembership_1 TO "Role2_$%{}[]()&*^!@""'`\/#" WITH ADMIN OPTION;
GRANT test_rolemembership_2 TO "Role2_$%{}[]()&*^!@""'`\/#";
ALTER ROLE "Role2_$%{}[]()&*^!@""'`\/#" IN DATABASE postgres
SET application_name TO 'pg4';

View File

@ -12,8 +12,8 @@ CREATE ROLE "Role2_$%{}[]()&*^!@""'`\/#" WITH
ENCRYPTED PASSWORD '<PASSWORD>'
VALID UNTIL '<TIMESTAMPTZ_1>';
GRANT pg_monitor TO "Role2_$%{}[]()&*^!@""'`\/#";
GRANT pg_signal_backend TO "Role2_$%{}[]()&*^!@""'`\/#" WITH ADMIN OPTION;
GRANT test_rolemembership_2 TO "Role2_$%{}[]()&*^!@""'`\/#";
GRANT test_rolemembership_1 TO "Role2_$%{}[]()&*^!@""'`\/#" WITH ADMIN OPTION;
ALTER ROLE "Role2_$%{}[]()&*^!@""'`\/#" IN DATABASE postgres SET application_name TO 'pg4';

View File

@ -1,2 +1,2 @@
REVOKE ADMIN OPTION FOR pg_signal_backend FROM "Role2_$%{}[]()&*^!@""'`\/#";
GRANT pg_monitor TO "Role2_$%{}[]()&*^!@""'`\/#" WITH ADMIN OPTION;
REVOKE ADMIN OPTION FOR test_rolemembership_1 FROM "Role2_$%{}[]()&*^!@""'`\/#";
GRANT test_rolemembership_2 TO "Role2_$%{}[]()&*^!@""'`\/#" WITH ADMIN OPTION;

View File

@ -12,8 +12,8 @@ CREATE ROLE "Role2_$%{}[]()&*^!@""'`\/#" WITH
ENCRYPTED PASSWORD '<PASSWORD>'
VALID UNTIL '2050-01-01 00:00:00+05:30';
GRANT pg_signal_backend TO "Role2_$%{}[]()&*^!@""'`\/#";
GRANT pg_monitor TO "Role2_$%{}[]()&*^!@""'`\/#" WITH ADMIN OPTION;
GRANT test_rolemembership_1 TO "Role2_$%{}[]()&*^!@""'`\/#";
GRANT test_rolemembership_2 TO "Role2_$%{}[]()&*^!@""'`\/#" WITH ADMIN OPTION;
ALTER ROLE "Role2_$%{}[]()&*^!@""'`\/#" IN DATABASE postgres SET application_name TO 'pg4';

View File

@ -1 +1 @@
REVOKE pg_signal_backend FROM "Role2_$%{}[]()&*^!@""'`\/#";
REVOKE test_rolemembership_1 FROM "Role2_$%{}[]()&*^!@""'`\/#";

View File

@ -12,7 +12,7 @@ CREATE ROLE "Role2_$%{}[]()&*^!@""'`\/#" WITH
ENCRYPTED PASSWORD '<PASSWORD>'
VALID UNTIL '2050-01-01 00:00:00+05:30';
GRANT pg_monitor TO "Role2_$%{}[]()&*^!@""'`\/#" WITH ADMIN OPTION;
GRANT test_rolemembership_2 TO "Role2_$%{}[]()&*^!@""'`\/#" WITH ADMIN OPTION;
ALTER ROLE "Role2_$%{}[]()&*^!@""'`\/#" IN DATABASE postgres SET application_name TO 'pg4';

View File

@ -1 +1 @@
GRANT pg_signal_backend, pg_monitor TO "Role2_$%{}[]()&*^!@""'`\/#" WITH ADMIN OPTION;
GRANT test_rolemembership_1, test_rolemembership_2 TO "Role2_$%{}[]()&*^!@""'`\/#" WITH ADMIN OPTION;

View File

@ -12,7 +12,7 @@ CREATE ROLE "Role2_$%{}[]()&*^!@""'`\/#" WITH
ENCRYPTED PASSWORD '<PASSWORD>'
VALID UNTIL '2050-01-01 00:00:00+05:30';
GRANT pg_monitor, pg_signal_backend TO "Role2_$%{}[]()&*^!@""'`\/#" WITH ADMIN OPTION;
GRANT test_rolemembership_1, test_rolemembership_2 TO "Role2_$%{}[]()&*^!@""'`\/#" WITH ADMIN OPTION;
ALTER ROLE "Role2_$%{}[]()&*^!@""'`\/#" IN DATABASE postgres SET application_name TO 'pg4';

View File

@ -1,5 +1,49 @@
{
"scenarios": [
{
"type": "create",
"name": "Create Role 1 for testing rolemembership",
"endpoint": "NODE-role.obj",
"sql_endpoint": "NODE-role.sql_id",
"data": {
"rolname": "test_rolemembership_1",
"rolcanlogin": false,
"rolpassword": null,
"rolconnlimit": -1,
"rolsuper": false,
"rolcreaterole": false,
"rolcreatedb": false,
"rolinherit": true,
"rolcatupdate": false,
"rolreplication": false,
"rolmembership": [],
"seclabels": [],
"variables": []
},
"store_object_id": true
},
{
"type": "create",
"name": "Create Role 2 for testing rolemembership",
"endpoint": "NODE-role.obj",
"sql_endpoint": "NODE-role.sql_id",
"data": {
"rolname": "test_rolemembership_2",
"rolcanlogin": false,
"rolpassword": null,
"rolconnlimit": -1,
"rolsuper": false,
"rolcreaterole": false,
"rolcreatedb": false,
"rolinherit": true,
"rolcatupdate": false,
"rolreplication": false,
"rolmembership": [],
"seclabels": [],
"variables": []
},
"store_object_id": true
},
{
"type": "create",
"name": "Create Role",
@ -62,7 +106,7 @@
"rolconnlimit": 100,
"rolvaliduntil": "2050-01-01 00:00:00 +05:30",
"variables": { "added": [{"name":"application_name","value":"pg4","database":"postgres"}] },
"rolmembership": { "added": [{"role": "pg_signal_backend", "admin": true}, {"role": "pg_monitor", "admin": false}] }
"rolmembership": { "added": [{"role": "test_rolemembership_1", "admin": true}, {"role": "test_rolemembership_2", "admin": false}] }
},
"expected_sql_file": "alter_role_options1.sql",
"expected_msql_file": "alter_role_options1.msql",
@ -76,7 +120,7 @@
"sql_endpoint": "NODE-role.sql_id",
"msql_endpoint": "NODE-role.msql_id",
"data": {
"rolmembership": { "changed": [{"role": "pg_signal_backend", "admin": false}, {"role": "pg_monitor", "admin": true}] }
"rolmembership": { "changed": [{"role": "test_rolemembership_1", "admin": false}, {"role": "test_rolemembership_2", "admin": true}] }
},
"expected_sql_file": "alter_role_options2.sql",
"expected_msql_file": "alter_role_options2.msql",
@ -91,7 +135,7 @@
"sql_endpoint": "NODE-role.sql_id",
"msql_endpoint": "NODE-role.msql_id",
"data": {
"rolmembership": { "deleted": [{"role": "pg_signal_backend"}] }
"rolmembership": { "deleted": [{"role": "test_rolemembership_1"}] }
},
"expected_sql_file": "alter_role_options3.sql",
"expected_msql_file": "alter_role_options3.msql",
@ -107,8 +151,8 @@
"msql_endpoint": "NODE-role.msql_id",
"data": {
"rolmembership": {
"added": [{"role": "pg_signal_backend", "admin": true}],
"changed": [{"role": "pg_monitor", "admin": true}]
"added": [{"role": "test_rolemembership_1", "admin": true}],
"changed": [{"role": "test_rolemembership_2", "admin": true}]
}
},
"expected_sql_file": "alter_role_options4.sql",
@ -123,6 +167,13 @@
"endpoint": "NODE-role.obj_id",
"data": {}
},
{
"type": "delete",
"name": "Drop Role",
"endpoint": "NODE-role.obj",
"data": {"ids": ["<test_rolemembership_1>", "<test_rolemembership_2>"]},
"preprocess_data": true
},
{
"type": "create",
"name": "Create Login Role",

View File

@ -281,7 +281,7 @@ class ReverseEngineeredSQLTestCases(BaseTestGenerator):
# Store the object id based on endpoints
if 'store_object_id' in scenario:
self.store_object_ids(object_id,
scenario['data']['name'],
scenario['data'],
scenario['endpoint'])
# Compare the reverse engineering SQL
@ -324,8 +324,9 @@ class ReverseEngineeredSQLTestCases(BaseTestGenerator):
elif 'type' in scenario and scenario['type'] == 'delete':
# Get the delete url and delete the object created above.
delete_url = self.get_url(scenario['endpoint'], object_id)
delete_response = self.tester.delete(delete_url,
follow_redirects=True)
delete_response = self.tester.delete(
delete_url, data=json.dumps(scenario.get('data', {})),
follow_redirects=True)
try:
self.assertEquals(delete_response.status_code, 200)
except Exception as e:
@ -628,7 +629,7 @@ class ReverseEngineeredSQLTestCases(BaseTestGenerator):
return sql
def store_object_ids(self, object_id, object_name, endpoint):
def store_object_ids(self, object_id, object_data, endpoint):
"""
This functions will store the object id based on endpoints
:param object_id: Object id of the created node
@ -636,12 +637,15 @@ class ReverseEngineeredSQLTestCases(BaseTestGenerator):
:param endpoint:
:return:
"""
object_name = object_data.get('name', '')
if endpoint.__contains__("NODE-table"):
self.parent_ids['tid'] = object_id
elif endpoint.__contains__("NODE-foreign_data_wrapper"):
self.parent_ids['fid'] = object_id
elif endpoint.__contains__("NODE-foreign_server"):
self.parent_ids['fsid'] = object_id
elif endpoint.__contains__("NODE-role.obj"):
object_name = object_data['rolname']
# Store object id with object name
self.all_object_ids[object_name] = object_id