6
0
mirror of https://github.com/FirebirdSQL/firebird-qa.git synced 2025-01-23 05:53:06 +01:00
firebird-qa/tests/bugs/core_6048_test.py

202 lines
7.2 KiB
Python
Raw Normal View History

2021-04-26 20:07:00 +02:00
#coding:utf-8
#
# id: bugs.core_6048
# title: Provide ability to see current state of DB encryption
2021-12-10 19:50:31 +01:00
# decription:
2021-04-26 20:07:00 +02:00
# Test database that is created by fbtest framework will be encrypted here using IBSurgeon Demo Encryption package
# ( https://ib-aid.com/download-demo-firebird-encryption-plugin/ ; https://ib-aid.com/download/crypt/CryptTest.zip )
# License file plugins\\dbcrypt.conf with unlimited expiration was provided by IBSurgeon to Firebird Foundation (FF).
# This file was preliminary stored in FF Test machine.
# Test assumes that this file and all neccessary libraries already were stored into FB_HOME and %FB_HOME%\\plugins.
2021-12-10 19:50:31 +01:00
#
2021-04-26 20:07:00 +02:00
# Anyone who wants to run this test on his own machine must
2021-12-10 19:50:31 +01:00
# 1) download https://ib-aid.com/download/crypt/CryptTest.zip AND
2021-04-26 20:07:00 +02:00
# 2) PURCHASE LICENSE and get from IBSurgeon file plugins\\dbcrypt.conf with apropriate expiration date and other info.
2021-12-10 19:50:31 +01:00
#
2021-04-26 20:07:00 +02:00
# ################################################ ! ! ! N O T E ! ! ! ##############################################
# FF tests storage (aka "fbt-repo") does not (and will not) contain any license file for IBSurgeon Demo Encryption package!
# #########################################################################################################################
2021-12-10 19:50:31 +01:00
#
2021-04-26 20:07:00 +02:00
# Checked on:
# 4.0.0.1575: OK, 3.024s.
2021-12-10 19:50:31 +01:00
#
2021-04-26 20:07:00 +02:00
# === NOTE-1 ===
2021-12-10 19:50:31 +01:00
# In case of "Crypt plugin DBCRYPT failed to load/607/335544351" check that all
2021-04-26 20:07:00 +02:00
# needed files from IBSurgeon Demo Encryption package exist in %FB_HOME% and %FB_HOME%\\plugins
# %FB_HOME%:
# 283136 fbcrypt.dll
# 2905600 libcrypto-1_1-x64.dll
# 481792 libssl-1_1-x64.dll
2021-12-10 19:50:31 +01:00
#
2021-04-26 20:07:00 +02:00
# %FB_HOME%\\plugins:
# 297984 dbcrypt.dll
# 306176 keyholder.dll
# 108 DbCrypt.conf
# 856 keyholder.conf
2021-12-10 19:50:31 +01:00
#
2021-04-26 20:07:00 +02:00
# === NOTE-2 ===
2021-12-10 19:50:31 +01:00
# Version of DbCrypt.dll of october-2018 must be replaced because it has hard-coded
2021-04-26 20:07:00 +02:00
# date of expiration rather than reading it from DbCrypt.conf !!
2021-12-10 19:50:31 +01:00
#
2021-04-26 20:07:00 +02:00
# === NOTE-3 ===
# firebird.conf must contain following line:
# KeyHolderPlugin = KeyHolder
2021-12-10 19:50:31 +01:00
#
#
2021-04-26 20:07:00 +02:00
# tracker_id: CORE-6048
# min_versions: ['4.0']
# versions: 4.0
# qmid: None
import pytest
2021-12-10 19:50:31 +01:00
from firebird.qa import db_factory, python_act, Action
2021-04-26 20:07:00 +02:00
# version: 4.0
# resources: None
substitutions_1 = [('[ \t]+', ' ')]
init_script_1 = """"""
db_1 = db_factory(sql_dialect=3, init=init_script_1)
# test_script_1
#---
2021-12-10 19:50:31 +01:00
#
2021-04-26 20:07:00 +02:00
# import os
# import time
# import subprocess
2021-12-10 19:50:31 +01:00
#
2021-04-26 20:07:00 +02:00
# os.environ["ISC_USER"] = user_name
# os.environ["ISC_PASSWORD"] = user_password
2021-12-10 19:50:31 +01:00
#
2021-04-26 20:07:00 +02:00
# # 27.02.2021.
# # Name of encryption plugin depends on OS:
# # * for Windows we (currently) use plugin by IBSurgeon, its name is 'dbcrypt';
# # later it can be replaced with built-in plugin 'fbSampleDbCrypt'
# # but currently it is included only in FB 4.x builds (not in FB 3.x).
# # Discussed tih Dimitr, Alex, Vlad, letters since: 08-feb-2021 00:22
# # "Windows-distributive FB 3.x: it is desired to see sub-folder 'examples\\prebuild' with files for encryption, like it is in FB 4.x
# # *** DEFERRED ***
# # * for Linux we use:
# # ** 'DbCrypt_example' for FB 3.x
# # ** 'fbSampleDbCrypt' for FB 4.x+
# #
# PLUGIN_NAME = 'dbcrypt' if os.name == 'nt' else ( '"DbCrypt_example"' if db_conn.engine_version < 4 else '"fbSampleDbCrypt"' )
2021-12-10 19:50:31 +01:00
#
2021-04-26 20:07:00 +02:00
# db_conn.close()
2021-12-10 19:50:31 +01:00
#
2021-04-26 20:07:00 +02:00
# #--------------------------------------------
2021-12-10 19:50:31 +01:00
#
2021-04-26 20:07:00 +02:00
# def flush_and_close( file_handle ):
# # https://docs.python.org/2/library/os.html#os.fsync
2021-12-10 19:50:31 +01:00
# # If you're starting with a Python file object f,
# # first do f.flush(), and
2021-04-26 20:07:00 +02:00
# # then do os.fsync(f.fileno()), to ensure that all internal buffers associated with f are written to disk.
# global os
2021-12-10 19:50:31 +01:00
#
2021-04-26 20:07:00 +02:00
# file_handle.flush()
# if file_handle.mode not in ('r', 'rb') and file_handle.name != os.devnull:
# # otherwise: "OSError: [Errno 9] Bad file descriptor"!
# os.fsync(file_handle.fileno())
# file_handle.close()
2021-12-10 19:50:31 +01:00
#
#
2021-04-26 20:07:00 +02:00
# #--------------------------------------------
2021-12-10 19:50:31 +01:00
#
2021-04-26 20:07:00 +02:00
# 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
2021-12-10 19:50:31 +01:00
#
2021-04-26 20:07:00 +02:00
# if del_name and os.path.isfile( del_name ):
# os.remove( del_name )
2021-12-10 19:50:31 +01:00
#
2021-04-26 20:07:00 +02:00
# #--------------------------------------------
2021-12-10 19:50:31 +01:00
#
#
#
2021-04-26 20:07:00 +02:00
# sql_scrypt='''
# set list on;
# recreate table test(x bigint unique);
# set term ^;
# create or alter procedure sp_delay as
# declare r bigint;
# begin
# r = rand() * 9223372036854775807;
# insert into test(x) values(:r);
# begin
# -- #########################################################
# -- ####################### D E L A Y #####################
# -- #########################################################
# in autonomous transaction do
# insert into test(x) values(:r); -- this will cause delay because of duplicate in index
2021-12-10 19:50:31 +01:00
# when any do
2021-04-26 20:07:00 +02:00
# begin
# -- nop --
# end
# end
# end
# ^
# set term ;^
# commit;
2021-12-10 19:50:31 +01:00
#
2021-04-26 20:07:00 +02:00
# alter database encrypt with %(PLUGIN_NAME)s key Red;
# commit;
# set transaction lock timeout 2; -- THIS LOCK TIMEOUT SERVES ONLY FOR DELAY
# execute procedure sp_delay;
# rollback;
# select mon$crypt_state as "Is database encrypted ?" from mon$database;
# commit;
2021-12-10 19:50:31 +01:00
#
2021-04-26 20:07:00 +02:00
# alter database decrypt;
# commit;
# set transaction lock timeout 2; -- THIS LOCK TIMEOUT SERVES ONLY FOR DELAY
# execute procedure sp_delay;
# rollback;
# select mon$crypt_state as "Is database encrypted ?" from mon$database;
# ''' % locals()
2021-12-10 19:50:31 +01:00
#
2021-04-26 20:07:00 +02:00
# f_sql_cmd = open(os.path.join(context['temp_directory'],'tmp_core_6048.sql'), 'w')
# f_sql_cmd.write(sql_scrypt)
# flush_and_close( f_sql_cmd )
2021-12-10 19:50:31 +01:00
#
2021-04-26 20:07:00 +02:00
# f_sql_log = open( os.path.join(context['temp_directory'],'tmp_core_6048.log'), 'w')
2021-12-10 19:50:31 +01:00
#
2021-04-26 20:07:00 +02:00
# subprocess.call( [ context['isql_path'], dsn, "-n", "-q", "-i", f_sql_cmd.name ],
# stdout = f_sql_log,
# stderr = subprocess.STDOUT
# )
# flush_and_close( f_sql_log )
2021-12-10 19:50:31 +01:00
#
2021-04-26 20:07:00 +02:00
# with open(f_sql_log.name,'r') as f:
# for line in f:
# print(line)
2021-12-10 19:50:31 +01:00
#
2021-04-26 20:07:00 +02:00
# # cleanup:
# ##########
# time.sleep(1)
# cleanup( (f_sql_cmd,f_sql_log) )
2021-12-10 19:50:31 +01:00
#
#
2021-04-26 20:07:00 +02:00
#---
2021-12-10 19:50:31 +01:00
act_1 = python_act('db_1', substitutions=substitutions_1)
2021-04-26 20:07:00 +02:00
expected_stdout_1 = """
Is database encrypted ? 1
Is database encrypted ? 0
2021-12-10 19:50:31 +01:00
"""
2021-04-26 20:07:00 +02:00
@pytest.mark.version('>=4.0')
2021-12-10 19:50:31 +01:00
def test_1(act_1: Action):
pytest.skip("Requires encryption plugin")
2021-04-26 20:07:00 +02:00