1 # Blackbox tests for the "net ads dns async" commands
3 # Copyright (C) Samuel Cabrero <scabrero@samba.org> 2022
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/>.
22 from samba
.tests
import BlackboxTestCase
24 SERVER
= os
.environ
["DC_SERVER"]
25 REALM
= os
.environ
["REALM"]
26 COMMAND
= "bin/net ads"
28 class NetAdsDnsTests(BlackboxTestCase
):
32 nameserver
= os
.environ
["DC_SERVER_IP"]
33 # filename=None will disable reading /etc/resolv.conf. The file might
34 # not exist e.g. on build or CI systems.
35 self
.resolver
= dns
.resolver
.Resolver(filename
=None)
36 self
.resolver
.nameservers
= [nameserver
]
38 def parse_output(self
, output
):
41 for line
in output
.split("\n"):
42 m
= re
.search(r
'^.*IPv4addr = (.*)$', line
)
45 m
= re
.search(r
'^.*IPv6addr = (.*)$', line
)
50 def test_async_dns(self
):
51 host
= "%s.%s" % (SERVER
, REALM
)
54 answers
= self
.resolver
.query(host
, 'A')
56 sync_v4
.append(rdata
.address
)
57 self
.assertGreaterEqual(len(sync_v4
), 1)
60 answers
= self
.resolver
.query(host
, 'AAAA')
62 sync_v6
.append(rdata
.address
)
63 self
.assertGreaterEqual(len(sync_v6
), 1)
67 argv
= "%s dns async %s.%s " % (COMMAND
, SERVER
, REALM
)
69 out
= self
.check_output(argv
)
70 (async_v4
, async_v6
) = self
.parse_output(out
.decode('utf-8'))
71 except samba
.tests
.BlackboxProcessError
as e
:
72 self
.fail("Error calling [%s]: %s" % (argv
, e
))
74 self
.assertGreaterEqual(len(async_v4
), 1)
75 self
.assertGreaterEqual(len(async_v6
), 1)
79 self
.assertStringsEqual(' '.join(sync_v4
), ' '.join(async_v4
))
83 self
.assertStringsEqual(' '.join(sync_v6
), ' '.join(async_v6
))