]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/smb: add test cases for password filering on smb apply command
authorJohn Mulligan <jmulligan@redhat.com>
Mon, 17 Mar 2025 19:35:55 +0000 (15:35 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Tue, 1 Apr 2025 12:02:39 +0000 (08:02 -0400)
Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/pybind/mgr/smb/tests/test_smb.py

index f94939ffaa36bfa3405890e318add33fb03bc863..3eb8298640722b73ec6ad86665a0a8cc7a620844 100644 (file)
@@ -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'