Added MSQL test cases for Sequences and cover missing ACL RE-SQL test cases.

This commit is contained in:
Aditya Toshniwal 2019-08-29 14:15:34 +05:30 committed by Akshay Joshi
parent fc4bef56a0
commit d6da1cf25c
28 changed files with 452 additions and 103 deletions

View File

@ -27,3 +27,4 @@ FROM
LEFT JOIN pg_catalog.pg_roles g ON (d.grantor = g.oid)
LEFT JOIN pg_catalog.pg_roles gt ON (d.grantee = gt.oid)
GROUP BY g.rolname, gt.rolname
ORDER BY grantee

View File

@ -35,7 +35,7 @@ SELECT setval({{ seqname|qtLiteral }}, {{ data.current_value }}, true);
{% set defquery = defquery+'\n NO CYCLE' %}
{% endif %}
{% if defquery and defquery != '' %}
ALTER SEQUENCE {{ conn|qtIdent(o_data.schema, data.name) }} {{ defquery }};
ALTER SEQUENCE {{ conn|qtIdent(o_data.schema, data.name) }}{{ defquery }};
{% endif %}
{% if data.schema and data.schema != o_data.schema %}

View File

@ -1,49 +0,0 @@
{
"scenarios": [
{
"type": "create",
"name": "Create Sequence",
"endpoint": "NODE-sequence.obj",
"sql_endpoint": "NODE-sequence.sql_id",
"data": {
"name": "Seq1_$%{}[]()&*^!@\"'`\\/#",
"seqowner": "postgres",
"schema": "public",
"increment": "5",
"start": "5",
"maximum": "999",
"minimum": "5",
"cache": "1",
"cycled": false,
"relacl": [],
"securities": []
},
"expected_sql_file": "create_sequence.sql"
},{
"type": "alter",
"name": "Alter Sequence comment",
"endpoint": "NODE-sequence.obj_id",
"sql_endpoint": "NODE-sequence.sql_id",
"data": {
"comment": "Some comment"
},
"expected_sql_file": "alter_seq_comment.sql"
},{
"type": "alter",
"name": "Alter Sequence properties",
"endpoint": "NODE-sequence.obj_id",
"sql_endpoint": "NODE-sequence.sql_id",
"data": {
"current_value": "7", "increment": "12", "minimum": "2", "maximum": "9992", "cache": "2", "cycled": true
},
"expected_sql_file": "alter_seq_props.sql"
},{
"type": "delete",
"name": "Drop sequence",
"endpoint": "NODE-sequence.delete_id",
"data": {
"name": "Seq1_$%{}[]()&*^!@\"'`\\/#"
}
}
]
}

View File

@ -0,0 +1,2 @@
COMMENT ON SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
IS 'Some comment';

View File

@ -0,0 +1,21 @@
-- SEQUENCE: public."Seq1_$%{}[]()&*^!@""'`\/#"
-- DROP SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#";
CREATE SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
CYCLE
INCREMENT 12
START 7
MINVALUE 2
MAXVALUE 9992
CACHE 2;
ALTER SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
OWNER TO postgres;
COMMENT ON SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
IS 'Some comment';
GRANT ALL ON SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#" TO PUBLIC;
GRANT ALL ON SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#" TO postgres;

View File

@ -0,0 +1 @@
GRANT ALL ON SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#" TO PUBLIC;

View File

@ -0,0 +1,19 @@
-- SEQUENCE: public."Seq1_$%{}[]()&*^!@""'`\/#"
-- DROP SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#";
CREATE SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
CYCLE
INCREMENT 12
START 7
MINVALUE 2
MAXVALUE 9992
CACHE 2;
ALTER SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
OWNER TO postgres;
COMMENT ON SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
IS 'Some comment';
GRANT ALL ON SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#" TO postgres;

View File

@ -0,0 +1 @@
REVOKE ALL ON SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#" FROM PUBLIC;

View File

@ -0,0 +1,21 @@
-- SEQUENCE: public."Seq1_$%{}[]()&*^!@""'`\/#"
-- DROP SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#";
CREATE SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
CYCLE
INCREMENT 12
START 7
MINVALUE 2
MAXVALUE 9992
CACHE 2;
ALTER SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
OWNER TO postgres;
COMMENT ON SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
IS 'Some comment';
GRANT SELECT ON SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#" TO PUBLIC;
GRANT ALL ON SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#" TO postgres;

View File

@ -0,0 +1,2 @@
REVOKE ALL ON SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#" FROM PUBLIC;
GRANT SELECT ON SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#" TO PUBLIC;

View File

@ -0,0 +1,8 @@
SELECT setval('public."Seq1_$%{}[]()&*^!@""''`\/#"', 7, true);
ALTER SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
INCREMENT 12
MINVALUE 2
MAXVALUE 9992
CACHE 2
CYCLE;

View File

@ -0,0 +1,9 @@
CREATE SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
INCREMENT 5
START 5
MINVALUE 5
MAXVALUE 999
CACHE 1;
ALTER SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
OWNER TO postgres;

View File

@ -1,49 +0,0 @@
{
"scenarios": [
{
"type": "create",
"name": "Create Sequence",
"endpoint": "NODE-sequence.obj",
"sql_endpoint": "NODE-sequence.sql_id",
"data": {
"name": "Seq1_$%{}[]()&*^!@\"'`\\/#",
"seqowner": "postgres",
"schema": "public",
"increment": "5",
"start": "5",
"maximum": "999",
"minimum": "5",
"cache": "1",
"cycled": false,
"relacl": [],
"securities": []
},
"expected_sql_file": "create_sequence.sql"
},{
"type": "alter",
"name": "Alter Sequence comment",
"endpoint": "NODE-sequence.obj_id",
"sql_endpoint": "NODE-sequence.sql_id",
"data": {
"comment": "Some comment"
},
"expected_sql_file": "alter_seq_comment.sql"
},{
"type": "alter",
"name": "Alter Sequence properties",
"endpoint": "NODE-sequence.obj_id",
"sql_endpoint": "NODE-sequence.sql_id",
"data": {
"current_value": "7", "increment": "12", "minimum": "2", "maximum": "9992", "cache": "2", "cycled": true
},
"expected_sql_file": "alter_seq_props.sql"
},{
"type": "delete",
"name": "Drop sequence",
"endpoint": "NODE-sequence.delete_id",
"data": {
"name": "Seq1_$%{}[]()&*^!@\"'`\\/#"
}
}
]
}

View File

@ -0,0 +1,134 @@
{
"scenarios": [
{
"type": "create",
"name": "Create Sequence",
"endpoint": "NODE-sequence.obj",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql",
"data": {
"name": "Seq1_$%{}[]()&*^!@\"'`\\/#",
"seqowner": "postgres",
"schema": "public",
"increment": "5",
"start": "5",
"maximum": "999",
"minimum": "5",
"cache": "1",
"cycled": false,
"relacl": [],
"securities": []
},
"expected_sql_file": "create_sequence.sql",
"expected_msql_file": "create_sequence_msql.sql"
},{
"type": "alter",
"name": "Alter Sequence comment",
"endpoint": "NODE-sequence.obj_id",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql_id",
"data": {
"comment": "Some comment"
},
"expected_sql_file": "alter_seq_comment.sql",
"expected_msql_file": "alter_seq_comment_msql.sql"
},{
"type": "alter",
"name": "Alter Sequence properties",
"endpoint": "NODE-sequence.obj_id",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql_id",
"data": {
"current_value": "7", "increment": "12", "minimum": "2", "maximum": "9992", "cache": "2", "cycled": true
},
"expected_sql_file": "alter_seq_props.sql",
"expected_msql_file": "alter_seq_props_msql.sql"
},{
"type": "alter",
"name": "Alter Sequence add privileges",
"endpoint": "NODE-sequence.obj_id",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql_id",
"data": {
"relacl": {
"added":[{
"grantee": "PUBLIC",
"grantor": "postgres",
"privileges":[{
"privilege_type": "r",
"privilege": true,
"with_grant": false
},{
"privilege_type": "U",
"privilege": true,
"with_grant": false
},{
"privilege_type": "w",
"privilege": true,
"with_grant": false
}]
}]
}
},
"expected_sql_file": "alter_seq_privs_add.sql",
"expected_msql_file": "alter_seq_privs_add_msql.sql"
},{
"type": "alter",
"name": "Alter Sequence update privileges",
"endpoint": "NODE-sequence.obj_id",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql_id",
"data": {
"relacl": {
"changed":[{
"grantee": "PUBLIC",
"grantor": "postgres",
"privileges":[{
"privilege_type": "r",
"privilege": true,
"with_grant": false
}]
}]
}
},
"expected_sql_file": "alter_seq_privs_update.sql",
"expected_msql_file": "alter_seq_privs_update_msql.sql"
},{
"type": "alter",
"name": "Alter Sequence remove privileges",
"endpoint": "NODE-sequence.obj_id",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql_id",
"data": {
"relacl": {
"deleted":[{
"grantee": "PUBLIC",
"grantor": "postgres",
"privileges":[{
"privilege_type": "r",
"privilege": true,
"with_grant": false
},{
"privilege_type": "U",
"privilege": true,
"with_grant": false
},{
"privilege_type": "w",
"privilege": true,
"with_grant": false
}]
}]
}
},
"expected_sql_file": "alter_seq_privs_remove.sql",
"expected_msql_file": "alter_seq_privs_remove_msql.sql"
},{
"type": "delete",
"name": "Drop sequence",
"endpoint": "NODE-sequence.delete_id",
"data": {
"name": "Seq1_$%{}[]()&*^!@\"'`\\/#"
}
}
]
}

View File

@ -10,7 +10,7 @@ CREATE SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
CACHE 1;
ALTER SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
OWNER TO postgres;
OWNER TO enterprisedb;
COMMENT ON SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
IS 'Some comment';

View File

@ -0,0 +1,2 @@
COMMENT ON SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
IS 'Some comment';

View File

@ -0,0 +1,21 @@
-- SEQUENCE: public."Seq1_$%{}[]()&*^!@""'`\/#"
-- DROP SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#";
CREATE SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
CYCLE
INCREMENT 12
START 7
MINVALUE 2
MAXVALUE 9992
CACHE 2;
ALTER SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
OWNER TO enterprisedb;
COMMENT ON SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
IS 'Some comment';
GRANT ALL ON SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#" TO PUBLIC;
GRANT ALL ON SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#" TO enterprisedb;

View File

@ -0,0 +1 @@
GRANT ALL ON SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#" TO PUBLIC;

View File

@ -0,0 +1,19 @@
-- SEQUENCE: public."Seq1_$%{}[]()&*^!@""'`\/#"
-- DROP SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#";
CREATE SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
CYCLE
INCREMENT 12
START 7
MINVALUE 2
MAXVALUE 9992
CACHE 2;
ALTER SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
OWNER TO enterprisedb;
COMMENT ON SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
IS 'Some comment';
GRANT ALL ON SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#" TO enterprisedb;

View File

@ -0,0 +1 @@
REVOKE ALL ON SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#" FROM PUBLIC;

View File

@ -0,0 +1,21 @@
-- SEQUENCE: public."Seq1_$%{}[]()&*^!@""'`\/#"
-- DROP SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#";
CREATE SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
CYCLE
INCREMENT 12
START 7
MINVALUE 2
MAXVALUE 9992
CACHE 2;
ALTER SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
OWNER TO enterprisedb;
COMMENT ON SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
IS 'Some comment';
GRANT SELECT ON SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#" TO PUBLIC;
GRANT ALL ON SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#" TO enterprisedb;

View File

@ -0,0 +1,2 @@
REVOKE ALL ON SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#" FROM PUBLIC;
GRANT SELECT ON SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#" TO PUBLIC;

View File

@ -11,7 +11,7 @@ CREATE SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
CACHE 2;
ALTER SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
OWNER TO postgres;
OWNER TO enterprisedb;
COMMENT ON SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
IS 'Some comment';

View File

@ -0,0 +1,8 @@
SELECT setval('public."Seq1_$%{}[]()&*^!@""''`\/#"', 7, true);
ALTER SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
INCREMENT 12
MINVALUE 2
MAXVALUE 9992
CACHE 2
CYCLE;

View File

@ -10,4 +10,4 @@ CREATE SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
CACHE 1;
ALTER SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
OWNER TO postgres;
OWNER TO enterprisedb;

View File

@ -0,0 +1,9 @@
CREATE SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
INCREMENT 5
START 5
MINVALUE 5
MAXVALUE 999
CACHE 1;
ALTER SEQUENCE public."Seq1_$%{}[]()&*^!@""'`\/#"
OWNER TO enterprisedb;

View File

@ -0,0 +1,134 @@
{
"scenarios": [
{
"type": "create",
"name": "Create Sequence",
"endpoint": "NODE-sequence.obj",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql",
"data": {
"name": "Seq1_$%{}[]()&*^!@\"'`\\/#",
"seqowner": "enterprisedb",
"schema": "public",
"increment": "5",
"start": "5",
"maximum": "999",
"minimum": "5",
"cache": "1",
"cycled": false,
"relacl": [],
"securities": []
},
"expected_sql_file": "create_sequence.sql",
"expected_msql_file": "create_sequence_msql.sql"
},{
"type": "alter",
"name": "Alter Sequence comment",
"endpoint": "NODE-sequence.obj_id",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql_id",
"data": {
"comment": "Some comment"
},
"expected_sql_file": "alter_seq_comment.sql",
"expected_msql_file": "alter_seq_comment_msql.sql"
},{
"type": "alter",
"name": "Alter Sequence properties",
"endpoint": "NODE-sequence.obj_id",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql_id",
"data": {
"current_value": "7", "increment": "12", "minimum": "2", "maximum": "9992", "cache": "2", "cycled": true
},
"expected_sql_file": "alter_seq_props.sql",
"expected_msql_file": "alter_seq_props_msql.sql"
},{
"type": "alter",
"name": "Alter Sequence add privileges",
"endpoint": "NODE-sequence.obj_id",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql_id",
"data": {
"relacl": {
"added":[{
"grantee": "PUBLIC",
"grantor": "enterprisedb",
"privileges":[{
"privilege_type": "r",
"privilege": true,
"with_grant": false
},{
"privilege_type": "U",
"privilege": true,
"with_grant": false
},{
"privilege_type": "w",
"privilege": true,
"with_grant": false
}]
}]
}
},
"expected_sql_file": "alter_seq_privs_add.sql",
"expected_msql_file": "alter_seq_privs_add_msql.sql"
},{
"type": "alter",
"name": "Alter Sequence update privileges",
"endpoint": "NODE-sequence.obj_id",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql_id",
"data": {
"relacl": {
"changed":[{
"grantee": "PUBLIC",
"grantor": "enterprisedb",
"privileges":[{
"privilege_type": "r",
"privilege": true,
"with_grant": false
}]
}]
}
},
"expected_sql_file": "alter_seq_privs_update.sql",
"expected_msql_file": "alter_seq_privs_update_msql.sql"
},{
"type": "alter",
"name": "Alter Sequence remove privileges",
"endpoint": "NODE-sequence.obj_id",
"sql_endpoint": "NODE-sequence.sql_id",
"msql_endpoint": "NODE-sequence.msql_id",
"data": {
"relacl": {
"deleted":[{
"grantee": "PUBLIC",
"grantor": "enterprisedb",
"privileges":[{
"privilege_type": "r",
"privilege": true,
"with_grant": false
},{
"privilege_type": "U",
"privilege": true,
"with_grant": false
},{
"privilege_type": "w",
"privilege": true,
"with_grant": false
}]
}]
}
},
"expected_sql_file": "alter_seq_privs_remove.sql",
"expected_msql_file": "alter_seq_privs_remove_msql.sql"
},{
"type": "delete",
"name": "Drop sequence",
"endpoint": "NODE-sequence.delete_id",
"data": {
"name": "Seq1_$%{}[]()&*^!@\"'`\\/#"
}
}
]
}

View File

@ -210,6 +210,8 @@ class ReverseEngineeredSQLTestCases(BaseTestGenerator):
print_msg = print_msg + "... FAIL"
print(print_msg)
continue
else:
print(scenario['name'] + " (MSQL) ... ok")
if 'type' in scenario and scenario['type'] == 'create':
# Get the url and create the specific node.
@ -329,7 +331,15 @@ class ReverseEngineeredSQLTestCases(BaseTestGenerator):
msql_url = self.get_url(scenario['msql_endpoint'],
object_id)
params = urllib.parse.urlencode(scenario['data'])
# As msql data is passed as URL params, dict, list types data has to
# be converted to string using json.dumps before passing it to
# urlencode
msql_data = {
key: json.dumps(val)
if isinstance(val, dict) or isinstance(val, list) else val
for key, val in scenario['data'].items()}
params = urllib.parse.urlencode(msql_data)
params = params.replace('False', 'false').replace('True', 'true')
url = msql_url + "?%s" % params
response = self.tester.get(url,