ctdb-server: Use find_public_ip_vnn() in a couple of extra places
[Samba.git] / python / samba / tests / samba_tool / user_auth_silo.py
blob8ffc80cfcf4efc40e623c07b6c85c171e2ff50c1
1 # Unix SMB/CIFS implementation.
3 # Tests for samba-tool user auth silo command
5 # Copyright (C) Catalyst.Net Ltd. 2023
7 # Written by Rob van der Linde <rob@catalyst.net.nz>
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 from samba.domain.models import AuthenticationSilo, User
25 from .silo_base import SiloTest
28 class AuthPolicyCmdTestCase(SiloTest):
29 def test_assign(self):
30 """Test assigning an authentication silo to a user."""
31 self.addCleanup(self.runcmd, "user", "auth", "silo", "remove", "alice")
32 result, out, err = self.runcmd("user", "auth", "silo", "assign",
33 "alice", "--silo", "Developers")
34 self.assertIsNone(result, msg=err)
36 # Assigned silo should be 'Developers'
37 user = User.get(self.samdb, account_name="alice")
38 silo = AuthenticationSilo.get(self.samdb, dn=user.assigned_silo)
39 self.assertEqual(silo.name, "Developers")
41 def test_assign__invalid_silo(self):
42 """Test assigning a non-existing authentication silo to a user."""
43 result, out, err = self.runcmd("user", "auth", "silo", "assign",
44 "alice", "--silo", "doesNotExist")
45 self.assertEqual(result, -1)
46 self.assertIn("Authentication silo doesNotExist not found.", err)
48 def test_remove(self):
49 """Test removing the assigned authentication silo from a user."""
50 # First assign a silo, so we can test removing it.
51 self.runcmd("user", "auth", "silo", "assign", "bob", "--silo", "QA")
53 # Assigned silo should be set
54 user = User.get(self.samdb, account_name="bob")
55 self.assertIsNotNone(user.assigned_silo)
57 # Now try removing it
58 result, out, err = self.runcmd("user", "auth", "silo", "remove",
59 "bob")
60 self.assertIsNone(result, msg=err)
62 # Assigned silo should be None
63 user = User.get(self.samdb, account_name="bob")
64 self.assertIsNone(user.assigned_silo)
66 def test_view(self):
67 """Test viewing the current assigned authentication silo on a user."""
68 # Assign a silo on one of the users.
69 self.addCleanup(self.runcmd, "user", "auth", "silo", "remove", "bob")
70 self.runcmd("user", "auth", "silo", "assign", "bob", "--silo", "QA")
72 # Test user with a silo assigned.
73 result, out, err = self.runcmd("user", "auth", "silo", "view",
74 "bob")
75 self.assertIsNone(result, msg=err)
76 self.assertEqual(
77 out, "User bob assigned to authentication silo QA (revoked)\n")
79 # Test user without a silo assigned.
80 result, out, err = self.runcmd("user", "auth", "silo", "view",
81 "joe")
82 self.assertIsNone(result, msg=err)
83 self.assertEqual(
84 out, "User joe has no assigned authentication silo.\n")