tests: Add test-case for 'group list --verbose'
[samba.git] / python / samba / tests / net_join.py
1 # Unix SMB/CIFS implementation.
2 #
3 # Copyright (C) Catalyst.Net Ltd. 2017
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 #
18
19 """
20 Confirm that net.join_member works
21 """
22
23 import samba.tests
24 import os
25 from samba.net import Net, LIBNET_JOIN_AUTOMATIC
26 from samba.credentials import DONT_USE_KERBEROS
27 from samba import NTSTATUSError, ntstatus
28 import ctypes
29
30
31 class NetJoinTests(samba.tests.TestCaseInTempDir):
32
33     def setUp(self):
34         super(NetJoinTests, self).setUp()
35         self.domain = os.environ["DOMAIN"]
36         self.server = os.environ["SERVER"]
37         self.lp = self.get_loadparm()
38         self.lp.set("private dir", self.tempdir)
39         self.lp.set("lock dir", self.tempdir)
40         self.lp.set("state directory", self.tempdir)
41
42     def tearDown(self):
43         super(NetJoinTests, self).tearDown()
44
45     def test_net_join(self):
46         netbios_name = "NetJoinTest"
47         machinepass  = "abcdefghij"
48         creds = self.insta_creds(template=self.get_credentials(),
49                                  kerberos_state=DONT_USE_KERBEROS)
50
51         net = Net(creds, self.lp, server=self.server)
52
53         # NOTE WELL: We must not run more than one successful
54         # net.join_member per file (process), as the shared
55         # secrets.ldb handle will be kept between runs.
56         try:
57             (join_password, sid, domain_name) = net.join_member(
58                 self.domain, netbios_name, LIBNET_JOIN_AUTOMATIC,
59                 machinepass=machinepass)
60         except NTSTATUSError as e:
61             code = ctypes.c_uint32(e.args[0]).value
62             if code == ntstatus.NT_STATUS_CONNECTION_DISCONNECTED:
63                 self.fail("Connection failure")
64             raise
65         os.unlink(os.path.join(self.tempdir, "secrets.ldb"))
66         pass