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

258 lines
8.6 KiB
Python

#coding:utf-8
"""
ID: issue-5255
ISSUE: 5255
TITLE: Real errors during connect to security database are hidden by Srp user manager. Errors should be logged no matter what AuthServer is used
DESCRIPTION:
Test obtains full path to $fb_home via FBSVCMGR info_get_env.
Then it makes copy of file 'databases.conf' that is in $fb_home directory because
following lines will be added to that 'databases.conf':
===
tmp_alias_4964 = ...
{
SecurityDatabase = $(dir_conf)/firebird.msg
}
===
NB: we intentionally put reference to file that for sure does exist but is INVALID for usage as fdb: 'firebird.msg'
Then we:
1) obtain content of server firebird.log
2) try to make connect to alias 'tmp_alias_4964' and (as expected) get error.
3) wait a little and obtain again content of server firebird.log
Finally we restore original databases.conf and check that:
1) Client error message contains phrase about need to check server firebird.log for details.
2) Difference of firebird.log contains messages that engine could not attach to password database
because it is invalid (we specify 'firebird.msg' as security_db in databases.conf for test database,
and of course this is not valid database)
Client always get message with gdscode = 335545106 and sqlcode=-902.
Error text in firebird.log depends on what plugin is used for authentification:
1) Legacy:
Authentication error
cannot attach to password database
Error in isc_attach_database() API call when working with legacy security database
file <...> is not a valid database
2) Srp:
Authentication error
file C:\\FB\\SS\\FIREBIRD.MSG is not a valid database
Checked for:
FB30SS, build 3.0.4.32972: OK, 3.360s.
FB40SS, build 4.0.0.977: OK, 3.485s.
Refactored 05.01.2020 (firebird.conf now contains Srp as first plugin in UserManager parameter):
JIRA: CORE-4964
"""
import pytest
from firebird.qa import *
substitutions = [('FILE.*FIREBIRD.MSG', 'FILE FIREBIRD.MSG'),
('CLIENT_MSG: 335545106L', 'CLIENT_MSG: 335545106')]
db = db_factory()
act = python_act('db', substitutions=substitutions)
expected_stdout = """
CLIENT_MSG: 'ERROR WHILE CONNECTING TO DATABASE:\\N- SQLCODE: -902\\N- ERROR OCCURRED DURING LOGIN, PLEASE CHECK SERVER FIREBIRD.LOG FOR DETAILS'
CLIENT_MSG: -902
CLIENT_MSG: 335545106L
FIREBIRD.LOG: + AUTHENTICATION ERROR
FIREBIRD.LOG: + FILE FIREBIRD.MSG IS NOT A VALID DATABASE
"""
@pytest.mark.skip('FIXME: databases.conf')
@pytest.mark.version('>=3.0')
def test_1(act: Action):
pytest.fail("Not IMPLEMENTED")
# test_script_1
#---
#
# import os
# import subprocess
# from subprocess import Popen
# import difflib
# import datetime
# import time
# import shutil
# import re
# from fdb import services
#
# os.environ["ISC_USER"] = user_name
# os.environ["ISC_PASSWORD"] = user_password
#
# db_conn.close()
#
# #--------------------------------------------
#
# def flush_and_close(file_handle):
# # https://docs.python.org/2/library/os.html#os.fsync
# # If you're starting with a Python file object f,
# # first do f.flush(), and
# # then do os.fsync(f.fileno()), to ensure that all internal buffers associated with f are written to disk.
# global os
#
# file_handle.flush()
# if file_handle.mode not in ('r', 'rb'):
# # otherwise: "OSError: [Errno 9] Bad file descriptor"!
# os.fsync(file_handle.fileno())
# file_handle.close()
#
# #--------------------------------------------
#
# def cleanup( f_names_list ):
# global os
# for i in range(len( f_names_list )):
# if type(f_names_list[i]) == file:
# del_name = f_names_list[i].name
# elif type(f_names_list[i]) == str:
# del_name = f_names_list[i]
# else:
# print('Unrecognized type of element:', f_names_list[i], ' - can not be treated as file.')
# del_name = None
#
# if del_name and os.path.isfile( del_name ):
# os.remove( del_name )
#
# #--------------------------------------------
#
# def svc_get_fb_log( f_fb_log ):
#
# global subprocess
#
# subprocess.call( [ context['fbsvcmgr_path'],
# "localhost:service_mgr",
# "action_get_fb_log"
# ],
# stdout=f_fb_log, stderr=subprocess.STDOUT
# )
# return
#
# #--------------------------------------------
#
# svc = services.connect(host='localhost')
# fb_home=svc.get_home_directory()
# svc.close()
#
# dts = datetime.datetime.now().strftime("%y%m%d_%H%M%S")
#
# dbconf = os.path.join(fb_home, 'databases.conf')
# fbconf = os.path.join(fb_home, 'firebird.conf')
#
# dbcbak = os.path.join(fb_home, 'databases_'+dts+'.bak')
# fbcbak = os.path.join(fb_home, 'firebird_'+dts+'.bak')
#
# shutil.copy2( dbconf, dbcbak )
# shutil.copy2( fbconf, fbcbak )
#
# tmp_fdb=os.path.join(context['temp_directory'],'tmp_4964.fdb')
#
# f_dbconf=open(dbconf,'a')
# f_dbconf.seek(0, 2)
# f_dbconf.write("\\n\\n# Temporarily added by fbtest, CORE-4964. Should be removed auto:")
# f_dbconf.write("\\n#" + '='*60 )
# f_dbconf.write("\\ntmp_alias_4964_"+dts+" = " + tmp_fdb )
# f_dbconf.write("\\n{\\n SecurityDatabase = $(dir_conf)/firebird.msg\\n}")
# f_dbconf.write("\\n#" + '='*60 )
# f_dbconf.close()
#
# f_fbconf=open(fbconf,'r')
# fbconf_content=f_fbconf.readlines()
# f_fbconf.close()
# for i,s in enumerate( fbconf_content ):
# if s.lower().lstrip().startswith( 'wirecrypt'.lower() ):
# fbconf_content[i] = '# <temply commented> ' + s
#
# fbconf_content.append('\\n# Temporarily added by fbtest, CORE-4964. Should be removed auto:')
# fbconf_content.append("\\n#" + '='*30 )
# fbconf_content.append('\\nWireCrypt = Disabled')
# fbconf_content.append("\\n#" + '='*30 )
#
# f_fbconf=open(fbconf,'w')
# f_fbconf.writelines( fbconf_content )
# flush_and_close( f_fbconf )
#
# f_fblog_before=open( os.path.join(context['temp_directory'],'tmp_4964_fblog_before.txt'), 'w')
# svc_get_fb_log( f_fblog_before )
# flush_and_close( f_fblog_before )
#
# f_connect_log=open( os.path.join(context['temp_directory'],'tmp_connect_4964.log'), 'w')
#
# try:
# # Try to connect to 'firebird.msg' which is obviously not a database file:
# ###################################
# con1=fdb.connect( dsn = 'localhost:tmp_alias_4964_'+dts )
# f_connect_log.write( con1.firebird_version )
# con1.close()
# except Exception,e:
# for x in e:
# f_connect_log.write( repr(x)+'\\n' )
#
# flush_and_close( f_connect_log )
#
# f_fblog_after=open( os.path.join(context['temp_directory'],'tmp_4964_fblog_after.txt'), 'w')
# svc_get_fb_log( f_fblog_after )
# flush_and_close( f_fblog_after )
#
#
# # RESTORE original config:
# ##########################
# shutil.move( dbcbak, dbconf )
# shutil.move( fbcbak, fbconf )
#
# # Compare firebird.log versions BEFORE and AFTER this test:
# ######################
#
# oldfb=open(f_fblog_before.name, 'r')
# newfb=open(f_fblog_after.name, 'r')
#
# difftext = ''.join(difflib.unified_diff(
# oldfb.readlines(),
# newfb.readlines()
# ))
# oldfb.close()
# newfb.close()
#
# f_diff_txt=open( os.path.join(context['temp_directory'],'tmp_4964_diff.txt'), 'w')
# f_diff_txt.write(difftext)
# flush_and_close( f_diff_txt )
#
#
# allowed_patterns = (
# re.compile('cannot\\s+attach\\s+to\\s+password+\\s+database\\.*', re.IGNORECASE)
# ,re.compile('error\\s+in\\s+isc_attach_database\\(\\)\\s+API\\.*', re.IGNORECASE)
# ,re.compile('file\\s+.*\\s+is\\s+not\\s+a\\s+valid\\s+database\\.*', re.IGNORECASE)
# ,re.compile('authentication\\s+error.*', re.IGNORECASE)
# ,re.compile('335545106')
# ,re.compile('-902')
# )
#
# with open( f_connect_log.name,'r') as f:
# for line in f:
# match2some = filter( None, [ p.search(line) for p in allowed_patterns ] )
# if match2some:
# print( 'CLIENT_MSG: ' + line.upper() )
#
# with open( f_diff_txt.name,'r') as f:
# for line in f:
# if line.startswith('+'):
# match2some = filter( None, [ p.search(line) for p in allowed_patterns ] )
# if match2some:
# print( 'FIREBIRD.LOG: ' + (' '.join(line.split()).upper()) )
#
#
#
# # Cleanup:
# ##########
# # do NOT remove this pause otherwise some of logs will not be enable for deletion and test will finish with
# # Exception raised while executing Python test script. exception: WindowsError: 32
# time.sleep(1)
# cleanup( (f_connect_log, f_diff_txt, f_fblog_before, f_fblog_after) )
#
#
#---