mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-01-24 15:26:46 -06:00
Add Reverse Engineered SQL tests for Languages. Fixes #4452
This commit is contained in:
parent
e6c067025c
commit
cdf655f7db
@ -18,6 +18,7 @@ Housekeeping
|
||||
|
||||
| `Issue #4415 <https://redmine.postgresql.org/issues/4415>`_ - Add Reverse Engineered SQL tests for Roles and Resource Groups.
|
||||
| `Issue #4441 <https://redmine.postgresql.org/issues/4441>`_ - Add Reverse Engineered SQL tests for FDWs.
|
||||
| `Issue #4452 <https://redmine.postgresql.org/issues/4452>`_ - Add Reverse Engineered SQL tests for Languages.
|
||||
| `Issue #4453 <https://redmine.postgresql.org/issues/4453>`_ - Add Reverse Engineered SQL tests for Extensions.
|
||||
| `Issue #4454 <https://redmine.postgresql.org/issues/4454>`_ - Add Reverse Engineered SQL tests for FTS Configurations.
|
||||
|
||||
|
@ -722,6 +722,13 @@ class LanguageView(PGChildNodeView):
|
||||
else:
|
||||
old_data[row['deftype']] = [priv]
|
||||
|
||||
# To format privileges
|
||||
if 'lanacl' in old_data:
|
||||
old_data['lanacl'] = parse_priv_to_db(
|
||||
old_data['lanacl'],
|
||||
['U']
|
||||
)
|
||||
|
||||
seclabels = []
|
||||
if 'seclabels' in old_data and old_data['seclabels'] is not None:
|
||||
import re
|
||||
|
@ -17,3 +17,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
|
||||
|
@ -5,7 +5,7 @@
|
||||
-- DROP LANGUAGE {{ conn|qtIdent(data.name) }}
|
||||
|
||||
{# ============= CREATE LANGUAGE Query ============= #}
|
||||
CREATE {% if data.trusted %}TRUSTED{% endif %} PROCEDURAL LANGUAGE {{ conn|qtIdent(data.name) }}
|
||||
CREATE{% if data.trusted %} TRUSTED{% endif %} PROCEDURAL LANGUAGE {{ conn|qtIdent(data.name) }}
|
||||
{% if data.lanproc %}
|
||||
HANDLER {{ conn|qtIdent(data.lanproc) }}
|
||||
{% endif %}
|
||||
@ -14,7 +14,7 @@ CREATE {% if data.trusted %}TRUSTED{% endif %} PROCEDURAL LANGUAGE {{ conn|qtIde
|
||||
{% endif %}
|
||||
{% if data.lanval %}
|
||||
VALIDATOR {{ conn|qtIdent(data.lanval) }}{% endif %};
|
||||
{# ============= ALTER LANGUAGE Query ============= #}
|
||||
{# ============= ALTER LANGUAGE Query ============= #}
|
||||
{% if data.lanowner %}
|
||||
|
||||
ALTER LANGUAGE {{ conn|qtIdent(data.name) }}
|
||||
@ -30,7 +30,7 @@ COMMENT ON LANGUAGE {{ conn|qtIdent(data.name) }}
|
||||
{% if data.lanacl and data.lanacl|length > 0 %}
|
||||
|
||||
{% for priv in data.lanacl %}
|
||||
{{ PRIVILEGE.RESETALL(conn, 'LANGUAGE', priv.grantee, data.name) }}
|
||||
{{ PRIVILEGE.APPLY(conn, 'LANGUAGE', priv.grantee, data.name, priv.without_grant, priv.with_grant) }}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{# ============= PRIVILEGES on LANGUAGE ============= #}
|
||||
@ -39,4 +39,4 @@ COMMENT ON LANGUAGE {{ conn|qtIdent(data.name) }}
|
||||
{% for r in data.seclabels %}
|
||||
{{ SECLABEL.APPLY(conn, 'PROCEDURAL LANGUAGE', data.name, r.provider, r.label) }}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
@ -21,3 +21,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
|
||||
|
@ -5,7 +5,7 @@
|
||||
-- DROP LANGUAGE {{ conn|qtIdent(data.name) }}
|
||||
|
||||
{# ============= CREATE LANGUAGE Query ============= #}
|
||||
CREATE {% if data.trusted %}TRUSTED{% endif %} PROCEDURAL LANGUAGE {{ conn|qtIdent(data.name) }}
|
||||
CREATE{% if data.trusted %} TRUSTED{% endif %} PROCEDURAL LANGUAGE {{ conn|qtIdent(data.name) }}
|
||||
{% if data.lanproc %}
|
||||
HANDLER {{ conn|qtIdent(data.lanproc) }}
|
||||
{% endif %}
|
||||
@ -14,7 +14,7 @@ CREATE {% if data.trusted %}TRUSTED{% endif %} PROCEDURAL LANGUAGE {{ conn|qtIde
|
||||
{% endif %}
|
||||
{% if data.lanval %}
|
||||
VALIDATOR {{ conn|qtIdent(data.lanval) }}{% endif %};
|
||||
{# ============= ALTER LANGUAGE Query ============= #}
|
||||
{# ============= ALTER LANGUAGE Query ============= #}
|
||||
{% if data.lanowner %}
|
||||
|
||||
ALTER LANGUAGE {{ conn|qtIdent(data.name) }}
|
||||
@ -30,7 +30,7 @@ COMMENT ON LANGUAGE {{ conn|qtIdent(data.name) }}
|
||||
{% if data.lanacl and data.lanacl|length > 0 %}
|
||||
|
||||
{% for priv in data.lanacl %}
|
||||
{{ PRIVILEGE.RESETALL(conn, 'LANGUAGE', priv.grantee, data.name) }}
|
||||
{{ PRIVILEGE.APPLY(conn, 'LANGUAGE', priv.grantee, data.name, priv.without_grant, priv.with_grant) }}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{# ============= PRIVILEGES on LANGUAGE ============= #}
|
||||
@ -39,4 +39,4 @@ COMMENT ON LANGUAGE {{ conn|qtIdent(data.name) }}
|
||||
{% for r in data.seclabels %}
|
||||
{{ SECLABEL.APPLY(conn, 'PROCEDURAL LANGUAGE', data.name, r.provider, r.label) }}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
@ -0,0 +1,18 @@
|
||||
-- Language: Lan2_$%{}[]()&*^!@"'`\/#
|
||||
|
||||
-- DROP LANGUAGE "Lan2_$%{}[]()&*^!@""'`\/#"
|
||||
|
||||
CREATE TRUSTED PROCEDURAL LANGUAGE "Lan2_$%{}[]()&*^!@""'`\/#"
|
||||
HANDLER plpgsql_call_handler
|
||||
INLINE plpgsql_inline_handler
|
||||
VALIDATOR plpgsql_validator;
|
||||
|
||||
ALTER LANGUAGE "Lan2_$%{}[]()&*^!@""'`\/#"
|
||||
OWNER TO <OWNER>;
|
||||
|
||||
COMMENT ON LANGUAGE "Lan2_$%{}[]()&*^!@""'`\/#"
|
||||
IS 'This is comment on custom trusted language';
|
||||
|
||||
GRANT USAGE ON LANGUAGE "Lan2_$%{}[]()&*^!@""'`\/#" TO PUBLIC;
|
||||
|
||||
GRANT USAGE ON LANGUAGE "Lan2_$%{}[]()&*^!@""'`\/#" TO postgres WITH GRANT OPTION;
|
@ -0,0 +1,11 @@
|
||||
-- Language: Lan2_$%{}[]()&*^!@"'`\/#
|
||||
|
||||
-- DROP LANGUAGE "Lan2_$%{}[]()&*^!@""'`\/#"
|
||||
|
||||
CREATE TRUSTED PROCEDURAL LANGUAGE "Lan2_$%{}[]()&*^!@""'`\/#"
|
||||
HANDLER plpgsql_call_handler
|
||||
INLINE plpgsql_inline_handler
|
||||
VALIDATOR plpgsql_validator;
|
||||
|
||||
ALTER LANGUAGE "Lan2_$%{}[]()&*^!@""'`\/#"
|
||||
OWNER TO <OWNER>;
|
@ -0,0 +1,11 @@
|
||||
-- Language: Lan1_$%{}[]()&*^!@"'`\/#
|
||||
|
||||
-- DROP LANGUAGE "Lan1_$%{}[]()&*^!@""'`\/#"
|
||||
|
||||
CREATE TRUSTED PROCEDURAL LANGUAGE "Lan1_$%{}[]()&*^!@""'`\/#"
|
||||
HANDLER plpgsql_call_handler
|
||||
INLINE plpgsql_inline_handler
|
||||
VALIDATOR plpgsql_validator;
|
||||
|
||||
ALTER LANGUAGE "Lan1_$%{}[]()&*^!@""'`\/#"
|
||||
OWNER TO <OWNER>;
|
@ -0,0 +1,11 @@
|
||||
-- Language: Lan1_$%{}[]()&*^!@"'`\/#
|
||||
|
||||
-- DROP LANGUAGE "Lan1_$%{}[]()&*^!@""'`\/#"
|
||||
|
||||
CREATE PROCEDURAL LANGUAGE "Lan1_$%{}[]()&*^!@""'`\/#"
|
||||
HANDLER plpgsql_call_handler
|
||||
INLINE plpgsql_inline_handler
|
||||
VALIDATOR plpgsql_validator;
|
||||
|
||||
ALTER LANGUAGE "Lan1_$%{}[]()&*^!@""'`\/#"
|
||||
OWNER TO <OWNER>;
|
@ -0,0 +1,86 @@
|
||||
{
|
||||
"scenarios": [
|
||||
{
|
||||
"type": "create",
|
||||
"name": "Create trusted language",
|
||||
"endpoint": "NODE-language.obj",
|
||||
"sql_endpoint": "NODE-language.sql_id",
|
||||
"data": {
|
||||
"name": "Lan1_$%{}[]()&*^!@\"'`\\/#",
|
||||
"trusted": true,
|
||||
"lanproc": "plpgsql_call_handler",
|
||||
"laninl": "plpgsql_inline_handler",
|
||||
"lanval": "plpgsql_validator",
|
||||
"is_template": false
|
||||
},
|
||||
"expected_sql_file": "create_trusted_language.sql"
|
||||
},
|
||||
{
|
||||
"type": "alter",
|
||||
"name": "Alter trusted language name",
|
||||
"endpoint": "NODE-language.obj_id",
|
||||
"sql_endpoint": "NODE-language.sql_id",
|
||||
"data": {
|
||||
"name": "Lan2_$%{}[]()&*^!@\"'`\\/#"
|
||||
},
|
||||
"expected_sql_file": "alter_trusted_lan_name.sql"
|
||||
},
|
||||
{
|
||||
"type": "alter",
|
||||
"name": "Alter comment and privileges",
|
||||
"endpoint": "NODE-language.obj_id",
|
||||
"sql_endpoint": "NODE-language.sql_id",
|
||||
"data": {
|
||||
"description": "This is comment on custom trusted language",
|
||||
"lanacl": {
|
||||
"added":[{
|
||||
"grantee": "PUBLIC",
|
||||
"grantor": "postgres",
|
||||
"privileges":[
|
||||
{
|
||||
"privilege_type": "U",
|
||||
"privilege": true,
|
||||
"with_grant": false
|
||||
}]
|
||||
},{
|
||||
"grantee": "postgres",
|
||||
"grantor": "postgres",
|
||||
"privileges":[{
|
||||
"privilege_type": "U",
|
||||
"privilege": true,
|
||||
"with_grant": true
|
||||
}]
|
||||
}]
|
||||
}
|
||||
},
|
||||
"expected_sql_file": "alter_comment_privileges.sql"
|
||||
},
|
||||
{
|
||||
"type": "delete",
|
||||
"name": "Drop trusted language",
|
||||
"endpoint": "NODE-language.obj_id",
|
||||
"data": {}
|
||||
},
|
||||
{
|
||||
"type": "create",
|
||||
"name": "Create untrusted language",
|
||||
"endpoint": "NODE-language.obj",
|
||||
"sql_endpoint": "NODE-language.sql_id",
|
||||
"data": {
|
||||
"name": "Lan1_$%{}[]()&*^!@\"'`\\/#",
|
||||
"trusted": false,
|
||||
"lanproc": "plpgsql_call_handler",
|
||||
"laninl": "plpgsql_inline_handler",
|
||||
"lanval": "plpgsql_validator",
|
||||
"is_template": false
|
||||
},
|
||||
"expected_sql_file": "create_untrusted_language.sql"
|
||||
},
|
||||
{
|
||||
"type": "delete",
|
||||
"name": "Drop untrusted language",
|
||||
"endpoint": "NODE-language.obj_id",
|
||||
"data": {}
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
-- Language: Lan2_$%{}[]()&*^!@"'`\/#
|
||||
|
||||
-- DROP LANGUAGE "Lan2_$%{}[]()&*^!@""'`\/#"
|
||||
|
||||
CREATE TRUSTED PROCEDURAL LANGUAGE "Lan2_$%{}[]()&*^!@""'`\/#"
|
||||
HANDLER spl_call_handler
|
||||
INLINE spl_inline_handler
|
||||
VALIDATOR spl_validator;
|
||||
|
||||
ALTER LANGUAGE "Lan2_$%{}[]()&*^!@""'`\/#"
|
||||
OWNER TO <OWNER>;
|
||||
|
||||
COMMENT ON LANGUAGE "Lan2_$%{}[]()&*^!@""'`\/#"
|
||||
IS 'This is comment on custom trusted language';
|
||||
|
||||
GRANT USAGE ON LANGUAGE "Lan2_$%{}[]()&*^!@""'`\/#" TO PUBLIC;
|
||||
|
||||
GRANT USAGE ON LANGUAGE "Lan2_$%{}[]()&*^!@""'`\/#" TO enterprisedb WITH GRANT OPTION;
|
@ -0,0 +1,11 @@
|
||||
-- Language: Lan2_$%{}[]()&*^!@"'`\/#
|
||||
|
||||
-- DROP LANGUAGE "Lan2_$%{}[]()&*^!@""'`\/#"
|
||||
|
||||
CREATE TRUSTED PROCEDURAL LANGUAGE "Lan2_$%{}[]()&*^!@""'`\/#"
|
||||
HANDLER spl_call_handler
|
||||
INLINE spl_inline_handler
|
||||
VALIDATOR spl_validator;
|
||||
|
||||
ALTER LANGUAGE "Lan2_$%{}[]()&*^!@""'`\/#"
|
||||
OWNER TO <OWNER>;
|
@ -0,0 +1,11 @@
|
||||
-- Language: Lan1_$%{}[]()&*^!@"'`\/#
|
||||
|
||||
-- DROP LANGUAGE "Lan1_$%{}[]()&*^!@""'`\/#"
|
||||
|
||||
CREATE TRUSTED PROCEDURAL LANGUAGE "Lan1_$%{}[]()&*^!@""'`\/#"
|
||||
HANDLER spl_call_handler
|
||||
INLINE spl_inline_handler
|
||||
VALIDATOR spl_validator;
|
||||
|
||||
ALTER LANGUAGE "Lan1_$%{}[]()&*^!@""'`\/#"
|
||||
OWNER TO <OWNER>;
|
@ -0,0 +1,11 @@
|
||||
-- Language: Lan1_$%{}[]()&*^!@"'`\/#
|
||||
|
||||
-- DROP LANGUAGE "Lan1_$%{}[]()&*^!@""'`\/#"
|
||||
|
||||
CREATE PROCEDURAL LANGUAGE "Lan1_$%{}[]()&*^!@""'`\/#"
|
||||
HANDLER spl_call_handler
|
||||
INLINE spl_inline_handler
|
||||
VALIDATOR spl_validator;
|
||||
|
||||
ALTER LANGUAGE "Lan1_$%{}[]()&*^!@""'`\/#"
|
||||
OWNER TO <OWNER>;
|
@ -0,0 +1,85 @@
|
||||
{
|
||||
"scenarios": [
|
||||
{
|
||||
"type": "create",
|
||||
"name": "Create trusted language",
|
||||
"endpoint": "NODE-language.obj",
|
||||
"sql_endpoint": "NODE-language.sql_id",
|
||||
"data": {
|
||||
"name": "Lan1_$%{}[]()&*^!@\"'`\\/#",
|
||||
"trusted": true,
|
||||
"lanproc": "spl_call_handler",
|
||||
"laninl": "spl_inline_handler",
|
||||
"lanval": "spl_validator",
|
||||
"is_template": false
|
||||
},
|
||||
"expected_sql_file": "create_trusted_language.sql"
|
||||
},
|
||||
{
|
||||
"type": "alter",
|
||||
"name": "Alter trusted language name",
|
||||
"endpoint": "NODE-language.obj_id",
|
||||
"sql_endpoint": "NODE-language.sql_id",
|
||||
"data": {
|
||||
"name": "Lan2_$%{}[]()&*^!@\"'`\\/#"
|
||||
},
|
||||
"expected_sql_file": "alter_trusted_lan_name.sql"
|
||||
},
|
||||
{
|
||||
"type": "alter",
|
||||
"name": "Alter comment and privileges",
|
||||
"endpoint": "NODE-language.obj_id",
|
||||
"sql_endpoint": "NODE-language.sql_id",
|
||||
"data": {
|
||||
"description": "This is comment on custom trusted language",
|
||||
"lanacl": {
|
||||
"added":[{
|
||||
"grantee": "PUBLIC",
|
||||
"grantor": "enterprisedb",
|
||||
"privileges":[{
|
||||
"privilege_type": "U",
|
||||
"privilege": true,
|
||||
"with_grant": false
|
||||
}]
|
||||
},{
|
||||
"grantee": "enterprisedb",
|
||||
"grantor": "enterprisedb",
|
||||
"privileges":[{
|
||||
"privilege_type": "U",
|
||||
"privilege": true,
|
||||
"with_grant": true
|
||||
}]
|
||||
}]
|
||||
}
|
||||
},
|
||||
"expected_sql_file": "alter_comment_privileges.sql"
|
||||
},
|
||||
{
|
||||
"type": "delete",
|
||||
"name": "Drop trusted language",
|
||||
"endpoint": "NODE-language.obj_id",
|
||||
"data": {}
|
||||
},
|
||||
{
|
||||
"type": "create",
|
||||
"name": "Create untrusted language",
|
||||
"endpoint": "NODE-language.obj",
|
||||
"sql_endpoint": "NODE-language.sql_id",
|
||||
"data": {
|
||||
"name": "Lan1_$%{}[]()&*^!@\"'`\\/#",
|
||||
"trusted": false,
|
||||
"lanproc": "spl_call_handler",
|
||||
"laninl": "spl_inline_handler",
|
||||
"lanval": "spl_validator",
|
||||
"is_template": false
|
||||
},
|
||||
"expected_sql_file": "create_untrusted_language.sql"
|
||||
},
|
||||
{
|
||||
"type": "delete",
|
||||
"name": "Drop untrusted language",
|
||||
"endpoint": "NODE-language.obj_id",
|
||||
"data": {}
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user