drsuapi.idl: fix source_dsa spelling
[samba4-gss.git] / python / samba / tests / netlogonsvc.py
bloba509930103a826b9c1c8db5128bc7c4d1ccc3679
1 # Tests to check the netlogon service is only running when it's required
3 # Copyright (C) Catalyst IT Ltd. 2017
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.
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.
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/>.
18 from samba.tests import TestCase
19 import os
21 from samba.credentials import Credentials
22 from samba.dcerpc import netlogon
23 from samba import NTSTATUSError, ntstatus
24 import ctypes
26 """
27 Tests whether the netlogon service is running
28 """
31 class NetlogonServiceTests(TestCase):
33 def setUp(self):
34 super().setUp()
36 self.server = os.environ["SERVER"]
37 self.lp = self.get_loadparm()
38 self.creds = Credentials()
40 # prefer the DC user/password in environments that have it
41 if "DC_USERNAME" in os.environ and "DC_PASSWORD" in os.environ:
42 self.creds.set_username(os.environ["DC_USERNAME"])
43 self.creds.set_password(os.environ["DC_PASSWORD"])
44 else:
45 self.creds.set_username(os.environ["USERNAME"])
46 self.creds.set_password(os.environ["PASSWORD"])
48 self.creds.guess(self.lp)
50 def test_have_netlogon_connection(self):
51 try:
52 c = self.get_netlogon_connection()
53 self.assertIsNotNone(c)
54 except NTSTATUSError as e:
55 # On non-DC test environments, netlogon should not be running on
56 # the server, so we expect the test to fail here
57 enum = ctypes.c_uint32(e.args[0]).value
58 if enum == ntstatus.NT_STATUS_OBJECT_NAME_NOT_FOUND:
59 self.fail("netlogon service is not running")
60 else:
61 raise
63 # Establish netlogon connection over NP
64 def get_netlogon_connection(self):
65 return netlogon.netlogon("ncacn_np:%s[seal]" % self.server, self.lp,
66 self.creds)