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

148 lines
5.6 KiB
Python
Raw Normal View History

2021-04-26 20:07:00 +02:00
#coding:utf-8
#
# id: bugs.core_5291
# title: Error messages differ when regular user tries to RESTORE database, depending on his default role and (perhaps) system privilege USE_GBAK_UTILITY
2021-12-06 19:23:35 +01:00
# decription:
2021-04-26 20:07:00 +02:00
# Works fine on 4.0.0.316.
2021-12-06 19:23:35 +01:00
#
2021-04-26 20:07:00 +02:00
# tracker_id: CORE-5291
# min_versions: ['4.0']
# versions: 4.0
# qmid: None
import pytest
2021-12-06 19:23:35 +01:00
from pathlib import Path
2021-12-14 20:56:34 +01:00
from firebird.qa import db_factory, python_act, Action, user_factory, User, temp_file, \
role_factory, Role
2021-04-26 20:07:00 +02:00
# version: 4.0
# resources: None
2021-12-06 19:23:35 +01:00
substitutions_1 = [('gbak: ERROR:no permission for CREATE access to DATABASE.*',
'gbak: ERROR:no permission for CREATE access to DATABASE'),
('gbak: ERROR: failed to create database.*',
'gbak: ERROR: failed to create database'),
('gbak: ERROR:failed to create database localhost:.*',
'gbak: ERROR:failed to create database localhost')]
2021-04-26 20:07:00 +02:00
init_script_1 = """
2021-12-06 19:23:35 +01:00
-- This is not needed anymore for new test implementation
--
-- set wng off;
-- create or alter user tmp$c5291_1 password '123' revoke admin role;
-- create or alter user tmp$c5291_2 password '456' revoke admin role;
-- commit;
-- revoke all on all from tmp$c5291_1;
-- revoke all on all from tmp$c5291_2;
-- commit;
-- create role role_for_use_gbak_utility set system privileges to USE_GBAK_UTILITY, SELECT_ANY_OBJECT_IN_DATABASE;
-- commit;
-- grant default role_for_use_gbak_utility to user tmp$c5291_2;
-- commit;
"""
2021-04-26 20:07:00 +02:00
db_1 = db_factory(sql_dialect=3, init=init_script_1)
# test_script_1
#---
2021-12-06 19:23:35 +01:00
#
2021-04-26 20:07:00 +02:00
# import os
2021-12-06 19:23:35 +01:00
#
2021-04-26 20:07:00 +02:00
# os.environ["ISC_USER"] = user_name
# os.environ["ISC_PASSWORD"] = user_password
2021-12-06 19:23:35 +01:00
#
2021-04-26 20:07:00 +02:00
# db_conn.close()
# tmpfbk=os.path.join(context['temp_directory'],'tmp_core_5291.fbk')
# tmpres1=os.path.join(context['temp_directory'],'tmp_core_5291_1.tmp')
# tmpres2=os.path.join(context['temp_directory'],'tmp_core_5291_2.tmp')
2021-12-06 19:23:35 +01:00
#
2021-04-26 20:07:00 +02:00
# runProgram('gbak',['-b', dsn, tmpfbk])
2021-12-06 19:23:35 +01:00
#
2021-04-26 20:07:00 +02:00
# runProgram('gbak',['-se', 'localhost:service_mgr', '-rep', tmpfbk, tmpres1, '-user', 'tmp$c5291_1', '-pas', '123'])
# runProgram('gbak',['-rep', tmpfbk, 'localhost:' + tmpres2, '-user', 'tmp$c5291_1', '-pas', '123'])
2021-12-06 19:23:35 +01:00
#
2021-04-26 20:07:00 +02:00
# runProgram('gbak',['-se', 'localhost:service_mgr', '-rep', tmpfbk, tmpres1, '-user', 'tmp$c5291_2', '-pas', '456'])
# runProgram('gbak',['-rep', tmpfbk, 'localhost:' + tmpres2, '-user', 'tmp$c5291_2', '-pas', '456'])
2021-12-06 19:23:35 +01:00
#
2021-04-26 20:07:00 +02:00
# runProgram('isql',[dsn],'drop user tmp$c5291_1; drop user tmp$c5291_2;')
2021-12-06 19:23:35 +01:00
#
2021-04-26 20:07:00 +02:00
# f_list=[tmpfbk, tmpres1, tmpres2]
2021-12-06 19:23:35 +01:00
#
2021-04-26 20:07:00 +02:00
# for i in range(len(f_list)):
# if os.path.isfile(f_list[i]):
# os.remove(f_list[i])
2021-12-06 19:23:35 +01:00
#
2021-04-26 20:07:00 +02:00
#---
2021-12-06 19:23:35 +01:00
act_1 = python_act('db_1', substitutions=substitutions_1)
2021-12-14 20:56:34 +01:00
user_1 = user_factory('db_1', name='tmp$c5291_1', password='123')
user_2 = user_factory('db_1', name='tmp$c5291_2', password='456')
test_role = role_factory('db_1', name='role_for_use_gbak_utility')
2021-12-06 19:23:35 +01:00
fbk_file = temp_file('tmp_core_5291.fbk')
fdb_file_1 = temp_file('tmp_core_5291_1.fdb')
fdb_file_2 = temp_file('tmp_core_5291_2.fdb')
2021-04-26 20:07:00 +02:00
expected_stderr_1 = """
gbak: ERROR:no permission for CREATE access to DATABASE
gbak: ERROR: failed to create database
gbak: ERROR: Exiting before completion due to errors
gbak:Exiting before completion due to errors
gbak: ERROR:no permission for CREATE access to DATABASE
gbak: ERROR:failed to create database localhost
gbak:Exiting before completion due to errors
gbak: ERROR:no permission for CREATE access to DATABASE
gbak: ERROR: failed to create database
gbak: ERROR: Exiting before completion due to errors
gbak:Exiting before completion due to errors
gbak: ERROR:no permission for CREATE access to DATABASE
gbak: ERROR:failed to create database localhost
gbak:Exiting before completion due to errors
2021-12-06 19:23:35 +01:00
"""
2021-04-26 20:07:00 +02:00
@pytest.mark.version('>=4.0')
2021-12-06 19:23:35 +01:00
def test_1(act_1: Action, user_1: User, user_2: User, fbk_file: Path, fdb_file_1: Path,
2021-12-14 20:56:34 +01:00
fdb_file_2: Path, test_role: Role, capsys):
with act_1.db.connect() as con:
con.execute_immediate('alter role role_for_use_gbak_utility set system privileges to USE_GBAK_UTILITY, SELECT_ANY_OBJECT_IN_DATABASE')
con.commit()
con.execute_immediate('grant default role_for_use_gbak_utility to user tmp$c5291_2')
con.commit()
#
act_1.gbak(switches=['-b', act_1.db.dsn, str(fbk_file)])
# User 1
act_1.reset()
act_1.expected_stderr = "We expect errors"
act_1.gbak(switches=['-se', 'localhost:service_mgr', '-rep', str(fbk_file),
str(fdb_file_1), '-user', user_1.name, '-pas', user_1.password],
credentials=False)
print(act_1.stderr)
# User 1
act_1.reset()
act_1.expected_stderr = "We expect errors"
act_1.gbak(switches=['-rep', str(fbk_file), act_1.get_dsn(fdb_file_2),
'-user', user_1.name, '-pas', user_1.password], credentials=False)
print(act_1.stderr)
# User 2
act_1.reset()
act_1.expected_stderr = "We expect errors"
act_1.gbak(switches=['-se', f'{act_1.host}:service_mgr', '-rep', str(fbk_file),
str(fdb_file_1), '-user', user_2.name, '-pas', user_2.password],
credentials=False)
print(act_1.stderr)
# User 2
act_1.reset()
act_1.expected_stderr = "We expect errors"
act_1.gbak(switches=['-rep', str(fbk_file), act_1.get_dsn(fdb_file_2),
'-user', user_2.name, '-pas', user_2.password], credentials=False)
print(act_1.stderr)
#
act_1.reset()
act_1.expected_stderr = expected_stderr_1
act_1.stderr = capsys.readouterr().out
assert act_1.clean_stderr == act_1.clean_expected_stderr