mirror of
https://github.com/samba-team/samba.git
synced 2025-12-23 00:23:53 +03:00
password_hash: Add tests to allow refactoring
Add tests for password_hash.c to allow refactoring of setup_supplemental_field Signed-off-by: Gary Lockyer <gary@catalyst.net.nz> Reviewed-by: Garming Sam <garming@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
committed by
Andrew Bartlett
parent
78403a8a71
commit
d1f4fc9ee3
126
python/samba/tests/password_hash_gpgme.py
Normal file
126
python/samba/tests/password_hash_gpgme.py
Normal file
@@ -0,0 +1,126 @@
|
||||
# Tests for Tests for source4/dsdb/samdb/ldb_modules/password_hash.c
|
||||
#
|
||||
# Copyright (C) Catalyst IT Ltd. 2017
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
"""
|
||||
Tests for source4/dsdb/samdb/ldb_modules/password_hash.c
|
||||
These tests need to be run in an environment in which
|
||||
io->ac->gpg_key_ids != NULL, so that the gpg supplemental credentials
|
||||
are generated. The functional level needs to be >= 2008 so that the
|
||||
kerberos newer keys are generated.
|
||||
"""
|
||||
|
||||
|
||||
from samba.tests.password_hash import (
|
||||
PassWordHashTests,
|
||||
get_package,
|
||||
USER_PASS
|
||||
)
|
||||
from samba.ndr import ndr_unpack
|
||||
from samba.dcerpc import drsblobs
|
||||
import binascii
|
||||
|
||||
|
||||
class PassWordHashGpgmeTests(PassWordHashTests):
|
||||
|
||||
def setUp(self):
|
||||
super(PassWordHashGpgmeTests, self).setUp()
|
||||
|
||||
def test_default_supplementalCredentials(self):
|
||||
self.add_user()
|
||||
if not self.lp.get("password hash gpg key ids"):
|
||||
self.skipTest("No password hash gpg key ids, " +
|
||||
"Primary:SambaGPG will not be generated");
|
||||
|
||||
sc = self.get_supplemental_creds()
|
||||
|
||||
# Check that we got all the expected supplemental credentials
|
||||
# And they are in the expected order.
|
||||
size = len(sc.sub.packages)
|
||||
self.assertEquals(5, size)
|
||||
(pos, package) = get_package(sc, "Primary:Kerberos-Newer-Keys")
|
||||
self.assertEquals(1, pos)
|
||||
self.assertEquals("Primary:Kerberos-Newer-Keys", package.name)
|
||||
|
||||
(pos, package) = get_package(sc, "Primary:Kerberos")
|
||||
self.assertEquals(2, pos)
|
||||
self.assertEquals("Primary:Kerberos", package.name)
|
||||
|
||||
(pos, wd_package) = get_package(sc, "Primary:WDigest")
|
||||
self.assertEquals(3, pos)
|
||||
self.assertEquals("Primary:WDigest", wd_package.name)
|
||||
|
||||
(pos, package) = get_package(sc, "Packages")
|
||||
self.assertEquals(4, pos)
|
||||
self.assertEquals("Packages", package.name)
|
||||
|
||||
(pos, package) = get_package(sc, "Primary:SambaGPG")
|
||||
self.assertEquals(5, pos)
|
||||
self.assertEquals("Primary:SambaGPG", package.name)
|
||||
|
||||
# Check that the WDigest values are correct.
|
||||
#
|
||||
digests = ndr_unpack(drsblobs.package_PrimaryWDigestBlob,
|
||||
binascii.a2b_hex(wd_package.data))
|
||||
self.check_wdigests(digests)
|
||||
|
||||
def test_supplementalCredentials_cleartext(self):
|
||||
self.add_user(clear_text=True)
|
||||
if not self.lp.get("password hash gpg key ids"):
|
||||
self.skipTest("No password hash gpg key ids, " +
|
||||
"Primary:SambaGPG will not be generated");
|
||||
|
||||
sc = self.get_supplemental_creds()
|
||||
|
||||
# Check that we got all the expected supplemental credentials
|
||||
# And they are in the expected order.
|
||||
size = len(sc.sub.packages)
|
||||
self.assertEquals(6, size)
|
||||
(pos, package) = get_package(sc, "Primary:Kerberos-Newer-Keys")
|
||||
self.assertEquals(1, pos)
|
||||
self.assertEquals("Primary:Kerberos-Newer-Keys", package.name)
|
||||
|
||||
(pos, package) = get_package(sc, "Primary:Kerberos")
|
||||
self.assertEquals(2, pos)
|
||||
self.assertEquals("Primary:Kerberos", package.name)
|
||||
|
||||
(pos, wd_package) = get_package(sc, "Primary:WDigest")
|
||||
self.assertEquals(3, pos)
|
||||
self.assertEquals("Primary:WDigest", wd_package.name)
|
||||
|
||||
(pos, ct_package) = get_package(sc, "Primary:CLEARTEXT")
|
||||
self.assertEquals(4, pos)
|
||||
self.assertEquals("Primary:CLEARTEXT", ct_package.name)
|
||||
|
||||
(pos, package) = get_package(sc, "Packages")
|
||||
self.assertEquals(5, pos)
|
||||
self.assertEquals("Packages", package.name)
|
||||
|
||||
(pos, package) = get_package(sc, "Primary:SambaGPG")
|
||||
self.assertEquals(6, pos)
|
||||
self.assertEquals("Primary:SambaGPG", package.name)
|
||||
|
||||
# Check that the WDigest values are correct.
|
||||
#
|
||||
digests = ndr_unpack(drsblobs.package_PrimaryWDigestBlob,
|
||||
binascii.a2b_hex(wd_package.data))
|
||||
self.check_wdigests(digests)
|
||||
|
||||
# Check the clear text value is correct.
|
||||
ct = ndr_unpack(drsblobs.package_PrimaryCLEARTEXTBlob,
|
||||
binascii.a2b_hex(ct_package.data))
|
||||
self.assertEquals(USER_PASS.encode('utf-16-le'), ct.cleartext)
|
||||
Reference in New Issue
Block a user