1 # Unix SMB/CIFS implementation.
2 # Copyright (C) Andrew Bartlett <abartlet@samba.org> 2018
3 # Written by Joe Guo <joeg@catalyst.net.nz>
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/>.
20 from samba
.tests
.samba_tool
.base
import SambaToolCmdTest
23 class DemoteCmdTestCase(SambaToolCmdTest
):
24 """Test for samba-tool domain demote subcommand"""
27 super(DemoteCmdTestCase
, self
).setUp()
28 self
.creds_string
= "-U{}%{}".format(
29 os
.environ
["DC_USERNAME"], os
.environ
["DC_PASSWORD"])
31 self
.dc_server
= os
.environ
['DC_SERVER']
32 self
.dburl
= "ldap://%s" % os
.environ
["DC_SERVER"]
33 self
.samdb
= self
.getSamDB("-H", self
.dburl
, self
.creds_string
)
35 def test_demote_and_remove_dns(self
):
37 Test domain demote command will also remove dns references
40 server
= os
.environ
['SERVER'] # the server to demote
41 zone
= os
.environ
['REALM'].lower()
43 # make sure zone exist
44 result
, out
, err
= self
.runsubcmd(
45 "dns", "zoneinfo", server
, zone
, self
.creds_string
)
46 self
.assertCmdSuccess(result
, out
, err
)
48 # add a A record for the server to demote
49 result
, out
, err
= self
.runsubcmd(
50 "dns", "add", self
.dc_server
, zone
,
51 server
, "A", "192.168.0.193", self
.creds_string
)
52 self
.assertCmdSuccess(result
, out
, err
)
54 # make sure above A record exist
55 result
, out
, err
= self
.runsubcmd(
56 "dns", "query", self
.dc_server
, zone
,
57 server
, 'A', self
.creds_string
)
58 self
.assertCmdSuccess(result
, out
, err
)
60 # the above A record points to this host
61 dnshostname
= '{}.{}'.format(server
, zone
)
63 # add a SRV record points to above host
64 srv_record
= "{} 65530 65530 65530".format(dnshostname
)
66 "dns", "add", self
.dc_server
, zone
, 'testrecord', "SRV",
67 srv_record
, self
.creds_string
)
69 # make sure above SRV record exist
70 result
, out
, err
= self
.runsubcmd(
71 "dns", "query", self
.dc_server
, zone
,
72 "testrecord", 'SRV', self
.creds_string
)
73 self
.assertCmdSuccess(result
, out
, err
)
75 for type_
in ['CNAME', 'NS', 'PTR']:
78 "dns", "add", self
.dc_server
, zone
,
79 'testrecord', type_
, dnshostname
,
81 self
.assertCmdSuccess(result
, out
, err
)
84 result
, out
, err
= self
.runsubcmd(
85 "dns", "query", self
.dc_server
, zone
,
86 "testrecord", 'SRV', self
.creds_string
)
87 self
.assertCmdSuccess(result
, out
, err
)
90 result
, out
, err
= self
.runsubcmd(
92 "--server", self
.dc_server
,
93 "--configfile", os
.environ
["CONFIGFILE"],
94 "--workgroup", os
.environ
["DOMAIN"],
96 self
.assertCmdSuccess(result
, out
, err
)
98 result
, out
, err
= self
.runsubcmd(
99 "dns", "query", self
.dc_server
, zone
,
100 server
, 'ALL', self
.creds_string
)
101 self
.assertCmdFail(result
)
103 result
, out
, err
= self
.runsubcmd(
104 "dns", "query", self
.dc_server
, zone
,
105 "testrecord", 'ALL', self
.creds_string
)
106 self
.assertCmdFail(result
)