Skip to content

Commit

Permalink
KSM CLI: Adjusted handling of empty _fields in Keeper Secrets Manager
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
maksimu committed Sep 15, 2023
1 parent 375bf95 commit df10167
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 2 additions & 3 deletions integration/keeper_secrets_manager_cli/tests/secret_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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")
Expand Down Expand Up @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion sdk/python/core/keeper_secrets_manager_core/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit df10167

Please sign in to comment.