1 # Unix SMB/CIFS implementation.
2 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007-2008
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 samba.upgradeprovision."""
21 from samba
.upgradehelpers
import (usn_in_range
, dn_sort
,
22 get_diff_sddls
, update_secrets
,
23 construct_existor_expr
)
25 from samba
.tests
.provision
import create_dummy_secretsdb
26 from samba
.tests
import TestCaseInTempDir
28 from ldb
import SCOPE_BASE
31 def dummymessage(a
=None, b
=None):
35 class UpgradeProvisionTestCase(TestCaseInTempDir
):
36 """Some simple tests for individual functions in the provisioning code.
38 def test_usn_in_range(self
):
39 range = [5, 25, 35, 55]
44 self
.assertFalse(usn_in_range(v
, range))
46 vals
= [5, 20, 25, 35, 36]
49 self
.assertTrue(usn_in_range(v
, range))
51 def test_dn_sort(self
):
52 # higher level comes after lower even if lexicographicaly closer
53 # ie dc=tata,dc=toto (2 levels), comes after dc=toto
54 # even if dc=toto is lexicographicaly after dc=tata, dc=toto
55 self
.assertEquals(dn_sort("dc=tata,dc=toto", "dc=toto"), 1)
56 self
.assertEquals(dn_sort("dc=zata", "dc=tata"), 1)
57 self
.assertEquals(dn_sort("dc=toto,dc=tata",
58 "cn=foo,dc=toto,dc=tata"), -1)
59 self
.assertEquals(dn_sort("cn=bar, dc=toto,dc=tata",
60 "cn=foo, dc=toto,dc=tata"), -1)
62 def test_get_diff_sddl(self
):
63 sddl
= "O:SAG:DUD:AI(A;CIID;RPWPCRCCLCLORCWOWDSW;;;SA)\
64 (A;CIID;RP LCLORC;;;AU)(A;CIID;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)S:AI(AU;CIIDSA;WP;;;WD)"
65 sddl1
= "O:SAG:DUD:AI(A;CIID;RPWPCRCCLCLORCWOWDSW;;;SA)\
66 (A;CIID;RP LCLORC;;;AU)(A;CIID;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)S:AI(AU;CIIDSA;WP;;;WD)"
67 sddl2
= "O:BAG:DUD:AI(A;CIID;RPWPCRCCLCLORCWOWDSW;;;SA)\
68 (A;CIID;RP LCLORC;;;AU)(A;CIID;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)S:AI(AU;CIIDSA;WP;;;WD)"
69 sddl3
= "O:SAG:BAD:AI(A;CIID;RPWPCRCCLCLORCWOWDSW;;;SA)\
70 (A;CIID;RP LCLORC;;;AU)(A;CIID;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)S:AI(AU;CIIDSA;WP;;;WD)"
71 sddl4
= "O:SAG:DUD:AI(A;CIID;RPWPCRCCLCLORCWOWDSW;;;BA)\
72 (A;CIID;RP LCLORC;;;AU)(A;CIID;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)S:AI(AU;CIIDSA;WP;;;WD)"
73 sddl5
= "O:SAG:DUD:AI(A;CIID;RPWPCRCCLCLORCWOWDSW;;;SA)\
74 (A;CIID;RP LCLORC;;;AU)(A;CIID;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)"
76 self
.assertEquals(get_diff_sddls(sddl
, sddl1
), "")
77 txt
= get_diff_sddls(sddl
, sddl2
)
78 self
.assertEquals(txt
, "\tOwner mismatch: SA (in ref) BA(in current)\n")
79 txt
= get_diff_sddls(sddl
, sddl3
)
80 self
.assertEquals(txt
, "\tGroup mismatch: DU (in ref) BA(in current)\n")
81 txt
= get_diff_sddls(sddl
, sddl4
)
82 txtmsg
= "\tPart dacl is different between reference and current here\
83 is the detail:\n\t\t(A;CIID;RPWPCRCCLCLORCWOWDSW;;;BA) ACE is not present in\
84 the reference\n\t\t(A;CIID;RPWPCRCCLCLORCWOWDSW;;;SA) ACE is not present in\
86 self
.assertEquals(txt
, txtmsg
)
87 txt
= get_diff_sddls(sddl
, sddl5
)
88 self
.assertEquals(txt
, "\tCurrent ACL hasn't a sacl part\n")
90 def test_construct_existor_expr(self
):
91 res
= construct_existor_expr([])
92 self
.assertEquals(res
, "")
94 res
= construct_existor_expr(["foo"])
95 self
.assertEquals(res
, "(|(foo=*))")
97 res
= construct_existor_expr(["foo", "bar"])
98 self
.assertEquals(res
, "(|(foo=*)(bar=*))")
101 class UpdateSecretsTests(samba
.tests
.TestCaseInTempDir
):
104 super(UpdateSecretsTests
, self
).setUp()
105 self
.referencedb
= create_dummy_secretsdb(
106 os
.path
.join(self
.tempdir
, "ref.ldb"))
108 def _getEmptyDb(self
):
109 return Ldb(os
.path
.join(self
.tempdir
, "secrets.ldb"))
111 def _getCurrentFormatDb(self
):
112 return create_dummy_secretsdb(
113 os
.path
.join(self
.tempdir
, "secrets.ldb"))
115 def test_trivial(self
):
116 # Test that updating an already up-to-date secretsdb works fine
117 self
.secretsdb
= self
._getCurrentFormatDb
()
118 self
.assertEquals(None,
119 update_secrets(self
.referencedb
, self
.secretsdb
, dummymessage
))
121 def test_update_modules(self
):
122 empty_db
= self
._getEmptyDb
()
123 update_secrets(self
.referencedb
, empty_db
, dummymessage
)
124 newmodules
= empty_db
.search(base
="@MODULES", scope
=SCOPE_BASE
)
125 refmodules
= self
.referencedb
.search(base
="@MODULES", scope
=SCOPE_BASE
)
126 self
.assertEquals(newmodules
.msgs
, refmodules
.msgs
)
129 for name
in ["ref.ldb", "secrets.ldb", "secrets.tdb", "secrets.tdb.bak", "secrets.ntdb"]:
130 path
= os
.path
.join(self
.tempdir
, name
)
131 if os
.path
.exists(path
):
133 super(UpdateSecretsTests
, self
).tearDown()