Skip to content

Commit

Permalink
Test saving profile with nested secure property
Browse files Browse the repository at this point in the history
Signed-off-by: Timothy Johnson <[email protected]>
  • Loading branch information
t1m0thyj committed Sep 29, 2023
1 parent ae02364 commit 248f6d2
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions tests/unit/test_zowe_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,25 +939,35 @@ def test_config_file_save(self, mock_save_secure_props):
cwd_up_file_path = os.path.join(cwd_up_dir_path, "zowe.config.json")
os.chdir(CWD)
shutil.copy(self.original_file_path, cwd_up_file_path)
config_data = {
"profiles": {
"zosmf": {
"properties": {
"user": "admin",
"port": 1443
},
"secure": ["user"]
}
profile_data = {
"lpar1": {
"profiles": {
"zosmf": {
"properties": {
"port": 1443,
"password": "secret"
},
"secure": ["password"]
}
},
"properties": {
"host": "example.com",
"user": "admin"
},
"secure": ["user"]
}
}
with mock.patch("builtins.open", mock.mock_open()) as mock_file:
config_file = ConfigFile("User Config", "zowe.config.json", cwd_up_dir_path , profiles=config_data.copy())
config_file.jsonc = config_data
config_file = ConfigFile("User Config", "zowe.config.json", cwd_up_dir_path, profiles=profile_data)
config_file.jsonc = {"profiles": profile_data}
config_file.save()

mock_save_secure_props.assert_called_once()
mock_file.assert_called_once_with(cwd_up_file_path, 'w')
mock_file.return_value.__enter__.return_value.write.asser_called()
mock_save_secure_props.assert_called_once()
mock_file.assert_called_once_with(cwd_up_file_path, 'w')
mock_file.return_value.write.assert_called()
self.assertIn("user", profile_data["lpar1"]["properties"])
self.assertNotIn("user", config_file.jsonc["profiles"]["lpar1"]["properties"])
self.assertEqual(["port"], list(config_file.jsonc["profiles"]["lpar1"]["profiles"]["zosmf"]["properties"].keys()))


class TestValidateConfigJsonClass(unittest.TestCase):
Expand Down

0 comments on commit 248f6d2

Please sign in to comment.