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

137 lines
4.8 KiB
Python
Raw Normal View History

2021-04-26 20:07:00 +02:00
#coding:utf-8
#
# id: bugs.core_4648
# title: no permission for CREATE access to DATABASE (for RDB$ADMIN)
2021-11-26 19:20:43 +01:00
# decription:
2021-04-26 20:07:00 +02:00
# tracker_id: CORE-4648
# min_versions: ['3.0']
# versions: 3.0
2021-11-26 19:20:43 +01:00
# qmid:
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
from firebird.qa import db_factory, python_act, Action, user_factory, User, temp_file
from firebird.driver import SrvRestoreFlag
2021-04-26 20:07:00 +02:00
# version: 3.0
# resources: None
substitutions_1 = []
2021-11-26 19:20:43 +01:00
init_script_1 = ""
#init_script_1 = """
#set wng off;
#create or alter user tmp$c4648 password '123' revoke admin role;
#commit;
#revoke all on all from tmp$c4648;
#-- 'create ... grant admin role' or 'grant rdb$admin' are NOT neccessary
#-- for enabling to creating database by non-sysdba user:
#grant create database to user tmp$c4648;
#commit;
#"""
2021-04-26 20:07:00 +02:00
db_1 = db_factory(sql_dialect=3, init=init_script_1)
# test_script_1
#---
# import os
2021-11-26 19:20:43 +01:00
#
2021-04-26 20:07:00 +02:00
# print ('Starting backup...')
# fbk = os.path.join(context['temp_directory'],'tmp4648.fbk')
# fdn = 'localhost:'+os.path.join(context['temp_directory'],'tmp4648.tmp')
# runProgram('gbak',['-b','-user',user_name,'-password',user_password,dsn,fbk])
# print ('Backup finished.')
# print ('Starting restore using NON sysdba user account...')
# runProgram('gbak',['-rep','-user','TMP$C4648','-password','123',fbk,fdn])
# print ('Restore using NON sysdba user account finished.')
# if os.path.isfile(fbk):
# print ('Delete backup file...')
# os.remove(fbk)
# print ('Backup file deleted.')
2021-11-26 19:20:43 +01:00
#
2021-04-26 20:07:00 +02:00
# script = '''
# set list on;
2021-11-26 19:20:43 +01:00
# select
2021-04-26 20:07:00 +02:00
# a.mon$user as "Who am I:"
# ,left(a.mon$remote_protocol,3) as "Used protocol:"
# ,iif(m.mon$database_name containing 'tmp4648.tmp','YES','NO! ' || m.mon$database_name ) as "Connected to restored DB ?"
# ,m.mon$owner as "Owner of DB is:"
2021-11-26 19:20:43 +01:00
# from mon$attachments a, mon$database m
2021-04-26 20:07:00 +02:00
# where a.mon$attachment_id=current_connection;
# commit;
# drop database;
# '''
# print ('Starting ISQL using NON sysdba user account...')
# runProgram('isql',[fdn,'-q','-user','tmp$c4648','-pas','123'],script)
# print ('ISQL using NON sysdba user account finished.')
2021-11-26 19:20:43 +01:00
#
2021-04-26 20:07:00 +02:00
# script='''revoke create database from user tmp$c4648;
# drop user tmp$c4648;
# commit;
# '''
# runProgram('isql',[dsn,'-q','-user',user_name,'-password',user_password],script)
2021-11-26 19:20:43 +01:00
#
2021-04-26 20:07:00 +02:00
#---
2021-11-26 19:20:43 +01:00
act_1 = python_act('db_1', substitutions=substitutions_1)
2021-04-26 20:07:00 +02:00
expected_stdout_1 = """
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
2021-11-26 19:20:43 +01:00
user_1 = user_factory(name='tmp$c4648', password='123')
temp_db_1 = temp_file('tmp4648.fdb')
2021-04-26 20:07:00 +02:00
2021-11-26 19:20:43 +01:00
@pytest.mark.version('>=3.0')
def test_1(act_1: Action, user_1: User, temp_db_1: Path, capsys):
with act_1.db.connect() as con:
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()
with act_1.connect_server() as srv:
srv.database.local_backup(database=str(act_1.db.db_path), backup_stream=backup)
print ('Backup finished.')
backup.seek(0)
with act_1.connect_server(user=user_1.name, password=user_1.password) as srv:
print ('Starting restore using NON sysdba user account...')
srv.database.local_restore(database=str(temp_db_1), backup_stream=backup,
flags=SrvRestoreFlag.REPLACE)
print ('Restore using NON sysdba user account finished.')
#
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;
"""
print ('Starting ISQL using NON sysdba user account...')
act_1.isql(switches=['-q', '-user', 'tmp$c4648', '-pas', '123', f'localhost:{temp_db_1}'],
connect_db=False, input=script)
print(act_1.stdout)
print ('ISQL using NON sysdba user account finished.')
act_1.reset()
act_1.expected_stdout = expected_stdout_1
act_1.stdout = capsys.readouterr().out
assert act_1.clean_stdout == act_1.clean_expected_stdout