1 # -*- coding: utf-8 -*-
2 # Unix SMB/CIFS implementation. Tests for netbios py module
3 # Copyright (C) Noel Power <noel.power@suse.com> 2018
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
import netbios
23 class NetBiosTests(samba
.tests
.TestCase
):
25 super(NetBiosTests
, self
).setUp()
26 self
.n
= netbios
.Node()
27 self
.ifc
= os
.environ
["SERVER_IP"]
28 self
.dc
= os
.environ
["DC_NETBIOSNAME"]
31 super(NetBiosTests
, self
).tearDown()
33 def test_query_name(self
):
34 (reply_from
, names
, addresses
) = self
.n
.query_name(self
.dc
, self
.ifc
, timeout
=4)
35 assert reply_from
== self
.ifc
36 assert names
[0] == self
.dc
37 assert addresses
[0] == self
.ifc
39 def test_name_status(self
):
40 (reply_from
, name
, name_list
) = self
.n
.name_status(self
.dc
, self
.ifc
, timeout
=4)
41 assert reply_from
== self
.ifc
42 assert name
[0] == self
.dc
43 assert len(name_list
) > 0
45 def test_register_name(self
):
47 (reply_from
, name
, reply_address
, code
) = self
.n
.register_name((self
.dc
, 0x20), address
, self
.ifc
, multi_homed
=False, timeout
=4)
48 assert reply_from
== self
.ifc
49 assert name
[0] == self
.dc
50 assert reply_address
== address
53 def disabled_test_refresh(self
):
54 # can't get the below test to work, disabling
56 res
= self
.n
.refresh_name((self
.dc
, 0x20), address
, self
.ifc
, timeout
=10)
59 class ValidNetbiosNameTests(samba
.tests
.TestCase
):
62 self
.assertTrue(samba
.valid_netbios_name("FOO"))
64 def test_too_long(self
):
65 self
.assertFalse(samba
.valid_netbios_name("FOO" * 10))
67 def test_invalid_characters(self
):
68 self
.assertFalse(samba
.valid_netbios_name("*BLA"))