6
0
mirror of https://github.com/FirebirdSQL/firebird-qa.git synced 2025-01-22 21:43:06 +01:00
firebird-qa/tests/bugs/core_0304_test.py

420 lines
11 KiB
Python
Raw Normal View History

2021-04-26 20:07:00 +02:00
#coding:utf-8
#
# id: bugs.core_0304
# title: ANY user can drop procedures, generators, exceptions.
# decription:
2021-04-26 20:07:00 +02:00
# fb30Cs, build 3.0.4.32924: OK, 4.406s.
# FB30SS, build 3.0.4.32939: OK, 1.563s.
#
2021-04-26 20:07:00 +02:00
# 24.01.2019. Added separate code for running on FB 4.0+.
# UDF usage is deprecated in FB 4+, see: ".../doc/README.incompatibilities.3to4.txt".
# Functions div, frac, dow, sdow, getExactTimestampUTC and isLeapYear got safe replacement
2021-04-26 20:07:00 +02:00
# in UDR library "udf_compat", see it in folder: ../plugins/udr/
# Checked on:
# 4.0.0.1172: OK, 8.140s.
# 4.0.0.1340: OK, 4.797s.
# 4.0.0.1378: OK, 4.032s.
#
# 01.06.2021. Adjusted STDERR caused by fixes
# https://github.com/FirebirdSQL/firebird/pull/6833
# https://github.com/FirebirdSQL/firebird/pull/6825
# ("Correct error message for DROP VIEW")
# Checked on 3.0.8.33470; 4.0.0.2502; 5.0.0.60.
#
#
2021-04-26 20:07:00 +02:00
# tracker_id: CORE-304
# min_versions: ['3.0']
# versions: 3.0, 4.0
# qmid: None
import pytest
2021-12-19 22:25:36 +01:00
from firebird.qa import db_factory, isql_act, Action, user_factory, User
2021-04-26 20:07:00 +02:00
# version: 3.0
# resources: None
substitutions_1 = []
init_script_1 = """"""
db_1 = db_factory(sql_dialect=3, init=init_script_1)
test_script_1 = """
DECLARE EXTERNAL FUNCTION strlen CSTRING(32767) RETURNS INTEGER BY VALUE ENTRY_POINT 'IB_UDF_strlen' MODULE_NAME 'ib_udf';
create domain dm_test int;
create collation name_coll for utf8 from unicode case insensitive;
create sequence g_test;
create exception e_test 'foo';
create or alter procedure sp_test as begin end;
create table test(id int not null, x int);
alter table test add constraint test_pk primary key(id) using index test_pk;
create index test_x on test(x);
create view v_test as select * from test;
create role manager;
commit;
set term ^;
create or alter trigger test_bi for test active
before insert position 0
as
begin
new.id = coalesce(new.id, gen_id(g_test, 1) );
end
^
set term ;^
commit;
connect '$(DSN)' user 'tmp$c0304' password '123';
-- All following statements should FAIL if current user is not SYSDBA:
execute procedure sp_test;
2021-04-26 20:07:00 +02:00
show sequence g_test;
alter domain dm_test set default 123;
alter domain dm_test set not null;
alter domain dm_test drop not null;
alter trigger test_bi inactive;
alter table test add z int;
alter table test drop constraint test_pk;
drop index test_x;
drop view v_test;
drop trigger test_bi;
drop table test;
drop role manager;
drop procedure sp_test;
drop sequence g_test;
drop exception e_test;
drop function strlen;
drop collation name_coll;
rollback;
2021-12-19 22:25:36 +01:00
"""
2021-04-26 20:07:00 +02:00
act_1 = isql_act('db_1', test_script_1, substitutions=substitutions_1)
2021-12-19 22:25:36 +01:00
user_1 = user_factory('db_1', name='tmp$c0304', password='123')
2021-04-26 20:07:00 +02:00
expected_stderr_1 = """
Statement failed, SQLSTATE = 28000
no permission for EXECUTE access to PROCEDURE SP_TEST
Statement failed, SQLSTATE = 28000
no permission for USAGE access to GENERATOR G_TEST
There is no generator G_TEST in this database
Statement failed, SQLSTATE = 28000
unsuccessful metadata update
-ALTER DOMAIN DM_TEST failed
-no permission for ALTER access to DOMAIN DM_TEST
Statement failed, SQLSTATE = 28000
unsuccessful metadata update
-ALTER DOMAIN DM_TEST failed
-no permission for ALTER access to DOMAIN DM_TEST
Statement failed, SQLSTATE = 28000
unsuccessful metadata update
-ALTER DOMAIN DM_TEST failed
-no permission for ALTER access to DOMAIN DM_TEST
Statement failed, SQLSTATE = 28000
unsuccessful metadata update
-ALTER TRIGGER TEST_BI failed
-no permission for ALTER access to TABLE TEST
Statement failed, SQLSTATE = 28000
unsuccessful metadata update
-ALTER TABLE TEST failed
-no permission for ALTER access to TABLE TEST
Statement failed, SQLSTATE = 28000
unsuccessful metadata update
-ALTER TABLE TEST failed
-no permission for ALTER access to TABLE TEST
Statement failed, SQLSTATE = 28000
unsuccessful metadata update
-DROP INDEX TEST_X failed
-no permission for ALTER access to TABLE TEST
Statement failed, SQLSTATE = 28000
unsuccessful metadata update
2021-12-22 20:23:11 +01:00
-DROP VIEW V_TEST failed
2021-04-26 20:07:00 +02:00
-no permission for DROP access to VIEW V_TEST
Statement failed, SQLSTATE = 28000
unsuccessful metadata update
-DROP TRIGGER TEST_BI failed
-no permission for ALTER access to TABLE TEST
Statement failed, SQLSTATE = 28000
unsuccessful metadata update
-DROP TABLE TEST failed
-no permission for DROP access to TABLE TEST
Statement failed, SQLSTATE = 28000
unsuccessful metadata update
-DROP ROLE MANAGER failed
-no permission for DROP access to ROLE MANAGER
Statement failed, SQLSTATE = 28000
unsuccessful metadata update
-DROP PROCEDURE SP_TEST failed
-no permission for DROP access to PROCEDURE SP_TEST
Statement failed, SQLSTATE = 28000
unsuccessful metadata update
-DROP SEQUENCE G_TEST failed
-no permission for DROP access to GENERATOR G_TEST
Statement failed, SQLSTATE = 28000
unsuccessful metadata update
-DROP EXCEPTION E_TEST failed
-no permission for DROP access to EXCEPTION E_TEST
Statement failed, SQLSTATE = 28000
unsuccessful metadata update
-DROP FUNCTION STRLEN failed
-no permission for DROP access to FUNCTION STRLEN
Statement failed, SQLSTATE = 28000
unsuccessful metadata update
-DROP COLLATION NAME_COLL failed
-no permission for DROP access to COLLATION NAME_COLL
2021-12-19 22:25:36 +01:00
"""
2021-04-26 20:07:00 +02:00
@pytest.mark.version('>=3.0,<4.0')
2021-12-19 22:25:36 +01:00
def test_1(act_1: Action, user_1: User):
2021-04-26 20:07:00 +02:00
act_1.expected_stderr = expected_stderr_1
act_1.execute()
2021-12-22 20:23:11 +01:00
assert act_1.clean_stderr == act_1.clean_expected_stderr
2021-04-26 20:07:00 +02:00
# version: 4.0
# resources: None
substitutions_2 = []
init_script_2 = """"""
db_2 = db_factory(sql_dialect=3, init=init_script_2)
2021-12-19 22:25:36 +01:00
user_2 = user_factory('db_2', name='tmp$c0304', password='123')
2021-04-26 20:07:00 +02:00
2021-12-19 22:25:36 +01:00
test_script_2 = """
2021-04-26 20:07:00 +02:00
-- See declaration sample in plugins\\udr\\UdfBackwardCompatibility.sql:
create function UDR40_frac (
val double precision
) returns double precision
external name 'udf_compat!UC_frac'
engine udr;
create domain dm_test int;
create collation name_coll for utf8 from unicode case insensitive;
create sequence g_test;
create exception e_test 'foo';
create or alter procedure sp_test as begin end;
create table test(id int not null, x int);
alter table test add constraint test_pk primary key(id) using index test_pk;
create index test_x on test(x);
create view v_test as select * from test;
create role manager;
commit;
set term ^;
create or alter trigger test_bi for test active
before insert position 0
as
begin
new.id = coalesce(new.id, gen_id(g_test, 1) );
end
^
set term ;^
commit;
connect '$(DSN)' user 'tmp$c0304' password '123';
-- All following statements should FAIL if current user is not SYSDBA:
execute procedure sp_test;
2021-04-26 20:07:00 +02:00
show sequence g_test;
alter domain dm_test set default 123;
alter domain dm_test set not null;
alter domain dm_test drop not null;
alter trigger test_bi inactive;
alter table test add z int;
alter table test drop constraint test_pk;
drop index test_x;
drop view v_test;
drop trigger test_bi;
drop table test;
drop role manager;
drop procedure sp_test;
drop sequence g_test;
drop exception e_test;
drop function UDR40_frac;
drop collation name_coll;
rollback;
2021-12-19 22:25:36 +01:00
"""
2021-04-26 20:07:00 +02:00
act_2 = isql_act('db_2', test_script_2, substitutions=substitutions_2)
expected_stderr_2 = """
Statement failed, SQLSTATE = 28000
no permission for EXECUTE access to PROCEDURE SP_TEST
-Effective user is TMP$C0304
Statement failed, SQLSTATE = 28000
no permission for USAGE access to GENERATOR G_TEST
-Effective user is TMP$C0304
There is no generator G_TEST in this database
Statement failed, SQLSTATE = 28000
unsuccessful metadata update
-ALTER DOMAIN DM_TEST failed
-no permission for ALTER access to DOMAIN DM_TEST
-Effective user is TMP$C0304
Statement failed, SQLSTATE = 28000
unsuccessful metadata update
-ALTER DOMAIN DM_TEST failed
-no permission for ALTER access to DOMAIN DM_TEST
-Effective user is TMP$C0304
Statement failed, SQLSTATE = 28000
unsuccessful metadata update
-ALTER DOMAIN DM_TEST failed
-no permission for ALTER access to DOMAIN DM_TEST
-Effective user is TMP$C0304
Statement failed, SQLSTATE = 28000
unsuccessful metadata update
-ALTER TRIGGER TEST_BI failed
-no permission for ALTER access to TABLE TEST
-Effective user is TMP$C0304
Statement failed, SQLSTATE = 28000
unsuccessful metadata update
-ALTER TABLE TEST failed
-no permission for ALTER access to TABLE TEST
-Effective user is TMP$C0304
Statement failed, SQLSTATE = 28000
unsuccessful metadata update
-ALTER TABLE TEST failed
-no permission for ALTER access to TABLE TEST
-Effective user is TMP$C0304
Statement failed, SQLSTATE = 28000
unsuccessful metadata update
-DROP INDEX TEST_X failed
-no permission for ALTER access to TABLE TEST
-Effective user is TMP$C0304
Statement failed, SQLSTATE = 28000
unsuccessful metadata update
-DROP TABLE V_TEST failed
-no permission for DROP access to VIEW V_TEST
-Effective user is TMP$C0304
Statement failed, SQLSTATE = 28000
unsuccessful metadata update
-DROP TRIGGER TEST_BI failed
-no permission for ALTER access to TABLE TEST
-Effective user is TMP$C0304
Statement failed, SQLSTATE = 28000
unsuccessful metadata update
-DROP TABLE TEST failed
-no permission for DROP access to TABLE TEST
-Effective user is TMP$C0304
Statement failed, SQLSTATE = 28000
unsuccessful metadata update
-DROP ROLE MANAGER failed
-no permission for DROP access to ROLE MANAGER
-Effective user is TMP$C0304
Statement failed, SQLSTATE = 28000
unsuccessful metadata update
-DROP PROCEDURE SP_TEST failed
-no permission for DROP access to PROCEDURE SP_TEST
-Effective user is TMP$C0304
Statement failed, SQLSTATE = 28000
unsuccessful metadata update
-DROP SEQUENCE G_TEST failed
-no permission for DROP access to GENERATOR G_TEST
-Effective user is TMP$C0304
Statement failed, SQLSTATE = 28000
unsuccessful metadata update
-DROP EXCEPTION E_TEST failed
-no permission for DROP access to EXCEPTION E_TEST
-Effective user is TMP$C0304
Statement failed, SQLSTATE = 28000
unsuccessful metadata update
-DROP FUNCTION UDR40_FRAC failed
-no permission for DROP access to FUNCTION UDR40_FRAC
-Effective user is TMP$C0304
Statement failed, SQLSTATE = 28000
unsuccessful metadata update
-DROP COLLATION NAME_COLL failed
-no permission for DROP access to COLLATION NAME_COLL
-Effective user is TMP$C0304
2021-12-19 22:25:36 +01:00
"""
2021-04-26 20:07:00 +02:00
@pytest.mark.version('>=4.0')
2021-12-19 22:25:36 +01:00
def test_2(act_2: Action, user_2: User):
2021-04-26 20:07:00 +02:00
act_2.expected_stderr = expected_stderr_2
act_2.execute()
2021-12-22 20:23:11 +01:00
assert act_2.clean_stderr == act_2.clean_expected_stderr