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
22 # here we reimplement unix_to_nt_time from lib/util/time.c
25 if t
== (1 << 63) - 1:
34 def unix2dns_timestamp(t
):
37 # because NTTIME is a uint64_t.
39 return nt
// int(3.6e10
)
42 def timestamp2nttime(ts
):
45 raise OverflowError("nt time won't fit this")
49 class DsdbDnsTestCase(TestCase
):
50 def test_unix_to_dns_timestamp(self
):
51 unixtimes
= [1616829393,
58 expected
= unix2dns_timestamp(t
)
59 result
= dsdb_dns
.unix_to_dns_timestamp(t
)
60 self
.assertEqual(result
, expected
)
62 def test_dns_timestamp_to_nt_time(self
):
63 timestamps
= [16168393,
68 int((1 << 63) / 3.6e10
),
69 int((1 << 63) / 3.6e10
) + 1, # overflows
75 expected
= timestamp2nttime(t
)
79 result
= dsdb_dns
.dns_timestamp_to_nt_time(t
)
81 self
.assertTrue(overflows
, f
"timestamp {t} should not overflow")
83 self
.assertFalse(overflows
, f
"timestamp {t} should overflow")
85 self
.assertEqual(result
, expected
)