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_3799_test.py

123 lines
4.0 KiB
Python

#coding:utf-8
#
# id: bugs.core_3799
# title: with caller privileges option do not work with autonomous transaction option
# decription:
# Checked on: 4.0.0.1635: OK, 1.505s; 3.0.5.33180: OK, 1.555s; 2.5.9.27119: OK, 0.308s.
#
# tracker_id: CORE-3799
# min_versions: ['2.5.2']
# versions: 2.5.2
# qmid: None
import pytest
from firebird.qa import db_factory, isql_act, Action
# version: 2.5.2
# resources: None
substitutions_1 = []
init_script_1 = """"""
db_1 = db_factory(sql_dialect=3, init=init_script_1)
test_script_1 = """
set wng off;
-- Drop old account if it remains from prevoius run:
set term ^;
execute block as
begin
begin
execute statement 'drop user tmp$c3799' with autonomous transaction;
when any do begin end
end
end
^
set term ;^
commit;
create user tmp$c3799 password '123';
commit;
revoke all on all from tmp$c3799;
commit;
create or alter procedure sp_test as begin end;
recreate table test(whoami rdb$user, my_trn int default current_transaction, outer_trn int);
commit;
set term ^ ;
create or alter procedure sp_test as
begin
execute statement ('insert into test(whoami, outer_trn) values(:x, :y)')
( x := current_user , y := current_transaction )
with caller privileges
with autonomous transaction;
end
^
set term ;^
commit;
grant insert,select on table test to procedure sp_test;
grant execute on procedure sp_test to user tmp$c3799;
commit;
-------------------------------------------------------------------------------------------------
set term ^;
execute block as
declare v_usr rdb$user = 'tmp$c3799';
declare v_pwd rdb$user = '123';
begin
execute statement 'execute procedure sp_test' as user v_usr password v_pwd;
end
^
set term ^;
commit;
-------------------------------------------------------------------------------------------------
--connect '$(DSN)' user 'tmp$c3799' password '123';
--execute procedure sp_test;
--commit;
-------------------------------------------------------------------------------------------------
set list on;
select whoami as "Who am I ?", sign( my_trn - outer_trn ) "Did I work in AUTONOMOUS Tx ?"
from test;
commit;
-- ||||||||||||||||||||||||||||
-- ###################################||| FB 4.0+, SS and SC |||##############################
-- ||||||||||||||||||||||||||||
-- If we check SS or SC and ExtConnPoolLifeTime > 0 (config parameter FB 4.0+) then current
-- DB (bugs.core_NNNN.fdb) will be 'captured' by firebird.exe process and fbt_run utility
-- will not able to drop this database at the final point of test.
-- Moreover, DB file will be hold until all activity in firebird.exe completed and AFTER this
-- we have to wait for <ExtConnPoolLifeTime> seconds after it (discussion and small test see
-- in the letter to hvlad and dimitr 13.10.2019 11:10).
-- This means that one need to kill all connections to prevent from exception on cleanup phase:
-- SQLCODE: -901 / lock time-out on wait transaction / object <this_test_DB> is in use
-- #############################################################################################
delete from mon$attachments where mon$attachment_id != current_connection;
commit;
drop user tmp$c3799;
commit;
"""
act_1 = isql_act('db_1', test_script_1, substitutions=substitutions_1)
expected_stdout_1 = """
Who am I ? TMP$C3799
Did I work in AUTONOMOUS Tx ? 1
"""
@pytest.mark.version('>=2.5.2')
def test_1(act_1: Action):
act_1.expected_stdout = expected_stdout_1
act_1.execute()
assert act_1.clean_expected_stdout == act_1.clean_stdout