<reponame>reevespaul/firebird-qa<gh_stars>0
#coding:utf-8
#
# id:           bugs.core_5207
# title:        ISQL -X may generate invalid GRANT USAGE statements for domains
# decription:   
#                  Test uses .fbk which was prepared on FB 2.5 (source .fdb contains single domain).
#                  After .fbk extration we start restore from it and extract metadata to log.
#                  Then we search metadata log for phrase 'GRANT USAGE ON DOMAIN' - it should NOT present there.
#                  Afterall, we try to apply extracted metadata to temp database (that was created auto by fbtest).
#                  If something will be broken we'll get:
#                  ===
#                       APPLY STDERR: Statement failed, SQLSTATE = 42000
#                       APPLY STDERR: Dynamic SQL Error
#                       APPLY STDERR: -SQL error code = -104
#                       APPLY STDERR: -Token unknown - line 1, column 16
#                       APPLY STDERR: -DOMAIN
#                       APPLY STDERR: At line <N> in file <path>/tmp_xmeta_5207.log
#                       WRONG GRANT: GRANT USAGE ON DOMAIN DM_INT TO PUBLIC;
#                  ===
#                  Checked on: LI-T4.0.0.142 - works fine.
#                
# tracker_id:   CORE-5207
# min_versions: ['3.0']
# versions:     3.0
# qmid:         None

import pytest
from firebird.qa import db_factory, isql_act, Action

# version: 3.0
# resources: None

substitutions_1 = []

init_script_1 = """"""

db_1 = db_factory(sql_dialect=3, init=init_script_1)

# test_script_1
#---
# import os
#  import time
#  import zipfile
#  import subprocess
#  import re
#  
#  os.environ["ISC_USER"] = user_name
#  os.environ["ISC_PASSWORD"] = <PASSWORD>
#  
#  tmpbkp = os.path.join( context['temp_directory'], 'core_5207.fbk' )
#  tmpres = os.path.join( context['temp_directory'], 'tmp_core_5207.fdb' )
#  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') and file_handle.name != os.devnull:
#          # 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 )
#  
#  #--------------------------------------------
#  
#  
#  zf = zipfile.ZipFile( os.path.join(context['files_location'],'core_5207.zip') )
#  zf.extractall( context['temp_directory'] )
#  zf.close()
#  
#  # Result: core_5207.fbk is extracted into context['temp_directory']
#  
#  f_restore=open( os.path.join(context['temp_directory'],'tmp_restore_5207.log'), 'w')
#  subprocess.check_call([context['fbsvcmgr_path'],
#                         "localhost:service_mgr",
#                         "action_restore",
#                         "bkp_file", tmpbkp,
#                         "dbname", tmpres,
#                         "res_replace"
#                        ],
#                        stdout=f_restore, stderr=subprocess.STDOUT)
#  flush_and_close( f_restore )
#  
#  # Result: database file 'tmp_core_5207.fdb' should be created after this restoring,
#  # log ('tmp_restore_5207.log') must be EMPTY.
#  
#  f_xmeta_log = open( os.path.join(context['temp_directory'],'tmp_xmeta_5207.log'), 'w')
#  f_xmeta_err = open( os.path.join(context['temp_directory'],'tmp_xmeta_5207.err'), 'w')
#  
#  subprocess.call( [context['isql_path'], "localhost:"+tmpres, "-x"],
#                   stdout = f_xmeta_log,
#                   stderr = f_xmeta_err
#                 )
#  
#  # This file should contain metadata:
#  flush_and_close( f_xmeta_log )
#  
#  # This file should be empty:
#  flush_and_close( f_xmeta_err )
#  
#  f_apply_log = open( os.path.join(context['temp_directory'],'tmp_apply_5207.log'), 'w')
#  f_apply_err = open( os.path.join(context['temp_directory'],'tmp_apply_5207.err'), 'w')
#  
#  subprocess.call( [context['isql_path'], dsn, "-i", f_xmeta_log.name],
#                   stdout = f_apply_log,
#                   stderr = f_apply_err
#                 )
#  
#  # Both of these files should be empty:
#  flush_and_close( f_apply_log )
#  flush_and_close( f_apply_err )
#  
#  # Output STDOUT+STDERR of restoring and STDERR of metadata extraction: they both should be EMPTY:
#  with open( f_restore.name,'r') as f:
#      for line in f:
#          print( "RESTORE LOG: "+line )
#  
#  with open( f_xmeta_err.name,'r') as f:
#      for line in f:
#          print( "EXTRACT ERR: "+line )
#  
#  with open( f_apply_log.name,'r') as f:
#      for line in f:
#          print( "APPLY STDOUT: "+line )
#  
#  with open( f_apply_err.name,'r') as f:
#      for line in f:
#          print( "APPLY STDERR: "+line )
#  
#  # Check that STDOUT of metadata extration (f_xmeta_log) does __not__ contain 
#  # statement like 'GRANT USAGE ON DOMAIN'.
#  # Output must be empty here:
#  #
#  with open( f_xmeta_log.name,'r') as f:
#      for line in f:
#          if 'GRANT USAGE ON DOMAIN' in line:
#              print( "WRONG GRANT: "+line )
#  
#  
#  # 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_restore,f_xmeta_log,f_xmeta_err,f_apply_log,f_apply_err,tmpbkp,tmpres) )
#    
#---
#act_1 = python_act('db_1', test_script_1, substitutions=substitutions_1)


@pytest.mark.version('>=3.0')
@pytest.mark.xfail
def test_1(db_1):
    pytest.fail("Test not IMPLEMENTED")



#coding:utf-8
#
# id:           bugs.core_5207
# title:        ISQL -X may generate invalid GRANT USAGE statements for domains
# decription:   
#                  Test uses .fbk which was prepared on FB 2.5 (source .fdb contains single domain).
#                  After .fbk extration we start restore from it and extract metadata to log.
#                  Then we search metadata log for phrase 'GRANT USAGE ON DOMAIN' - it should NOT present there.
#                  Afterall, we try to apply extracted metadata to temp database (that was created auto by fbtest).
#                  If something will be broken we'll get:
#                  ===
#                       APPLY STDERR: Statement failed, SQLSTATE = 42000
#                       APPLY STDERR: Dynamic SQL Error
#                       APPLY STDERR: -SQL error code = -104
#                       APPLY STDERR: -Token unknown - line 1, column 16
#                       APPLY STDERR: -DOMAIN
#                       APPLY STDERR: At line <N> in file <path>/tmp_xmeta_5207.log
#                       WRONG GRANT: GRANT USAGE ON DOMAIN DM_INT TO PUBLIC;
#                  ===
#                  Checked on: LI-T4.0.0.142 - works fine.
#                
# tracker_id:   CORE-5207
# min_versions: ['3.0']
# versions:     3.0
# qmid:         None

import pytest
from firebird.qa import db_factory, isql_act, Action

# version: 3.0
# resources: None

substitutions_1 = []

init_script_1 = """"""

db_1 = db_factory(sql_dialect=3, init=init_script_1)

# test_script_1
#---
# import os
#  import time
#  import zipfile
#  import subprocess
#  import re
#  
#  os.environ["ISC_USER"] = user_name
#  os.environ["ISC_PASSWORD"] = <PASSWORD>
#  
#  tmpbkp = os.path.join( context['temp_directory'], 'core_5207.fbk' )
#  tmpres = os.path.join( context['temp_directory'], 'tmp_core_5207.fdb' )
#  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') and file_handle.name != os.devnull:
#          # 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 )
#  
#  #--------------------------------------------
#  
#  
#  zf = zipfile.ZipFile( os.path.join(context['files_location'],'core_5207.zip') )
#  zf.extractall( context['temp_directory'] )
#  zf.close()
#  
#  # Result: core_5207.fbk is extracted into context['temp_directory']
#  
#  f_restore=open( os.path.join(context['temp_directory'],'tmp_restore_5207.log'), 'w')
#  subprocess.check_call([context['fbsvcmgr_path'],
#                         "localhost:service_mgr",
#                         "action_restore",
#                         "bkp_file", tmpbkp,
#                         "dbname", tmpres,
#                         "res_replace"
#                        ],
#                        stdout=f_restore, stderr=subprocess.STDOUT)
#  flush_and_close( f_restore )
#  
#  # Result: database file 'tmp_core_5207.fdb' should be created after this restoring,
#  # log ('tmp_restore_5207.log') must be EMPTY.
#  
#  f_xmeta_log = open( os.path.join(context['temp_directory'],'tmp_xmeta_5207.log'), 'w')
#  f_xmeta_err = open( os.path.join(context['temp_directory'],'tmp_xmeta_5207.err'), 'w')
#  
#  subprocess.call( [context['isql_path'], "localhost:"+tmpres, "-x"],
#                   stdout = f_xmeta_log,
#                   stderr = f_xmeta_err
#                 )
#  
#  # This file should contain metadata:
#  flush_and_close( f_xmeta_log )
#  
#  # This file should be empty:
#  flush_and_close( f_xmeta_err )
#  
#  f_apply_log = open( os.path.join(context['temp_directory'],'tmp_apply_5207.log'), 'w')
#  f_apply_err = open( os.path.join(context['temp_directory'],'tmp_apply_5207.err'), 'w')
#  
#  subprocess.call( [context['isql_path'], dsn, "-i", f_xmeta_log.name],
#                   stdout = f_apply_log,
#                   stderr = f_apply_err
#                 )
#  
#  # Both of these files should be empty:
#  flush_and_close( f_apply_log )
#  flush_and_close( f_apply_err )
#  
#  # Output STDOUT+STDERR of restoring and STDERR of metadata extraction: they both should be EMPTY:
#  with open( f_restore.name,'r') as f:
#      for line in f:
#          print( "RESTORE LOG: "+line )
#  
#  with open( f_xmeta_err.name,'r') as f:
#      for line in f:
#          print( "EXTRACT ERR: "+line )
#  
#  with open( f_apply_log.name,'r') as f:
#      for line in f:
#          print( "APPLY STDOUT: "+line )
#  
#  with open( f_apply_err.name,'r') as f:
#      for line in f:
#          print( "APPLY STDERR: "+line )
#  
#  # Check that STDOUT of metadata extration (f_xmeta_log) does __not__ contain 
#  # statement like 'GRANT USAGE ON DOMAIN'.
#  # Output must be empty here:
#  #
#  with open( f_xmeta_log.name,'r') as f:
#      for line in f:
#          if 'GRANT USAGE ON DOMAIN' in line:
#              print( "WRONG GRANT: "+line )
#  
#  
#  # 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_restore,f_xmeta_log,f_xmeta_err,f_apply_log,f_apply_err,tmpbkp,tmpres) )
#    
#---
#act_1 = python_act('db_1', test_script_1, substitutions=substitutions_1)


@pytest.mark.version('>=3.0')
@pytest.mark.xfail
def test_1(db_1):
    pytest.fail("Test not IMPLEMENTED")
#coding:utf-8 # # id:           bugs.core_5207 # title:        ISQL -X may generate invalid GRANT USAGE statements for domains # decription: #                  Test uses .fbk which was prepared on FB 2.5 (source .fdb contains single domain). #                  After .fbk extration we start restore from it and extract metadata to log. #                  Then we search metadata log for phrase 'GRANT USAGE ON DOMAIN' - it should NOT present there. #                  Afterall, we try to apply extracted metadata to temp database (that was created auto by fbtest). #                  If something will be broken we'll get: #                  === #                       APPLY STDERR: Statement failed, SQLSTATE = 42000 #                       APPLY STDERR: Dynamic SQL Error #                       APPLY STDERR: -SQL error code = -104 #                       APPLY STDERR: -Token unknown - line 1, column 16 #                       APPLY STDERR: -DOMAIN #                       APPLY STDERR: At line <N> in file <path>/tmp_xmeta_5207.log #                       WRONG GRANT: GRANT USAGE ON DOMAIN DM_INT TO PUBLIC; #                  === #                  Checked on: LI-T4.0.0.142 - works fine. # # tracker_id:   CORE-5207 # min_versions: ['3.0'] # versions:     3.0 # qmid:         None # version: 3.0 # resources: None # test_script_1 #--- # import os #  import time #  import zipfile #  import subprocess #  import re # #  os.environ["ISC_USER"] = user_name #  os.environ["ISC_PASSWORD"] = <PASSWORD> # #  tmpbkp = os.path.join( context['temp_directory'], 'core_5207.fbk' ) #  tmpres = os.path.join( context['temp_directory'], 'tmp_core_5207.fdb' ) #  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') and file_handle.name != os.devnull: #          # 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 ) # #  #-------------------------------------------- # # #  zf = zipfile.ZipFile( os.path.join(context['files_location'],'core_5207.zip') ) #  zf.extractall( context['temp_directory'] ) #  zf.close() # #  # Result: core_5207.fbk is extracted into context['temp_directory'] # #  f_restore=open( os.path.join(context['temp_directory'],'tmp_restore_5207.log'), 'w') #  subprocess.check_call([context['fbsvcmgr_path'], #                         "localhost:service_mgr", #                         "action_restore", #                         "bkp_file", tmpbkp, #                         "dbname", tmpres, #                         "res_replace" #                        ], #                        stdout=f_restore, stderr=subprocess.STDOUT) #  flush_and_close( f_restore ) # #  # Result: database file 'tmp_core_5207.fdb' should be created after this restoring, #  # log ('tmp_restore_5207.log') must be EMPTY. # #  f_xmeta_log = open( os.path.join(context['temp_directory'],'tmp_xmeta_5207.log'), 'w') #  f_xmeta_err = open( os.path.join(context['temp_directory'],'tmp_xmeta_5207.err'), 'w') # #  subprocess.call( [context['isql_path'], "localhost:"+tmpres, "-x"], #                   stdout = f_xmeta_log, #                   stderr = f_xmeta_err #                 ) # #  # This file should contain metadata: #  flush_and_close( f_xmeta_log ) # #  # This file should be empty: #  flush_and_close( f_xmeta_err ) # #  f_apply_log = open( os.path.join(context['temp_directory'],'tmp_apply_5207.log'), 'w') #  f_apply_err = open( os.path.join(context['temp_directory'],'tmp_apply_5207.err'), 'w') # #  subprocess.call( [context['isql_path'], dsn, "-i", f_xmeta_log.name], #                   stdout = f_apply_log, #                   stderr = f_apply_err #                 ) # #  # Both of these files should be empty: #  flush_and_close( f_apply_log ) #  flush_and_close( f_apply_err ) # #  # Output STDOUT+STDERR of restoring and STDERR of metadata extraction: they both should be EMPTY: #  with open( f_restore.name,'r') as f: #      for line in f: #          print( "RESTORE LOG: "+line ) # #  with open( f_xmeta_err.name,'r') as f: #      for line in f: #          print( "EXTRACT ERR: "+line ) # #  with open( f_apply_log.name,'r') as f: #      for line in f: #          print( "APPLY STDOUT: "+line ) # #  with open( f_apply_err.name,'r') as f: #      for line in f: #          print( "APPLY STDERR: "+line ) # #  # Check that STDOUT of metadata extration (f_xmeta_log) does __not__ contain #  # statement like 'GRANT USAGE ON DOMAIN'. #  # Output must be empty here: #  # #  with open( f_xmeta_log.name,'r') as f: #      for line in f: #          if 'GRANT USAGE ON DOMAIN' in line: #              print( "WRONG GRANT: "+line ) # # #  # 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_restore,f_xmeta_log,f_xmeta_err,f_apply_log,f_apply_err,tmpbkp,tmpres) ) # #--- #act_1 = python_act('db_1', test_script_1, substitutions=substitutions_1)