mirror of
https://github.com/saltstack/salt.git
synced 2025-04-16 09:40:20 +00:00
Fix nt_hash use in pdbedit.create (convert to string)
This commit is contained in:
parent
bbe4cab183
commit
dcdafc3954
3 changed files with 23 additions and 1 deletions
1
changelog/62670.fixed
Normal file
1
changelog/62670.fixed
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Fixed pdbedit.create trying to use a bytes-like hash as string.
|
|
@ -203,7 +203,7 @@ def create(login, password, password_hashed=False, machine_account=False):
|
||||||
password_hash = password.upper()
|
password_hash = password.upper()
|
||||||
password = "" # wipe password
|
password = "" # wipe password
|
||||||
else:
|
else:
|
||||||
password_hash = generate_nt_hash(password)
|
password_hash = generate_nt_hash(password).decode("ascii")
|
||||||
|
|
||||||
# create user
|
# create user
|
||||||
if login not in list_users(False):
|
if login not in list_users(False):
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import hashlib
|
||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -5,6 +6,12 @@ import pytest
|
||||||
import salt.modules.pdbedit as pdbedit
|
import salt.modules.pdbedit as pdbedit
|
||||||
from tests.support.mock import MagicMock, patch
|
from tests.support.mock import MagicMock, patch
|
||||||
|
|
||||||
|
try:
|
||||||
|
hashlib.new("md4", "".encode("utf-16le"))
|
||||||
|
MD4_SUPPORTED = True
|
||||||
|
except ValueError:
|
||||||
|
MD4_SUPPORTED = False
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def configure_loader_modules():
|
def configure_loader_modules():
|
||||||
|
@ -134,3 +141,17 @@ def test_when_verbose_and_multiple_records_present_data_should_be_correctly_pars
|
||||||
):
|
):
|
||||||
actual_data = pdbedit.list_users(verbose=True)
|
actual_data = pdbedit.list_users(verbose=True)
|
||||||
assert actual_data == expected_data
|
assert actual_data == expected_data
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skipif(not MD4_SUPPORTED, reason="Requires md4")
|
||||||
|
def test_create_with_existing_user_updates_password():
|
||||||
|
with patch(
|
||||||
|
"salt.modules.pdbedit.list_users", MagicMock(return_value=["Foo"])
|
||||||
|
), patch(
|
||||||
|
"salt.modules.pdbedit.get_user",
|
||||||
|
MagicMock(return_value={"nt hash": "old value"}),
|
||||||
|
), patch.dict(
|
||||||
|
pdbedit.__salt__, {"cmd.run_all": MagicMock(return_value={"retcode": 0})}
|
||||||
|
):
|
||||||
|
ret = pdbedit.create("Foo", "secret")
|
||||||
|
assert {"Foo": "updated"} == ret
|
||||||
|
|
Loading…
Add table
Reference in a new issue