1 # Unix SMB/CIFS implementation. Tests for dsdb_dns module
2 # Copyright © Catalyst IT 2021
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 from samba.tests import TestCase
18 from samba import dsdb_dns
23 # here we reimplement unix_to_nt_time from lib/util/time.c
26 if t == (1 << 63) - 1:
35 def unix2dns_timestamp(t):
38 # because NTTIME is a uint64_t.
40 return nt // int(3.6e10)
43 def timestamp2nttime(ts):
46 raise OverflowError("nt time won't fit this")
50 class DsdbDnsTestCase(TestCase):
51 def test_unix_to_dns_timestamp(self):
52 unixtimes = [1616829393,
59 expected = unix2dns_timestamp(t)
60 result = dsdb_dns.unix_to_dns_timestamp(t)
61 self.assertEqual(result, expected)
63 def test_dns_timestamp_to_nt_time(self):
64 timestamps = [16168393,
69 int((1 << 63) / 3.6e10),
70 int((1 << 63) / 3.6e10) + 1, # overflows
76 expected = timestamp2nttime(t)
80 result = dsdb_dns.dns_timestamp_to_nt_time(t)
82 self.assertTrue(overflows, f"timestamp {t} should not overflow")
84 self.assertFalse(overflows, f"timestamp {t} should overflow")
86 self.assertEqual(result, expected)