PEP8: fix E302: expected 2 blank lines, found 1
[metze/samba/wip.git] / python / samba / tests / password_test.py
1 # -*- coding: utf-8 -*-
2 #
3 # Common functionality for all password change tests
4 #
5 # Copyright (C) Andrew Bartlett <abartlet@samba.org> 2018
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20
21 import samba.tests
22 from samba.samdb import SamDB
23
24
25 class PasswordCommon:
26
27     @staticmethod
28     def allow_password_changes(testcase, samdb):
29         """Updates the DC to allow password changes during the current test"""
30
31         # Get the old "dSHeuristics" if it was set
32         dsheuristics = samdb.get_dsheuristics()
33
34         # Reset the "dSHeuristics" as they were before
35         testcase.addCleanup(samdb.set_dsheuristics, dsheuristics)
36
37         # Set the "dSHeuristics" to activate the correct "userPassword" behaviour
38         samdb.set_dsheuristics("000000001")
39
40         # Get the old "minPwdAge"
41         minPwdAge = samdb.get_minPwdAge()
42
43         # Reset the "minPwdAge" as it was before
44         testcase.addCleanup(samdb.set_minPwdAge, minPwdAge)
45
46         # Set it temporarily to "0"
47         samdb.set_minPwdAge("0")
48
49
50 class PasswordTestCase(samba.tests.TestCase):
51
52     # this requires that an LDB connection has already been setup (so is not
53     # part of the inherited setUp())
54     def allow_password_changes(self, samdb=None):
55         """Updates the DC to allow password changes during the current test"""
56
57         if samdb is None:
58             samdb = self.ldb
59
60         PasswordCommon.allow_password_changes(self, samdb)
61