1 | #!/usr/bin/python
|
---|
2 |
|
---|
3 | # Unix SMB/CIFS implementation.
|
---|
4 | # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
|
---|
5 | #
|
---|
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.
|
---|
10 | #
|
---|
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.
|
---|
15 | #
|
---|
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/>.
|
---|
18 | #
|
---|
19 |
|
---|
20 | """Tests for the Credentials Python bindings.
|
---|
21 |
|
---|
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.
|
---|
24 | """
|
---|
25 |
|
---|
26 | import unittest
|
---|
27 | from samba import credentials
|
---|
28 |
|
---|
29 | class CredentialsTests(unittest.TestCase):
|
---|
30 | def setUp(self):
|
---|
31 | self.creds = credentials.Credentials()
|
---|
32 |
|
---|
33 | def test_set_username(self):
|
---|
34 | self.creds.set_username("somebody")
|
---|
35 | self.assertEquals("somebody", self.creds.get_username())
|
---|
36 |
|
---|
37 | def test_set_password(self):
|
---|
38 | self.creds.set_password("S3CreT")
|
---|
39 | self.assertEquals("S3CreT", self.creds.get_password())
|
---|
40 |
|
---|
41 | def test_set_domain(self):
|
---|
42 | self.creds.set_domain("ABMAS")
|
---|
43 | self.assertEquals("ABMAS", self.creds.get_domain())
|
---|
44 |
|
---|
45 | def test_set_realm(self):
|
---|
46 | self.creds.set_realm("myrealm")
|
---|
47 | self.assertEquals("MYREALM", self.creds.get_realm())
|
---|
48 |
|
---|
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())
|
---|
53 |
|
---|
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())
|
---|
59 |
|
---|
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())
|
---|
64 |
|
---|
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())
|
---|
72 |
|
---|
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())
|
---|
78 |
|
---|
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())
|
---|
83 |
|
---|
84 | def test_guess(self):
|
---|
85 | # Just check the method is there and doesn't raise an exception
|
---|
86 | self.creds.guess()
|
---|
87 |
|
---|
88 | def test_set_cmdline_callbacks(self):
|
---|
89 | self.creds.set_cmdline_callbacks()
|
---|
90 |
|
---|
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())
|
---|
96 |
|
---|
97 | def test_wrong_password(self):
|
---|
98 | self.assertFalse(self.creds.wrong_password())
|
---|