9c432e3a37ef309d5819edf8042803efddb90166
[samba.git] / python / samba / tests / dcerpc / sam.py
1 # -*- coding: utf-8 -*-
2 #
3 # Unix SMB/CIFS implementation.
4 # Copyright © Jelmer Vernooij <jelmer@samba.org> 2008
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 #
19
20 """Tests for samba.dcerpc.sam."""
21
22 from samba.dcerpc import samr, security
23 from samba.tests import RpcInterfaceTestCase
24
25
26 # FIXME: Pidl should be doing this for us
27 def toArray(handle, array, num_entries):
28     return [(entry.idx, entry.name) for entry in array.entries[:num_entries]]
29
30
31 class SamrTests(RpcInterfaceTestCase):
32
33     def setUp(self):
34         super(SamrTests, self).setUp()
35         self.conn = samr.samr("ncalrpc:", self.get_loadparm())
36
37     def test_connect5(self):
38         (level, info, handle) = self.conn.Connect5(None, 0, 1, samr.ConnectInfo1())
39
40     def test_connect2(self):
41         handle = self.conn.Connect2(None, security.SEC_FLAG_MAXIMUM_ALLOWED)
42         self.assertTrue(handle is not None)
43
44     def test_EnumDomains(self):
45         handle = self.conn.Connect2(None, security.SEC_FLAG_MAXIMUM_ALLOWED)
46         domains = toArray(*self.conn.EnumDomains(handle, 0, 4294967295))
47         self.conn.Close(handle)