Skip to content

Commit bb38fec

Browse files
mgr/smb: add test cases for password filering on smb apply command
Signed-off-by: John Mulligan <[email protected]>
1 parent fd00ab7 commit bb38fec

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

src/pybind/mgr/smb/tests/test_smb.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,3 +748,83 @@ def test_show_password_filter_b64(tmodule):
748748
join_auth = ja[0]
749749
assert join_auth['auth']['username'] == 'testadmin'
750750
assert join_auth['auth']['password'] == 'UGFzc3cwcmQ='
751+
752+
753+
def test_apply_password_filter(tmodule):
754+
_example_cfg_1(tmodule)
755+
756+
txt = json.dumps(
757+
{
758+
'resource_type': 'ceph.smb.usersgroups',
759+
'users_groups_id': 'ug1',
760+
'intent': 'present',
761+
'values': {
762+
'users': [
763+
{'username': 'foo', 'password': 'YWJyYWNhZGFicmE='},
764+
{'username': 'bar', 'password': 'eHl6enk='},
765+
],
766+
'groups': [],
767+
},
768+
}
769+
)
770+
771+
rg = tmodule.apply_resources(
772+
txt, password_filter=smb.enums.InputPasswordFilter.BASE64
773+
)
774+
assert rg.success, rg.to_simplified()
775+
ts = rg.to_simplified()
776+
assert len(ts['results']) == 1
777+
r = ts['results'][0]['resource']
778+
assert r['resource_type'] == 'ceph.smb.usersgroups'
779+
assert len(r['values']['users']) == 2
780+
# filtered passwords of command output should match input by default
781+
assert r['values']['users'][0]['password'] == 'YWJyYWNhZGFicmE='
782+
assert r['values']['users'][1]['password'] == 'eHl6enk='
783+
784+
# get unfiltered object
785+
out = tmodule.show(['ceph.smb.usersgroups.ug1'])
786+
assert out['resource_type'] == 'ceph.smb.usersgroups'
787+
assert len(out['values']['users']) == 2
788+
assert out['values']['users'][0]['password'] == 'abracadabra'
789+
assert out['values']['users'][1]['password'] == 'xyzzy'
790+
791+
792+
def test_apply_password_filter_in_out(tmodule):
793+
_example_cfg_1(tmodule)
794+
795+
txt = json.dumps(
796+
{
797+
'resource_type': 'ceph.smb.usersgroups',
798+
'users_groups_id': 'ug1',
799+
'intent': 'present',
800+
'values': {
801+
'users': [
802+
{'username': 'foo', 'password': 'YWJyYWNhZGFicmE='},
803+
{'username': 'bar', 'password': 'eHl6enk='},
804+
],
805+
'groups': [],
806+
},
807+
}
808+
)
809+
810+
rg = tmodule.apply_resources(
811+
txt,
812+
password_filter=smb.enums.InputPasswordFilter.BASE64,
813+
password_filter_out=smb.enums.PasswordFilter.HIDDEN,
814+
)
815+
assert rg.success, rg.to_simplified()
816+
ts = rg.to_simplified()
817+
assert len(ts['results']) == 1
818+
r = ts['results'][0]['resource']
819+
assert r['resource_type'] == 'ceph.smb.usersgroups'
820+
assert len(r['values']['users']) == 2
821+
# filtered passwords of command output should match input by default
822+
assert r['values']['users'][0]['password'] == '****************'
823+
assert r['values']['users'][1]['password'] == '****************'
824+
825+
# get unfiltered object
826+
out = tmodule.show(['ceph.smb.usersgroups.ug1'])
827+
assert out['resource_type'] == 'ceph.smb.usersgroups'
828+
assert len(out['values']['users']) == 2
829+
assert out['values']['users'][0]['password'] == 'abracadabra'
830+
assert out['values']['users'][1]['password'] == 'xyzzy'

0 commit comments

Comments
 (0)