Skip to content

Commit

Permalink
[test] Ensure string secret created from files can be edited
Browse files Browse the repository at this point in the history
o opensvc/tests/test mgr.py::TestCfgSecEdit
  o test can edit editable objects created from file (sec)
  • Loading branch information
cgalibern committed Oct 16, 2020
1 parent be4fb8a commit 9013f4c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
6 changes: 5 additions & 1 deletion opensvc/core/objects/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ def edit(self):
if buff is None:
raise ex.Error("could not decode the secret key '%s'" % self.options.key)
if isinstance(buff, bytes):
raise ex.Error("binary keys are not editable")
try:
self.log.debug("try decode binary key")
buff = buff.decode()
except:
raise ex.Error("binary keys are not editable")
no_newline = os.sep not in try_decode(buff)
editor = find_editor()
fpath = self.tempfilename()
Expand Down
2 changes: 1 addition & 1 deletion opensvc/tests/test_mgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ def file_editor_side_effect(_, fpath):
assert output_file.read() == 'abcd text added'

@staticmethod
@pytest.mark.parametrize('obj', ['demo/cfg/name'])
@pytest.mark.parametrize('obj', ['demo/cfg/name', 'demo/sec/name'])
def test_can_edit_editable_objects_created_from_file(mocker, capture_stdout, tmp_file, obj):
"""
objects created from file are bytes
Expand Down
3 changes: 2 additions & 1 deletion opensvc/utilities/edit_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@


def edit_file(editor, fpath):
os.system(' '.join((editor, fpath)))
# for python 2.7 pylint disable no-member
os.system(' '.join((editor, fpath))) # pylint: disable=no-member

0 comments on commit 9013f4c

Please sign in to comment.