2021-04-26 20:07:00 +02:00
|
|
|
#coding:utf-8
|
2022-01-25 22:55:48 +01:00
|
|
|
|
|
|
|
"""
|
|
|
|
ID: issue-5569
|
|
|
|
ISSUE: 5569
|
|
|
|
TITLE: Error messages differ when regular user tries to RESTORE database, depending on his default role and (perhaps) system privilege USE_GBAK_UTILITY
|
|
|
|
DESCRIPTION:
|
|
|
|
JIRA: CORE-5291
|
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
|
|
|
import pytest
|
2021-12-06 19:23:35 +01:00
|
|
|
from pathlib import Path
|
2022-01-25 22:55:48 +01:00
|
|
|
from firebird.qa import *
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-25 22:55:48 +01:00
|
|
|
substitutions = [('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
|
|
|
|
2022-01-25 22:55:48 +01:00
|
|
|
init_script = """
|
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
|
|
|
|
2022-01-25 22:55:48 +01:00
|
|
|
db = db_factory(init=init_script)
|
2021-12-06 19:23:35 +01:00
|
|
|
|
2022-01-25 22:55:48 +01:00
|
|
|
user_1 = user_factory('db', name='tmp$c5291_1', password='123')
|
|
|
|
user_2 = user_factory('db', name='tmp$c5291_2', password='456')
|
|
|
|
test_role = role_factory('db', name='role_for_use_gbak_utility')
|
2021-12-06 19:23:35 +01:00
|
|
|
|
2022-01-25 22:55:48 +01:00
|
|
|
act = python_act('db', substitutions=substitutions)
|
2021-12-14 20:56:34 +01:00
|
|
|
|
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')
|
2022-01-25 22:55:48 +01:00
|
|
|
def test_1(act: 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):
|
2022-01-25 22:55:48 +01:00
|
|
|
with act.db.connect() as con:
|
2021-12-14 20:56:34 +01:00
|
|
|
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()
|
|
|
|
#
|
2022-01-25 22:55:48 +01:00
|
|
|
act.gbak(switches=['-b', act.db.dsn, str(fbk_file)])
|
2021-12-14 20:56:34 +01:00
|
|
|
# User 1
|
2022-01-25 22:55:48 +01:00
|
|
|
act.reset()
|
|
|
|
act.expected_stderr = "We expect errors"
|
|
|
|
act.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.stderr)
|
2021-12-14 20:56:34 +01:00
|
|
|
# User 1
|
2022-01-25 22:55:48 +01:00
|
|
|
act.reset()
|
|
|
|
act.expected_stderr = "We expect errors"
|
|
|
|
act.gbak(switches=['-rep', str(fbk_file), act.get_dsn(fdb_file_2),
|
|
|
|
'-user', user_1.name, '-pas', user_1.password], credentials=False)
|
|
|
|
print(act.stderr)
|
2021-12-14 20:56:34 +01:00
|
|
|
# User 2
|
2022-01-25 22:55:48 +01:00
|
|
|
act.reset()
|
|
|
|
act.expected_stderr = "We expect errors"
|
|
|
|
act.gbak(switches=['-se', f'{act.host}:service_mgr', '-rep', str(fbk_file),
|
|
|
|
str(fdb_file_1), '-user', user_2.name, '-pas', user_2.password],
|
|
|
|
credentials=False)
|
|
|
|
print(act.stderr)
|
2021-12-14 20:56:34 +01:00
|
|
|
# User 2
|
2022-01-25 22:55:48 +01:00
|
|
|
act.reset()
|
|
|
|
act.expected_stderr = "We expect errors"
|
|
|
|
act.gbak(switches=['-rep', str(fbk_file), act.get_dsn(fdb_file_2),
|
|
|
|
'-user', user_2.name, '-pas', user_2.password], credentials=False)
|
|
|
|
print(act.stderr)
|
2021-12-14 20:56:34 +01:00
|
|
|
#
|
2022-01-25 22:55:48 +01:00
|
|
|
act.reset()
|
|
|
|
act.expected_stderr = expected_stderr_1
|
|
|
|
act.stderr = capsys.readouterr().out
|
|
|
|
assert act.clean_stderr == act.clean_expected_stderr
|