mirror of
https://github.com/FirebirdSQL/firebird-qa.git
synced 2025-01-22 13:33:07 +01:00
Added/Updated functional\trigger\database\test_connect_02.py: Checked on: 3.0.8.33535, 4.0.1.2692, 5.0.0.497
This commit is contained in:
parent
9e757e44ba
commit
5e6f7c15cf
@ -4,63 +4,92 @@
|
||||
ID: trigger.database.connect-02
|
||||
TITLE: Error handling in trigger on database connect
|
||||
DESCRIPTION:
|
||||
This test verifies the proper error handling. Uncaught exceptions in trigger roll back
|
||||
the transaction, disconnect the attachment and are returned to the client.
|
||||
This test verifies the proper error handling: uncaught exceptions
|
||||
in trigger ON CONNECT have to roll back changes of transaction,
|
||||
disconnect the attachment and are returned to the client.
|
||||
FBTEST: functional.trigger.database.connect_02
|
||||
NOTES:
|
||||
[26.05.2022] pzotov
|
||||
Re-implemented for work in firebird-qa suite.
|
||||
Checked on: 3.0.8.33535, 4.0.1.2692, 5.0.0.497
|
||||
"""
|
||||
|
||||
import pytest
|
||||
from firebird.qa import *
|
||||
|
||||
init_script = """create table LOG (ID integer, MSG varchar(100));
|
||||
create generator LOGID;
|
||||
create exception CONNECTERROR 'Exception in ON CONNECT trigger';
|
||||
create role TEST;
|
||||
grant TEST to PUBLIC;
|
||||
set term ^;
|
||||
create trigger LOG_BI for LOG active before insert position 0
|
||||
as
|
||||
begin
|
||||
if (new.ID is null) then
|
||||
new.ID = gen_id(LOGID,1);
|
||||
end ^
|
||||
|
||||
create trigger ONCONNECT on connect position 0
|
||||
as
|
||||
begin
|
||||
insert into LOG (MSG) values ('Connect as ' || current_role);
|
||||
if (current_role ='TEST') then
|
||||
exception CONNECTERROR;
|
||||
end ^
|
||||
|
||||
set term ;^
|
||||
|
||||
commit;
|
||||
"""
|
||||
|
||||
db = db_factory(init=init_script)
|
||||
db = db_factory()
|
||||
tmp_worker = user_factory('db', name='tmp_worker', password='123')
|
||||
tmp_hacker = user_factory('db', name='tmp_hacker', password='456')
|
||||
|
||||
act = python_act('db', substitutions=[('line:.*', '')])
|
||||
|
||||
expected_stdout = """Error while connecting to database:
|
||||
- SQLCODE: -836
|
||||
- exception 1
|
||||
- CONNECTERROR
|
||||
- Exception in ON CONNECT trigger
|
||||
- At trigger 'ONCONNECT' line: 5, col: 29
|
||||
-836
|
||||
335544517
|
||||
"""
|
||||
|
||||
@pytest.mark.skip('FIXME: Not IMPLEMENTED')
|
||||
@pytest.mark.version('>=3.0')
|
||||
def test_1(act: Action):
|
||||
pytest.fail("Not IMPLEMENTED")
|
||||
def test_1(act: Action, tmp_worker: User, tmp_hacker: User):
|
||||
|
||||
# Original python code for this test:
|
||||
# -----------------------------------
|
||||
# try:
|
||||
# con = kdb.connect(dsn=dsn.encode(),user=user_name.encode(),password=user_password.encode(),role='TEST')
|
||||
# except Exception,e:
|
||||
# for msg in e: print (msg)
|
||||
# -----------------------------------
|
||||
expected_stdout = f"""
|
||||
Statement failed, SQLSTATE = HY000
|
||||
exception 1
|
||||
-EXC_CONNECT
|
||||
-Exception in ON CONNECT trigger for {tmp_hacker.name}
|
||||
-At trigger 'TRG_CONNECT'
|
||||
|
||||
ID 1
|
||||
AUDIT_WHO {tmp_worker.name}
|
||||
ID 2
|
||||
AUDIT_WHO {tmp_hacker.name}
|
||||
Records affected: 2
|
||||
|
||||
ID 1
|
||||
SESSION_WHO {tmp_worker.name}
|
||||
Records affected: 1
|
||||
"""
|
||||
|
||||
script = f"""
|
||||
create table sessions_in_work(
|
||||
id int generated by default as identity constraint pk_ssn_in_work primary key
|
||||
,session_who varchar(31) default current_user
|
||||
);
|
||||
|
||||
create table sessions_audit(
|
||||
id int generated by default as identity constraint pk_ssn_audit primary key
|
||||
,audit_who varchar(31) default current_user
|
||||
);
|
||||
create exception exc_connect 'Exception in ON CONNECT trigger for @1';
|
||||
|
||||
set term ^;
|
||||
create trigger trg_connect on connect position 0 as
|
||||
begin
|
||||
if ( current_user = '{act.db.user}' ) then
|
||||
exit;
|
||||
|
||||
in autonomous transaction do
|
||||
insert into sessions_audit default values;
|
||||
|
||||
insert into sessions_in_work default values;
|
||||
|
||||
if ( current_user = upper('{tmp_hacker.name}') ) then
|
||||
exception exc_connect using(current_user);
|
||||
end
|
||||
^
|
||||
set term ;^
|
||||
commit;
|
||||
-----------------------------------------------------
|
||||
connect '{act.db.dsn}' user '{tmp_worker.name}' password '{tmp_worker.password}';
|
||||
commit;
|
||||
|
||||
connect '{act.db.dsn}' user '{tmp_hacker.name}' password '{tmp_hacker.password}';
|
||||
commit;
|
||||
-----------------------------------------------------
|
||||
|
||||
-- Connect as DBA for obtaining results:
|
||||
connect '{act.db.dsn}' user '{act.db.user}' password '{act.db.password}';
|
||||
set list on;
|
||||
set count on;
|
||||
select * from sessions_audit;
|
||||
select * from sessions_in_work;
|
||||
"""
|
||||
|
||||
act.expected_stdout = expected_stdout
|
||||
act.isql(switches=['-q'], input = script, combine_output=True)
|
||||
assert act.clean_stdout == act.clean_expected_stdout
|
||||
|
Loading…
Reference in New Issue
Block a user