diff --git a/command_callbacks.py b/command_callbacks.py index 2ec095e..a636c39 100644 --- a/command_callbacks.py +++ b/command_callbacks.py @@ -1743,10 +1743,14 @@ def savestate_filename(input_dict, environment_dict): input_dict = input_dict[command_key]['children'] command_key = input_dict.keys()[0] - + if not environment_dict['currentkeyname']: + raise seash_exceptions.UserError("Specify the key name by first typing 'as [username]'.") + # expand ~ fileandpath = os.path.expanduser(command_key) - + + if not os.access(fileandpath, os.W_OK): + raise seash_exceptions.UserError("Permission denied: " + fileandpath) try: seash_helper.savestate(fileandpath, environment_dict['handleinfo'], environment_dict['host'], environment_dict['port'], diff --git a/tests/ut_seash_savestate_nicermessageone.py b/tests/ut_seash_savestate_nicermessageone.py new file mode 100644 index 0000000..83d8ae8 --- /dev/null +++ b/tests/ut_seash_savestate_nicermessageone.py @@ -0,0 +1,20 @@ +""" +This unit test is to test error messages when using savestate before +having loaded at least a pubkey, and work as that identity. +""" + +import seash +import sys +import os +import seash_exceptions + +#pragma out Specify the key name by first typing 'as [username]'. + +command_list = [ + 'savestate NO_KEYS_LOADED', +] + +try: + seash.command_loop(command_list) +except seash_exceptions.UserError, e: + print str(e) diff --git a/tests/ut_seash_savestate_nicermessagetwo.py b/tests/ut_seash_savestate_nicermessagetwo.py new file mode 100644 index 0000000..66afad3 --- /dev/null +++ b/tests/ut_seash_savestate_nicermessagetwo.py @@ -0,0 +1,27 @@ +""" +This unit test is to test error messages when using savestate to +a write-protected file. +""" + +import seash +import sys +import os +import seash_exceptions + +#pragma out Permission denied: write_protected_file + +open('write_protected_file', 'w+').close() +os.chmod('write_protected_file', 0444) + +command_list = [ + 'loadkeys guest0', + 'as guest0', + 'savestate write_protected_file', +] + +try: + seash.command_loop(command_list) +except seash_exceptions.UserError, e: + print str(e) + +os.remove('write_protected_file')