build: Change bin/default/python -> bin/python symlink to bin/default/python_modules
[Samba.git] / source4 / scripting / python / samba / tests / credentials.py
blob95ee0fa0deb7b6e6ec87515c6e23953b107281e4
1 # Unix SMB/CIFS implementation.
2 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
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/>.
18 """Tests for the Credentials Python bindings.
20 Note that this just tests the bindings work. It does not intend to test
21 the functionality, that's already done in other tests.
22 """
24 from samba import credentials
25 import samba.tests
27 class CredentialsTests(samba.tests.TestCase):
29 def setUp(self):
30 super(CredentialsTests, self).setUp()
31 self.creds = credentials.Credentials()
33 def test_set_username(self):
34 self.creds.set_username("somebody")
35 self.assertEquals("somebody", self.creds.get_username())
37 def test_set_password(self):
38 self.creds.set_password("S3CreT")
39 self.assertEquals("S3CreT", self.creds.get_password())
41 def test_set_domain(self):
42 self.creds.set_domain("ABMAS")
43 self.assertEquals("ABMAS", self.creds.get_domain())
45 def test_set_realm(self):
46 self.creds.set_realm("myrealm")
47 self.assertEquals("MYREALM", self.creds.get_realm())
49 def test_parse_string_anon(self):
50 self.creds.parse_string("%")
51 self.assertEquals("", self.creds.get_username())
52 self.assertEquals(None, self.creds.get_password())
54 def test_parse_string_user_pw_domain(self):
55 self.creds.parse_string("dom\\someone%secr")
56 self.assertEquals("someone", self.creds.get_username())
57 self.assertEquals("secr", self.creds.get_password())
58 self.assertEquals("DOM", self.creds.get_domain())
60 def test_bind_dn(self):
61 self.assertEquals(None, self.creds.get_bind_dn())
62 self.creds.set_bind_dn("dc=foo,cn=bar")
63 self.assertEquals("dc=foo,cn=bar", self.creds.get_bind_dn())
65 def test_is_anon(self):
66 self.creds.set_username("")
67 self.assertTrue(self.creds.is_anonymous())
68 self.creds.set_username("somebody")
69 self.assertFalse(self.creds.is_anonymous())
70 self.creds.set_anonymous()
71 self.assertTrue(self.creds.is_anonymous())
73 def test_workstation(self):
74 # FIXME: This is uninitialised, it should be None
75 #self.assertEquals(None, self.creds.get_workstation())
76 self.creds.set_workstation("myworksta")
77 self.assertEquals("myworksta", self.creds.get_workstation())
79 def test_get_nt_hash(self):
80 self.creds.set_password("geheim")
81 self.assertEquals('\xc2\xae\x1f\xe6\xe6H\x84cRE>\x81o*\xeb\x93',
82 self.creds.get_nt_hash())
84 def test_guess(self):
85 # Just check the method is there and doesn't raise an exception
86 self.creds.guess()
88 def test_set_cmdline_callbacks(self):
89 self.creds.set_cmdline_callbacks()
91 def test_authentication_requested(self):
92 self.creds.set_username("")
93 self.assertFalse(self.creds.authentication_requested())
94 self.creds.set_username("somebody")
95 self.assertTrue(self.creds.authentication_requested())
97 def test_wrong_password(self):
98 self.assertFalse(self.creds.wrong_password())