2008-01-13 23:33:35 +03:00
# Unix SMB/CIFS implementation.
# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
2011-09-13 03:10:37 +04:00
#
2008-01-13 23:33:35 +03:00
# 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.
2011-09-13 03:10:37 +04:00
#
2008-01-13 23:33:35 +03:00
# 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.
2011-09-13 03:10:37 +04:00
#
2008-01-13 23:33:35 +03:00
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
2010-12-05 19:00:45 +03:00
""" Tests for samba.dceprc.rpcecho. """
2008-05-22 04:21:25 +04:00
from samba . dcerpc import echo
2008-05-24 21:50:09 +04:00
from samba . ndr import ndr_pack , ndr_unpack
2010-06-19 20:58:18 +04:00
from samba . tests import RpcInterfaceTestCase , TestCase
2008-01-13 23:33:35 +03:00
2008-08-01 23:00:09 +04:00
2008-04-15 01:28:14 +04:00
class RpcEchoTests ( RpcInterfaceTestCase ) :
2009-09-23 21:52:45 +04:00
2008-01-13 23:33:35 +03:00
def setUp ( self ) :
2010-06-19 20:58:18 +04:00
super ( RpcEchoTests , self ) . setUp ( )
2008-04-15 01:28:14 +04:00
self . conn = echo . rpcecho ( " ncalrpc: " , self . get_loadparm ( ) )
2008-01-13 23:33:35 +03:00
2008-05-25 06:23:03 +04:00
def test_two_contexts ( self ) :
2008-05-30 09:09:59 +04:00
self . conn2 = echo . rpcecho ( " ncalrpc: " , self . get_loadparm ( ) , basis_connection = self . conn )
2020-02-07 01:02:38 +03:00
self . assertEqual ( 3 , self . conn2 . AddOne ( 2 ) )
2008-05-25 06:23:03 +04:00
2008-05-25 06:54:38 +04:00
def test_abstract_syntax ( self ) :
2020-02-07 01:02:38 +03:00
self . assertEqual ( ( " 60a15ec5-4de8-11d7-a637-005056a20182 " , 1 ) ,
2008-05-25 06:54:38 +04:00
self . conn . abstract_syntax )
2008-01-13 23:33:35 +03:00
def test_addone ( self ) :
2020-02-07 01:02:38 +03:00
self . assertEqual ( 2 , self . conn . AddOne ( 1 ) )
2008-01-13 23:42:42 +03:00
def test_echodata ( self ) :
2020-02-07 01:02:38 +03:00
self . assertEqual ( [ 1 , 2 , 3 ] , self . conn . EchoData ( [ 1 , 2 , 3 ] ) )
2008-01-13 23:42:42 +03:00
def test_call ( self ) :
2020-02-07 01:02:38 +03:00
self . assertEqual ( u " foobar " , self . conn . TestCall ( u " foobar " ) )
2008-01-13 23:42:42 +03:00
def test_surrounding ( self ) :
2008-01-14 08:05:28 +03:00
surrounding_struct = echo . Surrounding ( )
surrounding_struct . x = 4
2018-07-30 09:19:05 +03:00
surrounding_struct . surrounding = [ 1 , 2 , 3 , 4 ]
2008-01-14 08:05:28 +03:00
y = self . conn . TestSurrounding ( surrounding_struct )
2020-02-07 01:02:38 +03:00
self . assertEqual ( 8 * [ 0 ] , y . surrounding )
2008-05-24 21:50:09 +04:00
2008-05-25 00:13:32 +04:00
def test_manual_request ( self ) :
2020-02-07 01:02:38 +03:00
self . assertEqual ( b " \x01 \x00 \x00 \x00 " , self . conn . request ( 0 , chr ( 0 ) * 4 ) )
2008-05-25 00:13:32 +04:00
def test_server_name ( self ) :
2020-02-07 01:02:38 +03:00
self . assertEqual ( None , self . conn . server_name )
2008-05-24 21:50:09 +04:00
2008-08-01 23:00:09 +04:00
2010-06-19 20:58:18 +04:00
class NdrEchoTests ( TestCase ) :
2009-09-23 21:52:45 +04:00
2008-05-24 21:50:09 +04:00
def test_info1_push ( self ) :
x = echo . info1 ( )
x . v = 42
2020-02-07 01:02:38 +03:00
self . assertEqual ( b " \x2a " , ndr_pack ( x ) )
2008-05-24 21:50:09 +04:00
def test_info1_pull ( self ) :
2018-04-11 07:38:03 +03:00
x = ndr_unpack ( echo . info1 , b " \x42 " )
2020-02-07 01:02:38 +03:00
self . assertEqual ( x . v , 66 )