Move the mac_user._kcpassword unit test into the pytests directory.

Also fix a typo in the pytests README.
This commit is contained in:
pjcreath 2023-05-04 13:54:33 +00:00 committed by Megan Wilhite
parent 64def39282
commit 7fc547faff
3 changed files with 22 additions and 25 deletions

View file

@ -11,4 +11,4 @@ shall be used, neither our [customizations to it](../support/case.py).
While [PyTest](https://docs.pytest.org) can happily run unittest tests(withough taking advantage of most of PyTest's strengths),
this new path in the tests directory was created to provide a clear separation between the two approaches to writing tests.
Some(hopefully all) of the existing unittest tests might get ported to PyTest's style of writing tests, new tests should be added under
this directory tree, and, in the long run, this directoy shall become the top level tests directoy.
this directory tree, and, in the long run, this directory shall become the top level tests directory.

View file

@ -420,3 +420,24 @@ def test_list_users():
mac_user.__salt__, {"cmd.run_all": mock_run}
):
assert mac_user.list_users() == expected
def test_kcpassword():
hashes = {
# Actual hashes from macOS, since reference implementation didn't account for trailing null
"0": "4d 89 f9 91 1f 7a 46 5e f7 a8 11 ff",
"password": "0d e8 21 50 a5 d3 af 8e a3 de d9 14",
"shorterpwd": "0e e1 3d 51 a6 d9 af 9a d4 dd 1f 27",
"Squarepants": "2e f8 27 42 a0 d9 ad 8b cd cd 6c 7d",
"longerpasswd": "11 e6 3c 44 b7 ce ad 8b d0 ca 68 19 89 b1 65 ae 7e 89 12 b8 51 f8 f0 ff",
"ridiculouslyextendedpass": "0f e0 36 4a b1 c9 b1 85 d6 ca 73 04 ec 2a 57 b7 d2 b9 8f c7 c9 7e 0e fa 52 7b 71 e6 f8 b7 a6 ae 47 94 d7 86",
}
for password, hash in hashes.items():
kcpass = mac_user._kcpassword(password)
hash = bytes.fromhex(hash)
# macOS adds a trailing null and pads the rest with random data
length = len(password) + 1
assert kcpass[:length] == hash[:length]
assert len(kcpass) == len(hash)

View file

@ -1,24 +0,0 @@
import salt.modules.mac_user as user
from tests.support.unit import TestCase
class MacUserTestCase(TestCase):
def test_kcpass(self):
hashes = {
# Actual hashes from macOS, since reference implementation didn't account for trailing null
"0": "4d 89 f9 91 1f 7a 46 5e f7 a8 11 ff",
"password": "0d e8 21 50 a5 d3 af 8e a3 de d9 14",
"shorterpwd": "0e e1 3d 51 a6 d9 af 9a d4 dd 1f 27",
"Squarepants": "2e f8 27 42 a0 d9 ad 8b cd cd 6c 7d",
"longerpasswd": "11 e6 3c 44 b7 ce ad 8b d0 ca 68 19 89 b1 65 ae 7e 89 12 b8 51 f8 f0 ff",
"ridiculouslyextendedpass": "0f e0 36 4a b1 c9 b1 85 d6 ca 73 04 ec 2a 57 b7 d2 b9 8f c7 c9 7e 0e fa 52 7b 71 e6 f8 b7 a6 ae 47 94 d7 86",
}
for password, hash in hashes.items():
kcpass = user._kcpassword(password)
hash = bytes.fromhex(hash)
# macOS adds a trailing null and pads the rest with random data
length = len(password) + 1
self.assertEqual(kcpass[:length], hash[:length])
self.assertEqual(len(kcpass), len(hash))