2021-04-26 20:07:00 +02:00
|
|
|
#coding:utf-8
|
2022-01-23 20:41:55 +01:00
|
|
|
|
|
|
|
"""
|
|
|
|
ID: issue-4543
|
|
|
|
ISSUE: 4543
|
|
|
|
TITLE: Add database owner to mon$database
|
|
|
|
DESCRIPTION:
|
|
|
|
JIRA: CORE-4218
|
2025-01-13 12:26:41 +01:00
|
|
|
NOTES:
|
|
|
|
[13.01.2025] pzotov
|
|
|
|
Added (temporary ?) 'credentials = False' to prevent ISQL from using '-USER ... -PASS ...'.
|
|
|
|
This is needed since 6.0.0.570, otherwise we get (on attempting to create DB):
|
|
|
|
Statement failed, SQLSTATE = 28000
|
|
|
|
Your user name and password are not defined. Ask your database administrator to set up a Firebird login.
|
|
|
|
-Different logins in connect and attach packets - client library error
|
|
|
|
(IMO, this is bug; see https://github.com/FirebirdSQL/firebird/issues/8385)
|
2022-01-23 20:41:55 +01:00
|
|
|
"""
|
2025-01-13 12:26:41 +01:00
|
|
|
import time
|
|
|
|
import locale
|
2021-04-26 20:07:00 +02:00
|
|
|
import pytest
|
2021-11-18 20:15:37 +01:00
|
|
|
from pathlib import Path
|
2022-01-23 20:41:55 +01:00
|
|
|
from firebird.qa import *
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-23 20:41:55 +01:00
|
|
|
db = db_factory()
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2024-05-09 23:44:18 +02:00
|
|
|
tmp_user: User = user_factory('db', name='TMP_U4218', password='123')
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2024-05-09 23:44:18 +02:00
|
|
|
act = python_act('db', substitutions = [('[ \t]+', ' ')])
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-23 20:41:55 +01:00
|
|
|
test_db = temp_file('owner-db.fdb')
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2021-11-18 20:15:37 +01:00
|
|
|
@pytest.mark.version('>=3.0')
|
2024-05-09 23:44:18 +02:00
|
|
|
def test_1(act: Action, tmp_user: User, test_db: Path):
|
2022-01-23 20:41:55 +01:00
|
|
|
with act.db.connect() as con:
|
2021-11-18 20:15:37 +01:00
|
|
|
c = con.cursor()
|
2025-01-13 12:26:41 +01:00
|
|
|
c.execute(f'grant create database to user {tmp_user.name}')
|
2021-11-18 20:15:37 +01:00
|
|
|
con.commit()
|
2024-05-09 23:44:18 +02:00
|
|
|
|
2022-01-23 20:41:55 +01:00
|
|
|
test_script = f"""
|
2025-01-13 12:26:41 +01:00
|
|
|
-- set echo on;
|
2024-05-09 23:44:18 +02:00
|
|
|
create database 'localhost:{test_db}' user {tmp_user.name} password '{tmp_user.password}';
|
|
|
|
set list on;
|
|
|
|
select current_user as who_am_i, mon$owner as who_is_owner from mon$database;
|
|
|
|
commit;
|
2025-01-13 12:26:41 +01:00
|
|
|
connect 'localhost:{test_db}' user {act.db.user} password '{act.db.password}';
|
2024-05-09 23:44:18 +02:00
|
|
|
select current_user as who_am_i, mon$owner as who_is_owner from mon$database;
|
|
|
|
commit;
|
|
|
|
drop database;
|
|
|
|
quit;
|
2022-01-23 20:41:55 +01:00
|
|
|
"""
|
2025-01-13 12:26:41 +01:00
|
|
|
|
2024-05-09 23:44:18 +02:00
|
|
|
expected_stdout = f"""
|
|
|
|
WHO_AM_I {tmp_user.name.upper()}
|
|
|
|
WHO_IS_OWNER {tmp_user.name.upper()}
|
2025-01-13 12:26:41 +01:00
|
|
|
WHO_AM_I {act.db.user}
|
2024-05-09 23:44:18 +02:00
|
|
|
WHO_IS_OWNER {tmp_user.name.upper()}
|
|
|
|
"""
|
|
|
|
|
2022-01-23 20:41:55 +01:00
|
|
|
act.expected_stdout = expected_stdout
|
2025-01-13 12:26:41 +01:00
|
|
|
act.isql(switches=['-q'], input=test_script, connect_db=False, combine_output = True, credentials = False, io_enc = locale.getpreferredencoding())
|
2022-01-23 20:41:55 +01:00
|
|
|
assert act.clean_stdout == act.clean_expected_stdout
|