From df1016771131462411d7056233863f06adac34e2 Mon Sep 17 00:00:00 2001 From: Max Ustinov Date: Fri, 15 Sep 2023 13:45:21 -0700 Subject: [PATCH] KSM CLI: Adjusted handling of empty _fields in Keeper Secrets Manager Adjusted the dump method in Keeper Secrets Manager's mock.py to account for empty _fields variable, preventing a NoneType error. Updated the unit tests in secret_test.py to align with these changes, reducing the expected length of fields from 6 to 4 and adjusting the index of field from 1 to 0. Also, removed unnecessary print statement in the test. This ensures that tests correctly correspond to the application code and avoid false negatives. --- integration/keeper_secrets_manager_cli/tests/secret_test.py | 5 ++--- sdk/python/core/keeper_secrets_manager_core/mock.py | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/integration/keeper_secrets_manager_cli/tests/secret_test.py b/integration/keeper_secrets_manager_cli/tests/secret_test.py index 92b532c3..d1a2bc26 100644 --- a/integration/keeper_secrets_manager_cli/tests/secret_test.py +++ b/integration/keeper_secrets_manager_cli/tests/secret_test.py @@ -160,7 +160,7 @@ def test_get(self): self.assertEqual(0, result.exit_code, "the exit code was not 0") fields = json.loads(result.output) - self.assertEqual(6, len(fields), "didn't find 6 objects in array") + self.assertEqual(4, len(fields), "didn't find 4 objects in array") # Text Output to file tf_name = self._make_temp_file() @@ -185,7 +185,6 @@ def test_get(self): '--query', '[*].fields[*].type', '--force-array', '--deflate', ], catch_exceptions=True) - print(f'result.output: {result.output}') # TODO: remove after test data = json.loads(result.output) self.assertEqual(4, len(data), "found 4 rows") self.assertEqual(0, result.exit_code, "the exit code was not 0") @@ -959,7 +958,7 @@ def test_template_record_types(self): self.assertIsInstance(data.get("fields"), list, "fields is not a list") - field = data.get("fields")[1] + field = data.get("fields")[0] self.assertEqual("login", field.get("type"), "field type is not login") self.assertIsNotNone(field.get("value"), "value was None") diff --git a/sdk/python/core/keeper_secrets_manager_core/mock.py b/sdk/python/core/keeper_secrets_manager_core/mock.py index 0665590b..244dc8b6 100644 --- a/sdk/python/core/keeper_secrets_manager_core/mock.py +++ b/sdk/python/core/keeper_secrets_manager_core/mock.py @@ -390,7 +390,7 @@ def add_file(self, name, title=None, content_type=None, url=None, content=None, def dump(self, secret, flags=None): - fields = self._fields + fields = self._fields if self._fields else [] # If no files, the JSON has null files = None