2021-04-26 20:07:00 +02:00
|
|
|
#coding:utf-8
|
2022-01-24 20:27:02 +01:00
|
|
|
|
|
|
|
"""
|
|
|
|
ID: issue-4962
|
|
|
|
ISSUE: 4962
|
|
|
|
TITLE: no permission for CREATE access to DATABASE (for RDB$ADMIN)
|
|
|
|
DESCRIPTION:
|
|
|
|
JIRA: CORE-4648
|
2022-02-02 15:46:19 +01:00
|
|
|
FBTEST: bugs.core_4648
|
2022-01-24 20:27:02 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
|
|
|
import pytest
|
2021-11-26 19:20:43 +01:00
|
|
|
from io import BytesIO
|
|
|
|
from pathlib import Path
|
2022-01-24 20:27:02 +01:00
|
|
|
from firebird.qa import *
|
2021-11-26 19:20:43 +01:00
|
|
|
from firebird.driver import SrvRestoreFlag
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-24 20:27:02 +01:00
|
|
|
db = db_factory()
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-24 20:27:02 +01:00
|
|
|
act = python_act('db')
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-24 20:27:02 +01:00
|
|
|
expected_stdout = """
|
2021-04-26 20:07:00 +02:00
|
|
|
Starting backup...
|
|
|
|
Backup finished.
|
|
|
|
Starting restore using NON sysdba user account...
|
|
|
|
Restore using NON sysdba user account finished.
|
|
|
|
Starting ISQL using NON sysdba user account...
|
|
|
|
Who am I: TMP$C4648
|
|
|
|
Used protocol: TCP
|
|
|
|
Connected to restored DB ? YES
|
|
|
|
Owner of DB is: TMP$C4648
|
|
|
|
ISQL using NON sysdba user account finished.
|
2021-11-26 19:20:43 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-24 20:27:02 +01:00
|
|
|
tmp_user = user_factory('db', name='tmp$c4648', password='123')
|
|
|
|
temp_db = temp_file('tmp4648.fdb')
|
|
|
|
|
|
|
|
script = """
|
|
|
|
set list on;
|
|
|
|
select
|
|
|
|
a.mon$user as "Who am I:"
|
|
|
|
,left(a.mon$remote_protocol,3) as "Used protocol:"
|
|
|
|
,iif(m.mon$database_name containing 'tmp4648.fdb','YES','NO! ' || m.mon$database_name ) as "Connected to restored DB ?"
|
|
|
|
,m.mon$owner as "Owner of DB is:"
|
|
|
|
from mon$attachments a, mon$database m
|
|
|
|
where a.mon$attachment_id=current_connection;
|
|
|
|
commit;
|
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2021-11-26 19:20:43 +01:00
|
|
|
@pytest.mark.version('>=3.0')
|
2022-01-24 20:27:02 +01:00
|
|
|
def test_1(act: Action, tmp_user: User, temp_db: Path, capsys):
|
|
|
|
with act.db.connect() as con:
|
2021-11-26 19:20:43 +01:00
|
|
|
c = con.cursor()
|
|
|
|
#-- 'create ... grant admin role' or 'grant rdb$admin' are NOT neccessary
|
|
|
|
#-- for enabling to creating database by non-sysdba user:
|
|
|
|
c.execute('grant create database to user tmp$c4648')
|
|
|
|
con.commit()
|
|
|
|
#
|
|
|
|
print ('Starting backup...')
|
|
|
|
backup = BytesIO()
|
2022-01-24 20:27:02 +01:00
|
|
|
with act.connect_server() as srv:
|
|
|
|
srv.database.local_backup(database=act.db.db_path, backup_stream=backup)
|
2021-11-26 19:20:43 +01:00
|
|
|
print ('Backup finished.')
|
|
|
|
backup.seek(0)
|
2022-01-24 20:27:02 +01:00
|
|
|
with act.connect_server(user=tmp_user.name, password=tmp_user.password) as srv:
|
2021-11-26 19:20:43 +01:00
|
|
|
print ('Starting restore using NON sysdba user account...')
|
2022-01-24 20:27:02 +01:00
|
|
|
srv.database.local_restore(database=temp_db, backup_stream=backup,
|
2021-11-26 19:20:43 +01:00
|
|
|
flags=SrvRestoreFlag.REPLACE)
|
|
|
|
print ('Restore using NON sysdba user account finished.')
|
|
|
|
#
|
|
|
|
print ('Starting ISQL using NON sysdba user account...')
|
2022-01-24 20:27:02 +01:00
|
|
|
act.isql(switches=['-q', '-user', 'tmp$c4648', '-pas', '123', act.get_dsn(temp_db)],
|
2021-12-07 13:36:20 +01:00
|
|
|
connect_db=False, input=script, credentials=False)
|
2022-01-24 20:27:02 +01:00
|
|
|
print(act.stdout)
|
2021-11-26 19:20:43 +01:00
|
|
|
print ('ISQL using NON sysdba user account finished.')
|
2022-01-24 20:27:02 +01:00
|
|
|
act.reset()
|
|
|
|
act.expected_stdout = expected_stdout
|
|
|
|
act.stdout = capsys.readouterr().out
|
|
|
|
assert act.clean_stdout == act.clean_expected_stdout
|