Skip to content

Commit

Permalink
Added/Updated tests\functional\database\create\test_02.py: Added (tem…
Browse files Browse the repository at this point in the history
…porary ?) 'credentials = False' to prevent ISQL from using '-USER ... -PASS ...'. IMO, this is bug; see FirebirdSQL/firebird#8385
  • Loading branch information
pavel-zotov committed Jan 13, 2025
1 parent f869ab0 commit ef33e8f
Showing 1 changed file with 51 additions and 44 deletions.
95 changes: 51 additions & 44 deletions tests/functional/database/create/test_02.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,60 +5,67 @@
TITLE: Create database: non sysdba user
DESCRIPTION:
FBTEST: functional.database.create.02
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)
"""

import locale
from pathlib import Path
import pytest
from firebird.qa import *

db = db_factory()
act = python_act('db', substitutions = [('[ \t]+', ' ')])

test_script = """
set wng off;
set bail on;
create or alter user ozzy password 'osb' revoke admin role;
commit;
revoke all on all from ozzy;
commit;
tmp_user = user_factory('db', name='tmp$boss', password='123')
test_db = temp_file('tmp4test.fdb')

-- ::: NB ::: do NOT miss specification of 'USER' or 'ROLE' clause in
-- GRANT | REVOKE CREATE DATABASE, between `to` and login! Otherwise:
-- Statement failed, SQLSTATE = 0A000
-- unsuccessful metadata update
-- -GRANT failed
-- -feature is not supported
-- -Only grants to USER or ROLE are supported for CREATE DATABASE
grant create database to USER ozzy;
-- ^^^^
grant drop database to USER ozzy;
-- ^^^^
commit;
create database 'localhost:$(DATABASE_LOCATION)tmp.ozzy$db$987456321.tmp' user 'OZZY' password 'osb';
set list on;
select
a.mon$user "Who am I ?"
,iif( m.mon$database_name containing 'tmp.ozzy$db$987456321.tmp' , 'YES', 'NO! ' || m.mon$database_name) "Am I on just created DB ?"
from mon$database m, mon$attachments a where a.mon$attachment_id = current_connection;
commit;
@pytest.mark.version('>=3.0')
def test_1(act: Action, tmp_user: User, test_db: Path):

drop database;
connect '$(DSN)' user 'SYSDBA' password 'masterkey';
revoke create database from user ozzy;
revoke drop database from user ozzy;
drop user ozzy;
commit;
"""
test_script = f"""
set wng off;
set bail on;
connect '{act.db.dsn}' user {act.db.user} password '{act.db.password}';
revoke all on all from {tmp_user.name};
commit;
act = isql_act('db', test_script)
-- ::: NB ::: do NOT miss specification of 'USER' or 'ROLE' clause in
-- GRANT | REVOKE CREATE DATABASE, between `to` and login! Otherwise:
-- Statement failed, SQLSTATE = 0A000
-- unsuccessful metadata update
-- -GRANT failed
-- -feature is not supported
-- -Only grants to USER or ROLE are supported for CREATE DATABASE
grant create database to USER {tmp_user.name};
-- ^^^^
grant drop database to USER {tmp_user.name};
-- ^^^^
commit;
create database 'localhost:{test_db}' user {tmp_user.name} password '{tmp_user.password}';
expected_stdout = """
Who am I ? OZZY
Am I on just created DB ? YES
"""
set list on;
select
a.mon$user "Who am I ?"
,iif( m.mon$database_name containing '{test_db}' , 'YES', 'NO! ' || m.mon$database_name) "Am I on just created DB ?"
from mon$database m cross join mon$attachments a
where a.mon$attachment_id = current_connection;
commit;
drop database;
set echo on;
-- Done.
"""

@pytest.mark.version('>=3.0')
def test_1(act: Action):
act.expected_stdout = expected_stdout
act.execute()
act.expected_stdout = f"""
Who am I ? {tmp_user.name.upper()}
Am I on just created DB ? YES
-- Done.
"""
act.isql(switches=['-q'], input=test_script, connect_db=False, combine_output = True, credentials = False, io_enc = locale.getpreferredencoding())
assert act.clean_stdout == act.clean_expected_stdout

0 comments on commit ef33e8f

Please sign in to comment.