2021-04-26 20:07:00 +02:00
|
|
|
#coding:utf-8
|
2022-01-27 20:08:36 +01:00
|
|
|
|
|
|
|
"""
|
|
|
|
ID: issue-2343
|
|
|
|
ISSUE: 2343
|
|
|
|
TITLE: Better diagnostic when 'Missing security context'
|
|
|
|
DESCRIPTION:
|
2022-06-20 11:49:41 +02:00
|
|
|
::: NB :::
|
|
|
|
List of AuthClient plugins must contain Win_Sspi in order to reproduce this test expected results.
|
|
|
|
Otherwise firebird.log will not contain any message like "Available context(s): ..."
|
|
|
|
Because of this, test marked as to be performed on WINDOWS only.
|
2022-01-27 20:08:36 +01:00
|
|
|
JIRA: CORE-6362
|
2022-02-02 15:46:19 +01:00
|
|
|
FBTEST: bugs.core_6362
|
2022-06-20 11:49:41 +02:00
|
|
|
NOTES:
|
|
|
|
[20.06.2022] pzotov
|
2023-12-13 18:16:01 +01:00
|
|
|
See also bugs/gh_7165_test.py
|
|
|
|
Message about missed sec. context will raise if we make undefined ISC_* variables and try to connect.
|
|
|
|
Confirmed missed info in FB 3.0.6.33301: firebird.log remains unchanged (though ISQL issues expected message).
|
|
|
|
Checked on 4.0.1.2692, 3.0.8.33535.
|
|
|
|
|
|
|
|
[13.12.2023] pzotov
|
|
|
|
Added 'SQLSTATE' in substitutions: runtime error must not be filtered out by '?!(...)' pattern
|
|
|
|
("negative lookahead assertion", see https://docs.python.org/3/library/re.html#regular-expression-syntax).
|
|
|
|
Added 'combine_output = True' in order to see SQLSTATE if any error occurs.
|
2022-01-27 20:08:36 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-06-20 11:49:41 +02:00
|
|
|
import os
|
|
|
|
import locale
|
|
|
|
from difflib import unified_diff
|
2021-04-26 20:07:00 +02:00
|
|
|
import pytest
|
2022-01-27 20:08:36 +01:00
|
|
|
from firebird.qa import *
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-06-20 11:49:41 +02:00
|
|
|
for v in ('ISC_USER','ISC_PASSWORD'):
|
|
|
|
try:
|
|
|
|
del os.environ[ v ]
|
|
|
|
except KeyError as e:
|
|
|
|
pass
|
|
|
|
|
2022-01-27 20:08:36 +01:00
|
|
|
db = db_factory()
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2023-12-13 18:16:01 +01:00
|
|
|
substitutions = [ ( '^((?!SQLSTATE|context).)*$', ''),
|
2022-06-20 11:49:41 +02:00
|
|
|
( 'Missing security context(\\(s\\))?( required)? for .*', 'Missing security context'),
|
|
|
|
( 'Available context(\\(s\\))?(:)? .*', 'Available context'),
|
|
|
|
( '[\t ]+', ' '),
|
|
|
|
]
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-06-20 11:49:41 +02:00
|
|
|
act = python_act('db', substitutions = substitutions)
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2023-12-13 18:16:01 +01:00
|
|
|
expected_isql = """
|
|
|
|
Statement failed, SQLSTATE = 28000
|
|
|
|
Missing security context for TEST.FDB
|
|
|
|
"""
|
|
|
|
|
2022-06-20 11:49:41 +02:00
|
|
|
expected_fb_log_diff = """
|
|
|
|
+ Missing security context
|
|
|
|
+ Available context
|
2022-01-27 20:08:36 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
@pytest.mark.version('>=3.0.7')
|
|
|
|
@pytest.mark.platform('Windows')
|
2022-06-20 11:49:41 +02:00
|
|
|
def test_1(act: Action, capsys):
|
|
|
|
with act.connect_server(encoding=locale.getpreferredencoding()) as srv:
|
|
|
|
srv.info.get_log()
|
|
|
|
fb_log_init = srv.readlines()
|
|
|
|
|
2023-12-13 18:16:01 +01:00
|
|
|
act.expected_stdout = expected_isql
|
|
|
|
act.isql(switches=['-q'], input = 'quit;', credentials = False, combine_output = True)
|
|
|
|
assert act.clean_stdout == act.clean_expected_stdout
|
2022-06-20 11:49:41 +02:00
|
|
|
act.reset()
|
|
|
|
|
|
|
|
with act.connect_server(encoding=locale.getpreferredencoding()) as srv:
|
|
|
|
srv.info.get_log()
|
|
|
|
fb_log_curr = srv.readlines()
|
|
|
|
|
|
|
|
|
|
|
|
for line in unified_diff(fb_log_init, fb_log_curr):
|
|
|
|
if line.startswith('+'):
|
|
|
|
print(line.strip())
|
|
|
|
|
|
|
|
act.expected_stdout = expected_fb_log_diff
|
|
|
|
act.stdout = capsys.readouterr().out
|
|
|
|
assert act.clean_stdout == act.clean_expected_stdout
|
|
|
|
act.reset()
|
2021-04-26 20:07:00 +02:00
|
|
|
|