From bb38fecf60fd861d0f7310d691d3bd9cb92a7d89 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Mon, 17 Mar 2025 15:35:55 -0400 Subject: [PATCH] mgr/smb: add test cases for password filering on smb apply command Signed-off-by: John Mulligan --- src/pybind/mgr/smb/tests/test_smb.py | 80 ++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/src/pybind/mgr/smb/tests/test_smb.py b/src/pybind/mgr/smb/tests/test_smb.py index f94939ffaa3..3eb82986407 100644 --- a/src/pybind/mgr/smb/tests/test_smb.py +++ b/src/pybind/mgr/smb/tests/test_smb.py @@ -748,3 +748,83 @@ def test_show_password_filter_b64(tmodule): join_auth = ja[0] assert join_auth['auth']['username'] == 'testadmin' assert join_auth['auth']['password'] == 'UGFzc3cwcmQ=' + + +def test_apply_password_filter(tmodule): + _example_cfg_1(tmodule) + + txt = json.dumps( + { + 'resource_type': 'ceph.smb.usersgroups', + 'users_groups_id': 'ug1', + 'intent': 'present', + 'values': { + 'users': [ + {'username': 'foo', 'password': 'YWJyYWNhZGFicmE='}, + {'username': 'bar', 'password': 'eHl6enk='}, + ], + 'groups': [], + }, + } + ) + + rg = tmodule.apply_resources( + txt, password_filter=smb.enums.InputPasswordFilter.BASE64 + ) + assert rg.success, rg.to_simplified() + ts = rg.to_simplified() + assert len(ts['results']) == 1 + r = ts['results'][0]['resource'] + assert r['resource_type'] == 'ceph.smb.usersgroups' + assert len(r['values']['users']) == 2 + # filtered passwords of command output should match input by default + assert r['values']['users'][0]['password'] == 'YWJyYWNhZGFicmE=' + assert r['values']['users'][1]['password'] == 'eHl6enk=' + + # get unfiltered object + out = tmodule.show(['ceph.smb.usersgroups.ug1']) + assert out['resource_type'] == 'ceph.smb.usersgroups' + assert len(out['values']['users']) == 2 + assert out['values']['users'][0]['password'] == 'abracadabra' + assert out['values']['users'][1]['password'] == 'xyzzy' + + +def test_apply_password_filter_in_out(tmodule): + _example_cfg_1(tmodule) + + txt = json.dumps( + { + 'resource_type': 'ceph.smb.usersgroups', + 'users_groups_id': 'ug1', + 'intent': 'present', + 'values': { + 'users': [ + {'username': 'foo', 'password': 'YWJyYWNhZGFicmE='}, + {'username': 'bar', 'password': 'eHl6enk='}, + ], + 'groups': [], + }, + } + ) + + rg = tmodule.apply_resources( + txt, + password_filter=smb.enums.InputPasswordFilter.BASE64, + password_filter_out=smb.enums.PasswordFilter.HIDDEN, + ) + assert rg.success, rg.to_simplified() + ts = rg.to_simplified() + assert len(ts['results']) == 1 + r = ts['results'][0]['resource'] + assert r['resource_type'] == 'ceph.smb.usersgroups' + assert len(r['values']['users']) == 2 + # filtered passwords of command output should match input by default + assert r['values']['users'][0]['password'] == '****************' + assert r['values']['users'][1]['password'] == '****************' + + # get unfiltered object + out = tmodule.show(['ceph.smb.usersgroups.ug1']) + assert out['resource_type'] == 'ceph.smb.usersgroups' + assert len(out['values']['users']) == 2 + assert out['values']['users'][0]['password'] == 'abracadabra' + assert out['values']['users'][1]['password'] == 'xyzzy' -- 2.39.5