3 # Unix SMB/CIFS implementation.
4 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 """Tests for the Credentials Python bindings.
22 Note that this just tests the bindings work. It does not intend to test
23 the functionality, that's already done in other tests.
26 from samba
import credentials
29 class CredentialsTests(samba
.tests
.TestCase
):
32 super(CredentialsTests
, self
).setUp()
33 self
.creds
= credentials
.Credentials()
35 def test_set_username(self
):
36 self
.creds
.set_username("somebody")
37 self
.assertEquals("somebody", self
.creds
.get_username())
39 def test_set_password(self
):
40 self
.creds
.set_password("S3CreT")
41 self
.assertEquals("S3CreT", self
.creds
.get_password())
43 def test_set_domain(self
):
44 self
.creds
.set_domain("ABMAS")
45 self
.assertEquals("ABMAS", self
.creds
.get_domain())
47 def test_set_realm(self
):
48 self
.creds
.set_realm("myrealm")
49 self
.assertEquals("MYREALM", self
.creds
.get_realm())
51 def test_parse_string_anon(self
):
52 self
.creds
.parse_string("%")
53 self
.assertEquals("", self
.creds
.get_username())
54 self
.assertEquals(None, self
.creds
.get_password())
56 def test_parse_string_user_pw_domain(self
):
57 self
.creds
.parse_string("dom\\someone%secr")
58 self
.assertEquals("someone", self
.creds
.get_username())
59 self
.assertEquals("secr", self
.creds
.get_password())
60 self
.assertEquals("DOM", self
.creds
.get_domain())
62 def test_bind_dn(self
):
63 self
.assertEquals(None, self
.creds
.get_bind_dn())
64 self
.creds
.set_bind_dn("dc=foo,cn=bar")
65 self
.assertEquals("dc=foo,cn=bar", self
.creds
.get_bind_dn())
67 def test_is_anon(self
):
68 self
.creds
.set_username("")
69 self
.assertTrue(self
.creds
.is_anonymous())
70 self
.creds
.set_username("somebody")
71 self
.assertFalse(self
.creds
.is_anonymous())
72 self
.creds
.set_anonymous()
73 self
.assertTrue(self
.creds
.is_anonymous())
75 def test_workstation(self
):
76 # FIXME: This is uninitialised, it should be None
77 #self.assertEquals(None, self.creds.get_workstation())
78 self
.creds
.set_workstation("myworksta")
79 self
.assertEquals("myworksta", self
.creds
.get_workstation())
81 def test_get_nt_hash(self
):
82 self
.creds
.set_password("geheim")
83 self
.assertEquals('\xc2\xae\x1f\xe6\xe6H\x84cRE>\x81o*\xeb\x93',
84 self
.creds
.get_nt_hash())
87 # Just check the method is there and doesn't raise an exception
90 def test_set_cmdline_callbacks(self
):
91 self
.creds
.set_cmdline_callbacks()
93 def test_authentication_requested(self
):
94 self
.creds
.set_username("")
95 self
.assertFalse(self
.creds
.authentication_requested())
96 self
.creds
.set_username("somebody")
97 self
.assertTrue(self
.creds
.authentication_requested())
99 def test_wrong_password(self
):
100 self
.assertFalse(self
.creds
.wrong_password())