2012-08-15 16:08:45 +04:00
# Unix SMB/CIFS implementation.
# Copyright Volker Lendecke <vl@samba.org> 2012
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
2018-12-13 02:32:17 +03:00
""" Tests for samba.samba3.libsmb. """
2012-08-15 16:08:45 +04:00
2019-01-09 00:15:49 +03:00
from samba . samba3 import libsmb_samba_internal as libsmb
2012-08-15 16:08:45 +04:00
from samba . dcerpc import security
from samba . samba3 import param as s3param
from samba import credentials
2020-06-10 12:26:00 +03:00
from samba . credentials import SMB_ENCRYPTION_REQUIRED
2012-08-15 16:08:45 +04:00
import samba . tests
import threading
import sys
import os
2020-06-10 12:26:00 +03:00
import random
2012-08-15 16:08:45 +04:00
2018-07-30 09:20:39 +03:00
2012-08-15 16:08:45 +04:00
class LibsmbTestCase ( samba . tests . TestCase ) :
class OpenClose ( threading . Thread ) :
def __init__ ( self , conn , filename , num_ops ) :
threading . Thread . __init__ ( self )
self . conn = conn
self . filename = filename
self . num_ops = num_ops
self . exc = False
def run ( self ) :
c = self . conn
try :
for i in range ( self . num_ops ) :
f = c . create ( self . filename , CreateDisposition = 3 ,
DesiredAccess = security . SEC_STD_DELETE )
c . delete_on_close ( f , True )
c . close ( f )
except Exception :
self . exc = sys . exc_info ( )
2020-11-17 18:11:11 +03:00
def prep_creds ( self ) :
2012-08-15 16:08:45 +04:00
lp = s3param . get_context ( )
lp . load ( os . getenv ( " SMB_CONF_PATH " ) )
creds = credentials . Credentials ( )
2016-12-02 12:23:28 +03:00
creds . guess ( lp )
2012-08-15 16:08:45 +04:00
creds . set_username ( os . getenv ( " USERNAME " ) )
creds . set_password ( os . getenv ( " PASSWORD " ) )
2020-11-17 18:11:11 +03:00
return ( lp , creds )
def test_OpenClose ( self ) :
( lp , creds ) = self . prep_creds ( )
2018-12-13 02:32:17 +03:00
c = libsmb . Conn ( os . getenv ( " SERVER_IP " ) , " tmp " ,
lp , creds , multi_threaded = True ,
force_smb1 = True )
2012-08-15 16:08:45 +04:00
mythreads = [ ]
for i in range ( 3 ) :
t = LibsmbTestCase . OpenClose ( c , " test " + str ( i ) , 10 )
mythreads . append ( t )
for t in mythreads :
t . start ( )
for t in mythreads :
t . join ( )
if t . exc :
raise t . exc [ 0 ] ( t . exc [ 1 ] )
2020-06-10 12:26:00 +03:00
def test_SMB3EncryptionRequired ( self ) :
test_dir = ' testing_ %d ' % random . randint ( 0 , 0xFFFF )
2020-11-17 18:11:11 +03:00
( lp , creds ) = self . prep_creds ( )
2020-06-10 12:26:00 +03:00
creds . set_smb_encryption ( SMB_ENCRYPTION_REQUIRED )
c = libsmb . Conn ( os . getenv ( " SERVER_IP " ) , " tmp " ,
lp , creds )
c . mkdir ( test_dir )
c . rmdir ( test_dir )
def test_SMB1EncryptionRequired ( self ) :
test_dir = ' testing_ %d ' % random . randint ( 0 , 0xFFFF )
2020-11-17 18:11:11 +03:00
( lp , creds ) = self . prep_creds ( )
2020-06-10 12:26:00 +03:00
creds . set_smb_encryption ( SMB_ENCRYPTION_REQUIRED )
c = libsmb . Conn ( os . getenv ( " SERVER_IP " ) , " tmp " ,
lp , creds , force_smb1 = True )
c . mkdir ( test_dir )
c . rmdir ( test_dir )
2018-07-30 09:21:29 +03:00
2012-08-15 16:08:45 +04:00
if __name__ == " __main__ " :
import unittest
unittest . main ( )