samba-tool tests: Tests for virtualCryptSHAxxx rounds
[samba.git] / python / samba / tests / samba_tool / timecmd.py
1 # Unix SMB/CIFS implementation.
2 # Copyright (C) Sean Dague <sdague@linux.vnet.ibm.com> 2011
3 #
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.
8 #
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.
13 #
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/>.
16 #
17
18 import os
19 from time import localtime, strptime, mktime
20 from samba.tests.samba_tool.base import SambaToolCmdTest
21
22 class TimeCmdTestCase(SambaToolCmdTest):
23     """Tests for samba-tool time subcommands"""
24
25     def test_timeget(self):
26         """Run time against the server and make sure it looks accurate"""
27         (result, out, err) = self.runcmd("time", os.environ["SERVER"])
28         self.assertCmdSuccess(result, out, err, "Ensuring time ran successfully")
29
30         timefmt = strptime(out, "%a %b %d %H:%M:%S %Y %Z\n")
31         servertime = int(mktime(timefmt))
32         now = int(mktime(localtime()))
33
34         # because there is a race here, allow up to 5 seconds difference in times
35         delta = 5
36         self.assertTrue((servertime > (now - delta) and (servertime < (now + delta)), "Time is now"))
37
38     def test_timefail(self):
39         """Run time against a non-existent server, and make sure it fails"""
40         (result, out, err) = self.runcmd("time", "notaserver")
41         self.assertEquals(result, -1, "check for result code")
42         self.assertNotEqual(err.strip().find("NT_STATUS_OBJECT_NAME_NOT_FOUND"), -1, "ensure right error string")
43         self.assertEquals(out, "", "ensure no output returned")