From e448fc723b9456573464827560ea13a68507ac94 Mon Sep 17 00:00:00 2001 From: "Remi GASCOU (Podalirius)" <79218792+p0dalirius@users.noreply.github.com> Date: Wed, 10 Jul 2024 20:27:31 +0200 Subject: [PATCH] Created test cases --- smbclientng/core/CommandCompleter.py | 3 +- smbclientng/core/InteractiveShell.py | 9 ++- testing/core/Check.py | 62 ++++++++++++------- testing/core/utils.py | 2 +- testing/main.py | 18 ++++-- .../tests/commands/bat/bat_existing_file.json | 23 +++++++ .../bat/bat_insufficient_permissions.json | 22 +++++++ .../commands/bat/bat_no_file_specified.json | 22 +++++++ .../commands/bat/bat_non_existing_file.json | 22 +++++++ .../tests/commands/cat/cat_existing_file.json | 22 +++++++ .../cat/cat_insufficient_permissions.json | 22 +++++++ .../commands/cat/cat_no_file_specified.json | 22 +++++++ .../commands/cat/cat_non_existing_file.json | 22 +++++++ .../cd_a_non_existing_directory_in_cwd.json | 20 ++++++ .../cd/cd_an_existing_directory_in_cwd.json | 23 +++++++ .../cd/cd_deeply_nested_directory.json | 22 +++++++ .../cd/cd_no_directory_specified.json | 22 +++++++ .../close/close_after_operations.json | 26 ++++++++ .../close_already_closed_connection.json | 24 +++++++ .../close/close_followed_by_reconnect.json | 24 +++++++ .../close/close_no_active_connection.json | 16 +++++ .../commands/connect/connect_after_close.json | 24 +++++++ .../connect/connect_after_timeout.json | 24 +++++++ .../connect_incorrect_credentials.json | 21 +++++++ .../connect_non_responsive_server.json | 21 +++++++ .../connect/connect_smb_connection.json | 21 +++++++ .../dir/dir_current_working_directory.json | 25 ++++++++ .../commands/dir/dir_empty_directory.json | 24 +++++++ .../dir/dir_insufficient_permissions.json | 23 +++++++ .../dir/dir_non_existing_directory.json | 22 +++++++ .../find/find_by_name_case_insensitive.json | 22 +++++++ .../find/find_by_name_current_directory.json | 23 +++++++ .../find/find_by_name_specific_directory.json | 22 +++++++ testing/tests/commands/find/find_by_size.json | 22 +++++++ .../commands/find/find_by_type_directory.json | 23 +++++++ .../find/find_insufficient_permissions.json | 23 +++++++ .../find/find_non_existing_directory.json | 22 +++++++ .../get/get_directory_recursively.json | 22 +++++++ .../tests/commands/get/get_existing_file.json | 22 +++++++ .../get/get_insufficient_permissions.json | 22 +++++++ .../tests/commands/get/get_large_file.json | 22 +++++++ .../commands/get/get_no_file_specified.json | 22 +++++++ .../commands/get/get_non_existing_file.json | 22 +++++++ testing/tests/commands/help/help_general.json | 21 +++++++ .../help/help_non_existing_command.json | 21 +++++++ .../commands/help/help_specific_command.json | 21 +++++++ .../commands/info/info_invalid_parameter.json | 22 +++++++ .../commands/info/info_no_connection.json | 16 +++++ .../commands/info/info_no_parameter.json | 23 +++++++ testing/tests/commands/info/info_server.json | 21 +++++++ testing/tests/commands/info/info_share.json | 22 +++++++ .../tree_a_non_existing_directory_in_cwd.json | 20 ++++++ .../tree_an_existing_directory_in_cwd.json | 23 +++++++ .../tree/tree_deeply_nested_directory.json | 20 ++++++ testing/tests/setup.ps1 | 49 +++++++++++++++ 55 files changed, 1189 insertions(+), 32 deletions(-) create mode 100644 testing/tests/commands/bat/bat_existing_file.json create mode 100644 testing/tests/commands/bat/bat_insufficient_permissions.json create mode 100644 testing/tests/commands/bat/bat_no_file_specified.json create mode 100644 testing/tests/commands/bat/bat_non_existing_file.json create mode 100644 testing/tests/commands/cat/cat_existing_file.json create mode 100644 testing/tests/commands/cat/cat_insufficient_permissions.json create mode 100644 testing/tests/commands/cat/cat_no_file_specified.json create mode 100644 testing/tests/commands/cat/cat_non_existing_file.json create mode 100644 testing/tests/commands/cd/cd_a_non_existing_directory_in_cwd.json create mode 100644 testing/tests/commands/cd/cd_an_existing_directory_in_cwd.json create mode 100644 testing/tests/commands/cd/cd_deeply_nested_directory.json create mode 100644 testing/tests/commands/cd/cd_no_directory_specified.json create mode 100644 testing/tests/commands/close/close_after_operations.json create mode 100644 testing/tests/commands/close/close_already_closed_connection.json create mode 100644 testing/tests/commands/close/close_followed_by_reconnect.json create mode 100644 testing/tests/commands/close/close_no_active_connection.json create mode 100644 testing/tests/commands/connect/connect_after_close.json create mode 100644 testing/tests/commands/connect/connect_after_timeout.json create mode 100644 testing/tests/commands/connect/connect_incorrect_credentials.json create mode 100644 testing/tests/commands/connect/connect_non_responsive_server.json create mode 100644 testing/tests/commands/connect/connect_smb_connection.json create mode 100644 testing/tests/commands/dir/dir_current_working_directory.json create mode 100644 testing/tests/commands/dir/dir_empty_directory.json create mode 100644 testing/tests/commands/dir/dir_insufficient_permissions.json create mode 100644 testing/tests/commands/dir/dir_non_existing_directory.json create mode 100644 testing/tests/commands/find/find_by_name_case_insensitive.json create mode 100644 testing/tests/commands/find/find_by_name_current_directory.json create mode 100644 testing/tests/commands/find/find_by_name_specific_directory.json create mode 100644 testing/tests/commands/find/find_by_size.json create mode 100644 testing/tests/commands/find/find_by_type_directory.json create mode 100644 testing/tests/commands/find/find_insufficient_permissions.json create mode 100644 testing/tests/commands/find/find_non_existing_directory.json create mode 100644 testing/tests/commands/get/get_directory_recursively.json create mode 100644 testing/tests/commands/get/get_existing_file.json create mode 100644 testing/tests/commands/get/get_insufficient_permissions.json create mode 100644 testing/tests/commands/get/get_large_file.json create mode 100644 testing/tests/commands/get/get_no_file_specified.json create mode 100644 testing/tests/commands/get/get_non_existing_file.json create mode 100644 testing/tests/commands/help/help_general.json create mode 100644 testing/tests/commands/help/help_non_existing_command.json create mode 100644 testing/tests/commands/help/help_specific_command.json create mode 100644 testing/tests/commands/info/info_invalid_parameter.json create mode 100644 testing/tests/commands/info/info_no_connection.json create mode 100644 testing/tests/commands/info/info_no_parameter.json create mode 100644 testing/tests/commands/info/info_server.json create mode 100644 testing/tests/commands/info/info_share.json create mode 100644 testing/tests/commands/tree/tree_a_non_existing_directory_in_cwd.json create mode 100644 testing/tests/commands/tree/tree_an_existing_directory_in_cwd.json create mode 100644 testing/tests/commands/tree/tree_deeply_nested_directory.json create mode 100644 testing/tests/setup.ps1 diff --git a/smbclientng/core/CommandCompleter.py b/smbclientng/core/CommandCompleter.py index f068c90..3aa14d8 100644 --- a/smbclientng/core/CommandCompleter.py +++ b/smbclientng/core/CommandCompleter.py @@ -515,7 +515,8 @@ def print_help(self, command=None): if command is not None: if command not in list(self.commands.keys())+["format"]: - command = None + self.logger.error("Help for command '%s' does not exist." % command) + return # Print help for a specific command if command is not None: diff --git a/smbclientng/core/InteractiveShell.py b/smbclientng/core/InteractiveShell.py index 5840797..54a36dd 100644 --- a/smbclientng/core/InteractiveShell.py +++ b/smbclientng/core/InteractiveShell.py @@ -43,7 +43,7 @@ def wrapper(*args, **kwargs): if self.sessionsManager.current_session.connected: return func(*args, **kwargs) else: - print("[!] SMB Session is disconnected.") + self.logger.error("SMB Session is disconnected.") return None return wrapper @@ -53,7 +53,7 @@ def wrapper(*args, **kwargs): if self.sessionsManager.current_session.smb_share is not None: return func(*args, **kwargs) else: - print("[!] You must open a share first, try the 'use ' command.") + self.logger.error("You must open a share first, try the 'use ' command.") return None return wrapper @@ -459,6 +459,9 @@ def command_info(self, arguments, command): print_server_info = False print_share_info = False if len(arguments) != 0: + if arguments[0].lower() not in ["server", "share"]: + self.logger.error("'%s' is not a valid parameter. Use 'server' or 'share'." % arguments[0]) + return None print_server_info = (arguments[0].lower() == "server") print_share_info = (arguments[0].lower() == "share") else: @@ -471,7 +474,7 @@ def command_info(self, arguments, command): server=print_server_info ) except impacket.smbconnection.SessionError as e: - self.logger.error("[!] SMB Error: %s" % e) + self.logger.error("SMB Error: %s" % e) @command_arguments_required def command_lbat(self, arguments, command): diff --git a/testing/core/Check.py b/testing/core/Check.py index a60ea3d..6f480fc 100644 --- a/testing/core/Check.py +++ b/testing/core/Check.py @@ -20,31 +20,47 @@ def __init__(self, logger, options, test_case): def run(self): data = self.exec() - parsed = parseLogfileContents(data) - last_line = parsed[-1] - check_passed = True - for expectedMessage in self.test_case["expected_output"]["messages"]: - if expectedMessage not in ''.join(last_line["output"]): - check_passed = False - else: - self.logger.debug("'%s' is not present in output" % expectedMessage) - - # Error output is matching what is expected - if self.test_case["expected_output"]["error"] != last_line["error"]: - self.logger.debug("Error output is not matching what is expected.") - check_passed = False - - # Traceback output is matching what is expected - if self.test_case["expected_output"]["traceback"] != last_line["traceback"]: - self.logger.debug("Traceback output is not matching what is expected.") + if data is None: check_passed = False + return check_passed - # Final print of check - if check_passed: - self.__print_passed() else: - self.__print_failed() + parsed = parseLogfileContents(data) + + if len(parsed) != 0: + last_line = parsed[-1] + + check_passed = True + for expectedMessage in self.test_case["expected_output"]["messages"]: + if expectedMessage not in ''.join(last_line["output"]): + check_passed = False + else: + self.logger.debug("'%s' is not present in output" % expectedMessage) + + # Error output is matching what is expected + if self.test_case["expected_output"]["error"] != last_line["error"]: + self.logger.debug("Error output is not matching what is expected.") + self.logger.debug("=[Output]====================================") + self.logger.debug('\n'.join(last_line["output"])) + self.logger.debug("=============================================") + check_passed = False + + # Traceback output is matching what is expected + if self.test_case["expected_output"]["traceback"] != last_line["traceback"]: + self.logger.debug("Traceback output is not matching what is expected.") + self.logger.debug("=[Output]====================================") + self.logger.debug('\n'.join(last_line["output"])) + self.logger.debug("=============================================") + check_passed = False + + # Final print of check + if check_passed: + self.__print_passed() + return True + else: + self.__print_failed() + return False def exec(self): # Create scriptfile @@ -95,10 +111,10 @@ def exec(self): return None def __print_passed(self): - title = (self.test_case["title"]+" ").ljust(60,'─') + title = (self.test_case["title"]+" ").ljust(80,'─') self.logger.print("├───┼───┼── %s \x1b[1;48;2;83;170;51;97m PASSED \x1b[0m" % title) def __print_failed(self): - title = (self.test_case["title"]+" ").ljust(60,'─') + title = (self.test_case["title"]+" ").ljust(80,'─') self.logger.print("├───┼───┼── %s \x1b[1;48;2;233;61;3;97m FAILED \x1b[0m" % title) diff --git a/testing/core/utils.py b/testing/core/utils.py index 4b24478..4c8e20d 100644 --- a/testing/core/utils.py +++ b/testing/core/utils.py @@ -51,7 +51,7 @@ def parseLogfileContents(contents): parsed.append({ "command": command, "output": buffer, - "error": any(["[error]" in l.startswith() for l in buffer]), + "error": any([l.startswith("[error]") for l in buffer]), "traceback": any([l.startswith("Traceback") for l in buffer]), }) command = None diff --git a/testing/main.py b/testing/main.py index 0ff3718..07b7438 100644 --- a/testing/main.py +++ b/testing/main.py @@ -41,15 +41,25 @@ def parseArgs(): nb_testcases += len(testCases[category][subcategory].keys()) logger.info("Registered %d tests." % nb_testcases) + + tests_passed = 0 + tests_failed = 0 for category in sorted(testCases.keys()): - logger.print("\x1b[1;48;2;170;170;170;30m├──[+] Category: %-64s\x1b[0m" % category) + logger.print("\x1b[1;48;2;170;170;170;30m├──[+] Category: %-84s\x1b[0m" % category) for subcategory in sorted(testCases[category].keys()): - logger.print("\x1b[1;48;2;200;200;200;30m├───┼──[+] Subcategory: %-57s\x1b[0m" % subcategory) + logger.print("\x1b[1;48;2;200;200;200;30m├───┼──[+] Subcategory: %-77s\x1b[0m" % subcategory) for pathToTestCase, testCase in testCases[category][subcategory].items(): logger.debug("Testing: %s" % testCase["title"]) c = Check(logger=logger, options=options, test_case=testCase) - c.run() + + if c.run() == True: + tests_passed += 1 + else: + tests_failed += 1 - logger.info("Finished tests.") \ No newline at end of file + logger.print("\x1b[1;48;2;170;170;170;30m[+] %-96s \x1b[0m" % "All done!") + logger.info("Finished tests.") + logger.info("Tests PASSED: (%d/%d) %d%%" % (tests_passed, nb_testcases, (tests_passed / nb_testcases)*100)) + logger.info("Tests FAILED: (%d/%d) %d%%" % (tests_failed, nb_testcases, (tests_failed / nb_testcases)*100)) \ No newline at end of file diff --git a/testing/tests/commands/bat/bat_existing_file.json b/testing/tests/commands/bat/bat_existing_file.json new file mode 100644 index 0000000..9c8a68c --- /dev/null +++ b/testing/tests/commands/bat/bat_existing_file.json @@ -0,0 +1,23 @@ +{ + "title": "Command 'bat': of an existing remote file", + "category": "commands", + "subcategory": "bat", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "use 'C$'", + "bat './Users/John/Documents/file.txt'" + ], + "expected_output": { + "messages": [ + "Contents of './Users/John/Documents/file.txt':", + "This is a test file." + ], + "error": false, + "traceback": false + } +} \ No newline at end of file diff --git a/testing/tests/commands/bat/bat_insufficient_permissions.json b/testing/tests/commands/bat/bat_insufficient_permissions.json new file mode 100644 index 0000000..83240b0 --- /dev/null +++ b/testing/tests/commands/bat/bat_insufficient_permissions.json @@ -0,0 +1,22 @@ +{ + "title": "Command 'bat': of a remote file with insufficient permissions", + "category": "commands", + "subcategory": "bat", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "use 'C$'", + "bat './Windows/System32/protected_file.txt'" + ], + "expected_output": { + "messages": [ + "Error: Permission denied for './Windows/System32/protected_file.txt'." + ], + "error": true, + "traceback": false + } +} \ No newline at end of file diff --git a/testing/tests/commands/bat/bat_no_file_specified.json b/testing/tests/commands/bat/bat_no_file_specified.json new file mode 100644 index 0000000..0e074ba --- /dev/null +++ b/testing/tests/commands/bat/bat_no_file_specified.json @@ -0,0 +1,22 @@ +{ + "title": "Command 'bat': without specifying a file", + "category": "commands", + "subcategory": "bat", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "use 'C$'", + "bat" + ], + "expected_output": { + "messages": [ + "Error: No file specified." + ], + "error": true, + "traceback": false + } +} \ No newline at end of file diff --git a/testing/tests/commands/bat/bat_non_existing_file.json b/testing/tests/commands/bat/bat_non_existing_file.json new file mode 100644 index 0000000..ba99af2 --- /dev/null +++ b/testing/tests/commands/bat/bat_non_existing_file.json @@ -0,0 +1,22 @@ +{ + "title": "Command 'bat': of a non-existing remote file", + "category": "commands", + "subcategory": "bat", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "use 'C$'", + "bat './Users/John/Documents/non_existing_file.txt'" + ], + "expected_output": { + "messages": [ + "Error: File './Users/John/Documents/non_existing_file.txt' not found." + ], + "error": true, + "traceback": false + } +} \ No newline at end of file diff --git a/testing/tests/commands/cat/cat_existing_file.json b/testing/tests/commands/cat/cat_existing_file.json new file mode 100644 index 0000000..b5934ea --- /dev/null +++ b/testing/tests/commands/cat/cat_existing_file.json @@ -0,0 +1,22 @@ +{ + "title": "Command 'cat': of an existing remote file", + "category": "commands", + "subcategory": "cat", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "use 'C$'", + "cat './Users/John/Documents/file.txt'" + ], + "expected_output": { + "messages": [ + "This is a test file." + ], + "error": false, + "traceback": false + } +} \ No newline at end of file diff --git a/testing/tests/commands/cat/cat_insufficient_permissions.json b/testing/tests/commands/cat/cat_insufficient_permissions.json new file mode 100644 index 0000000..9155303 --- /dev/null +++ b/testing/tests/commands/cat/cat_insufficient_permissions.json @@ -0,0 +1,22 @@ +{ + "title": "Command 'cat': of a remote file with insufficient permissions", + "category": "commands", + "subcategory": "cat", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "use 'C$'", + "cat './Windows/System32/protected_file.txt'" + ], + "expected_output": { + "messages": [ + "Error: Permission denied for './Windows/System32/protected_file.txt'." + ], + "error": true, + "traceback": false + } +} \ No newline at end of file diff --git a/testing/tests/commands/cat/cat_no_file_specified.json b/testing/tests/commands/cat/cat_no_file_specified.json new file mode 100644 index 0000000..190ff4d --- /dev/null +++ b/testing/tests/commands/cat/cat_no_file_specified.json @@ -0,0 +1,22 @@ +{ + "title": "Command 'cat': without specifying a file", + "category": "commands", + "subcategory": "cat", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "use 'C$'", + "cat" + ], + "expected_output": { + "messages": [ + "Error: No file specified." + ], + "error": true, + "traceback": false + } +} \ No newline at end of file diff --git a/testing/tests/commands/cat/cat_non_existing_file.json b/testing/tests/commands/cat/cat_non_existing_file.json new file mode 100644 index 0000000..f2d67a3 --- /dev/null +++ b/testing/tests/commands/cat/cat_non_existing_file.json @@ -0,0 +1,22 @@ +{ + "title": "Command 'cat': attempts to get the contents of a non-existing remote file", + "category": "commands", + "subcategory": "cat", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "use 'C$'", + "cat './Users/John/Documents/non_existing_file.txt'" + ], + "expected_output": { + "messages": [ + "Error: File './Users/John/Documents/non_existing_file.txt' not found." + ], + "error": true, + "traceback": false + } +} \ No newline at end of file diff --git a/testing/tests/commands/cd/cd_a_non_existing_directory_in_cwd.json b/testing/tests/commands/cd/cd_a_non_existing_directory_in_cwd.json new file mode 100644 index 0000000..2cb718d --- /dev/null +++ b/testing/tests/commands/cd/cd_a_non_existing_directory_in_cwd.json @@ -0,0 +1,20 @@ +{ + "title": "Command 'cd': with a non-existing directory in CWD", + "category": "commands", + "subcategory": "cd", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "use 'C$'", + "cd './{random_string_8}/'" + ], + "expected_output": { + "messages": ["[error] Remote directory '", "' does not exist."], + "error": true, + "traceback": false + } +} diff --git a/testing/tests/commands/cd/cd_an_existing_directory_in_cwd.json b/testing/tests/commands/cd/cd_an_existing_directory_in_cwd.json new file mode 100644 index 0000000..da13189 --- /dev/null +++ b/testing/tests/commands/cd/cd_an_existing_directory_in_cwd.json @@ -0,0 +1,23 @@ +{ + "title": "Command 'cd': with an existing directory in CWD", + "category": "commands", + "subcategory": "cd", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "use 'C$'", + "cd './Users/'" + ], + "expected_output": { + "messages": [], + "error": false, + "traceback": false + } +} + + + diff --git a/testing/tests/commands/cd/cd_deeply_nested_directory.json b/testing/tests/commands/cd/cd_deeply_nested_directory.json new file mode 100644 index 0000000..0c9f76a --- /dev/null +++ b/testing/tests/commands/cd/cd_deeply_nested_directory.json @@ -0,0 +1,22 @@ +{ + "title": "Command 'cd': to a deeply nested directory", + "category": "commands", + "subcategory": "cd", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "use 'C$'", + "cd './Users/John/Documents/Projects/'" + ], + "expected_output": { + "messages": [ + "Changed directory to './Users/John/Documents/Projects/'" + ], + "error": false, + "traceback": false + } +} diff --git a/testing/tests/commands/cd/cd_no_directory_specified.json b/testing/tests/commands/cd/cd_no_directory_specified.json new file mode 100644 index 0000000..5b0dd4f --- /dev/null +++ b/testing/tests/commands/cd/cd_no_directory_specified.json @@ -0,0 +1,22 @@ +{ + "title": "Command 'cd': without specifying a directory", + "category": "commands", + "subcategory": "cd", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "use 'C$'", + "cd" + ], + "expected_output": { + "messages": [ + "Error: No directory specified." + ], + "error": true, + "traceback": false + } +} \ No newline at end of file diff --git a/testing/tests/commands/close/close_after_operations.json b/testing/tests/commands/close/close_after_operations.json new file mode 100644 index 0000000..9f8fbf6 --- /dev/null +++ b/testing/tests/commands/close/close_after_operations.json @@ -0,0 +1,26 @@ +{ + "title": "Command 'close': executed after performing some operations", + "category": "commands", + "subcategory": "close", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "use 'C$'", + "dir", + "cd './Users/'", + "close" + ], + "expected_output": { + "messages": [ + "Directory listing...", + "Changed directory to './Users/'", + "SMB connection closed." + ], + "error": false, + "traceback": false + } +} \ No newline at end of file diff --git a/testing/tests/commands/close/close_already_closed_connection.json b/testing/tests/commands/close/close_already_closed_connection.json new file mode 100644 index 0000000..66d583a --- /dev/null +++ b/testing/tests/commands/close/close_already_closed_connection.json @@ -0,0 +1,24 @@ +{ + "title": "Command 'close': closes an already closed SMB connection", + "category": "commands", + "subcategory": "close", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "use 'C$'", + "close", + "close" + ], + "expected_output": { + "messages": [ + "SMB connection closed.", + "Error: No active SMB connection to close." + ], + "error": true, + "traceback": false + } +} \ No newline at end of file diff --git a/testing/tests/commands/close/close_followed_by_reconnect.json b/testing/tests/commands/close/close_followed_by_reconnect.json new file mode 100644 index 0000000..55cbb5c --- /dev/null +++ b/testing/tests/commands/close/close_followed_by_reconnect.json @@ -0,0 +1,24 @@ +{ + "title": "Command 'close': followed by a reconnect", + "category": "commands", + "subcategory": "close", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "use 'C$'", + "close", + "reconnect" + ], + "expected_output": { + "messages": [ + "SMB connection closed.", + "Reconnected to the SMB server." + ], + "error": false, + "traceback": false + } +} \ No newline at end of file diff --git a/testing/tests/commands/close/close_no_active_connection.json b/testing/tests/commands/close/close_no_active_connection.json new file mode 100644 index 0000000..b889e22 --- /dev/null +++ b/testing/tests/commands/close/close_no_active_connection.json @@ -0,0 +1,16 @@ +{ + "title": "Command 'close': attempts to close SMB connection without an active connection", + "category": "commands", + "subcategory": "close", + "parameters": {}, + "smbclientng_commands": [ + "close" + ], + "expected_output": { + "messages": [ + "Error: No active SMB connection to close." + ], + "error": true, + "traceback": false + } +} \ No newline at end of file diff --git a/testing/tests/commands/connect/connect_after_close.json b/testing/tests/commands/connect/connect_after_close.json new file mode 100644 index 0000000..7b39087 --- /dev/null +++ b/testing/tests/commands/connect/connect_after_close.json @@ -0,0 +1,24 @@ +{ + "title": "Command 'connect': after closing a previous connection", + "category": "commands", + "subcategory": "connect", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "use 'C$'", + "close", + "connect" + ], + "expected_output": { + "messages": [ + "SMB connection closed.", + "Connected to the SMB server." + ], + "error": false, + "traceback": false + } +} \ No newline at end of file diff --git a/testing/tests/commands/connect/connect_after_timeout.json b/testing/tests/commands/connect/connect_after_timeout.json new file mode 100644 index 0000000..3dcbe03 --- /dev/null +++ b/testing/tests/commands/connect/connect_after_timeout.json @@ -0,0 +1,24 @@ +{ + "title": "Command 'connect': reconnects after a connection timeout", + "category": "commands", + "subcategory": "connect", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "use 'C$'", + "connect", + "dir" + ], + "expected_output": { + "messages": [ + "Connected to the SMB server.", + "Directory listing..." + ], + "error": false, + "traceback": false + } +} \ No newline at end of file diff --git a/testing/tests/commands/connect/connect_incorrect_credentials.json b/testing/tests/commands/connect/connect_incorrect_credentials.json new file mode 100644 index 0000000..63de186 --- /dev/null +++ b/testing/tests/commands/connect/connect_incorrect_credentials.json @@ -0,0 +1,21 @@ +{ + "title": "Command 'connect': with incorrect credentials", + "category": "commands", + "subcategory": "connect", + "parameters": { + "-d": "{random_string_8}", + "-u": "{random_string_8}", + "-p": "{random_string_8}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "connect" + ], + "expected_output": { + "messages": [ + "Error: Authentication failed." + ], + "error": true, + "traceback": false + } +} \ No newline at end of file diff --git a/testing/tests/commands/connect/connect_non_responsive_server.json b/testing/tests/commands/connect/connect_non_responsive_server.json new file mode 100644 index 0000000..7924bd3 --- /dev/null +++ b/testing/tests/commands/connect/connect_non_responsive_server.json @@ -0,0 +1,21 @@ +{ + "title": "Command 'connect': to a non-responsive server", + "category": "commands", + "subcategory": "connect", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{random_string_8}" + }, + "smbclientng_commands": [ + "connect" + ], + "expected_output": { + "messages": [ + "Error: Unable to connect to the SMB server." + ], + "error": true, + "traceback": false + } +} \ No newline at end of file diff --git a/testing/tests/commands/connect/connect_smb_connection.json b/testing/tests/commands/connect/connect_smb_connection.json new file mode 100644 index 0000000..d0150b4 --- /dev/null +++ b/testing/tests/commands/connect/connect_smb_connection.json @@ -0,0 +1,21 @@ +{ + "title": "Command 'connect': establishes an SMB connection", + "category": "commands", + "subcategory": "connect", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "connect" + ], + "expected_output": { + "messages": [ + "Connected to the SMB server." + ], + "error": false, + "traceback": false + } +} \ No newline at end of file diff --git a/testing/tests/commands/dir/dir_current_working_directory.json b/testing/tests/commands/dir/dir_current_working_directory.json new file mode 100644 index 0000000..2d9904e --- /dev/null +++ b/testing/tests/commands/dir/dir_current_working_directory.json @@ -0,0 +1,25 @@ +{ + "title": "Command 'dir': of the current working directory", + "category": "commands", + "subcategory": "dir", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "use 'C$'", + "dir" + ], + "expected_output": { + "messages": [ + "Listing directory contents...", + "file1.txt", + "file2.txt", + "folder1/" + ], + "error": false, + "traceback": false + } +} \ No newline at end of file diff --git a/testing/tests/commands/dir/dir_empty_directory.json b/testing/tests/commands/dir/dir_empty_directory.json new file mode 100644 index 0000000..eab0be4 --- /dev/null +++ b/testing/tests/commands/dir/dir_empty_directory.json @@ -0,0 +1,24 @@ +{ + "title": "Command 'dir': of an empty directory", + "category": "commands", + "subcategory": "dir", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "use 'C$'", + "cd './empty_folder'", + "dir" + ], + "expected_output": { + "messages": [ + "Listing directory contents...", + "No files or directories found." + ], + "error": false, + "traceback": false + } +} \ No newline at end of file diff --git a/testing/tests/commands/dir/dir_insufficient_permissions.json b/testing/tests/commands/dir/dir_insufficient_permissions.json new file mode 100644 index 0000000..d99495a --- /dev/null +++ b/testing/tests/commands/dir/dir_insufficient_permissions.json @@ -0,0 +1,23 @@ +{ + "title": "Command 'dir': of a directory with insufficient permissions", + "category": "commands", + "subcategory": "dir", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "use 'C$'", + "cd './restricted_folder'", + "dir" + ], + "expected_output": { + "messages": [ + "Error: Permission denied." + ], + "error": true, + "traceback": false + } +} diff --git a/testing/tests/commands/dir/dir_non_existing_directory.json b/testing/tests/commands/dir/dir_non_existing_directory.json new file mode 100644 index 0000000..16c27da --- /dev/null +++ b/testing/tests/commands/dir/dir_non_existing_directory.json @@ -0,0 +1,22 @@ +{ + "title": "Command 'dir': of a non-existing directory", + "category": "commands", + "subcategory": "dir", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "use 'C$'", + "dir './non_existing_directory'" + ], + "expected_output": { + "messages": [ + "Error: Directory not found." + ], + "error": true, + "traceback": false + } +} diff --git a/testing/tests/commands/find/find_by_name_case_insensitive.json b/testing/tests/commands/find/find_by_name_case_insensitive.json new file mode 100644 index 0000000..c3cd275 --- /dev/null +++ b/testing/tests/commands/find/find_by_name_case_insensitive.json @@ -0,0 +1,22 @@ +{ + "title": "Command 'find': search for files by name case-insensitively", + "category": "commands", + "subcategory": "find", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "use 'C$'", + "find -iname 'Report.docx' './Users/Administrator'" + ], + "expected_output": { + "messages": [ + "./Users/John/Documents/report.docx" + ], + "error": false, + "traceback": false + } +} diff --git a/testing/tests/commands/find/find_by_name_current_directory.json b/testing/tests/commands/find/find_by_name_current_directory.json new file mode 100644 index 0000000..3e3a258 --- /dev/null +++ b/testing/tests/commands/find/find_by_name_current_directory.json @@ -0,0 +1,23 @@ +{ + "title": "Command 'find': search for files by name in the current directory", + "category": "commands", + "subcategory": "find", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "use 'C$'", + "cd Users/Administrator", + "find -name 'file.txt' ./" + ], + "expected_output": { + "messages": [ + "./file.txt" + ], + "error": false, + "traceback": false + } +} diff --git a/testing/tests/commands/find/find_by_name_specific_directory.json b/testing/tests/commands/find/find_by_name_specific_directory.json new file mode 100644 index 0000000..05d041c --- /dev/null +++ b/testing/tests/commands/find/find_by_name_specific_directory.json @@ -0,0 +1,22 @@ +{ + "title": "Command 'find': search for files by name in a specific directory", + "category": "commands", + "subcategory": "find", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "use 'C$'", + "find -name 'document.pdf' './Users/Administrator'" + ], + "expected_output": { + "messages": [ + "./Users/John/Documents/document.pdf" + ], + "error": false, + "traceback": false + } +} diff --git a/testing/tests/commands/find/find_by_size.json b/testing/tests/commands/find/find_by_size.json new file mode 100644 index 0000000..401b753 --- /dev/null +++ b/testing/tests/commands/find/find_by_size.json @@ -0,0 +1,22 @@ +{ + "title": "Command 'find': search for files by size", + "category": "commands", + "subcategory": "find", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "use 'C$'", + "find -size +100M './Users/Administrator/'" + ], + "expected_output": { + "messages": [ + "./Users/John/Videos/movie.mp4" + ], + "error": false, + "traceback": false + } +} diff --git a/testing/tests/commands/find/find_by_type_directory.json b/testing/tests/commands/find/find_by_type_directory.json new file mode 100644 index 0000000..c925e1e --- /dev/null +++ b/testing/tests/commands/find/find_by_type_directory.json @@ -0,0 +1,23 @@ +{ + "title": "Command 'find': search for directories", + "category": "commands", + "subcategory": "find", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "use 'C$'", + "find -type d './Users/Administrator'" + ], + "expected_output": { + "messages": [ + "./Users/John/Documents", + "./Users/John/Pictures" + ], + "error": false, + "traceback": false + } +} diff --git a/testing/tests/commands/find/find_insufficient_permissions.json b/testing/tests/commands/find/find_insufficient_permissions.json new file mode 100644 index 0000000..6627e0c --- /dev/null +++ b/testing/tests/commands/find/find_insufficient_permissions.json @@ -0,0 +1,23 @@ +{ + "title": "Command 'find': search with insufficient permissions", + "category": "commands", + "subcategory": "find", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "use 'C$'", + "cd Users/Administrator", + "find -name 'file.txt' './restricted_folder'" + ], + "expected_output": { + "messages": [ + "Error: Permission denied for './restricted_folder'." + ], + "error": true, + "traceback": false + } +} diff --git a/testing/tests/commands/find/find_non_existing_directory.json b/testing/tests/commands/find/find_non_existing_directory.json new file mode 100644 index 0000000..0d041b1 --- /dev/null +++ b/testing/tests/commands/find/find_non_existing_directory.json @@ -0,0 +1,22 @@ +{ + "title": "Command 'find': search in a non-existing directory", + "category": "commands", + "subcategory": "find", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "use 'C$'", + "find -name 'file.txt' './non_existing_directory'" + ], + "expected_output": { + "messages": [ + "Error: Directory './non_existing_directory' not found." + ], + "error": true, + "traceback": false + } +} diff --git a/testing/tests/commands/get/get_directory_recursively.json b/testing/tests/commands/get/get_directory_recursively.json new file mode 100644 index 0000000..73dc9b0 --- /dev/null +++ b/testing/tests/commands/get/get_directory_recursively.json @@ -0,0 +1,22 @@ +{ + "title": "Command 'get': retrieves a remote directory recursively", + "category": "commands", + "subcategory": "get", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "use 'C$'", + "get -r './Users/John/Documents/projects/'" + ], + "expected_output": { + "messages": [ + "Directory './Users/John/Documents/projects/' downloaded successfully." + ], + "error": false, + "traceback": false + } +} diff --git a/testing/tests/commands/get/get_existing_file.json b/testing/tests/commands/get/get_existing_file.json new file mode 100644 index 0000000..1180cd4 --- /dev/null +++ b/testing/tests/commands/get/get_existing_file.json @@ -0,0 +1,22 @@ +{ + "title": "Command 'get': retrieves an existing remote file", + "category": "commands", + "subcategory": "get", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "use 'C$'", + "get './Users/John/Documents/file.txt'" + ], + "expected_output": { + "messages": [ + "File './Users/John/Documents/file.txt' downloaded successfully." + ], + "error": false, + "traceback": false + } +} diff --git a/testing/tests/commands/get/get_insufficient_permissions.json b/testing/tests/commands/get/get_insufficient_permissions.json new file mode 100644 index 0000000..c8c7656 --- /dev/null +++ b/testing/tests/commands/get/get_insufficient_permissions.json @@ -0,0 +1,22 @@ +{ + "title": "Command 'get': retrieves a remote file with insufficient permissions", + "category": "commands", + "subcategory": "get", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "use 'C$'", + "get './Windows/System32/protected_file.txt'" + ], + "expected_output": { + "messages": [ + "Error: Permission denied for './Windows/System32/protected_file.txt'." + ], + "error": true, + "traceback": false + } +} diff --git a/testing/tests/commands/get/get_large_file.json b/testing/tests/commands/get/get_large_file.json new file mode 100644 index 0000000..f97bfb5 --- /dev/null +++ b/testing/tests/commands/get/get_large_file.json @@ -0,0 +1,22 @@ +{ + "title": "Command 'get': retrieves a large remote file", + "category": "commands", + "subcategory": "get", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "use 'C$'", + "get './Users/John/Documents/large_file.zip'" + ], + "expected_output": { + "messages": [ + "File './Users/John/Documents/large_file.zip' downloaded successfully." + ], + "error": false, + "traceback": false + } +} diff --git a/testing/tests/commands/get/get_no_file_specified.json b/testing/tests/commands/get/get_no_file_specified.json new file mode 100644 index 0000000..b02d517 --- /dev/null +++ b/testing/tests/commands/get/get_no_file_specified.json @@ -0,0 +1,22 @@ +{ + "title": "Command 'get': without specifying a file", + "category": "commands", + "subcategory": "get", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "use 'C$'", + "get" + ], + "expected_output": { + "messages": [ + "Error: No file specified." + ], + "error": true, + "traceback": false + } +} diff --git a/testing/tests/commands/get/get_non_existing_file.json b/testing/tests/commands/get/get_non_existing_file.json new file mode 100644 index 0000000..2311682 --- /dev/null +++ b/testing/tests/commands/get/get_non_existing_file.json @@ -0,0 +1,22 @@ +{ + "title": "Command 'get': attempts to retrieve a non-existing remote file", + "category": "commands", + "subcategory": "get", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "use 'C$'", + "get './Users/John/Documents/non_existing_file.txt'" + ], + "expected_output": { + "messages": [ + "Error: File './Users/John/Documents/non_existing_file.txt' not found." + ], + "error": true, + "traceback": false + } +} diff --git a/testing/tests/commands/help/help_general.json b/testing/tests/commands/help/help_general.json new file mode 100644 index 0000000..444b85c --- /dev/null +++ b/testing/tests/commands/help/help_general.json @@ -0,0 +1,21 @@ +{ + "title": "Command 'help': displays general help message", + "category": "commands", + "subcategory": "help", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "help" + ], + "expected_output": { + "messages": [ + "Pretty prints the contents of a remote file." + ], + "error": false, + "traceback": false + } +} diff --git a/testing/tests/commands/help/help_non_existing_command.json b/testing/tests/commands/help/help_non_existing_command.json new file mode 100644 index 0000000..00c01b1 --- /dev/null +++ b/testing/tests/commands/help/help_non_existing_command.json @@ -0,0 +1,21 @@ +{ + "title": "Command 'help': requests help for a non-existing command", + "category": "commands", + "subcategory": "help", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "help nonexistingcommand" + ], + "expected_output": { + "messages": [ + "[error] Help for command 'nonexistingcommand' does not exist." + ], + "error": true, + "traceback": false + } +} diff --git a/testing/tests/commands/help/help_specific_command.json b/testing/tests/commands/help/help_specific_command.json new file mode 100644 index 0000000..ddf9958 --- /dev/null +++ b/testing/tests/commands/help/help_specific_command.json @@ -0,0 +1,21 @@ +{ + "title": "Command 'help': displays help message for 'get' command", + "category": "commands", + "subcategory": "help", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "help get" + ], + "expected_output": { + "messages": [ + "Get a remote file." + ], + "error": false, + "traceback": false + } +} diff --git a/testing/tests/commands/info/info_invalid_parameter.json b/testing/tests/commands/info/info_invalid_parameter.json new file mode 100644 index 0000000..6cca1a1 --- /dev/null +++ b/testing/tests/commands/info/info_invalid_parameter.json @@ -0,0 +1,22 @@ +{ + "title": "Command 'info': with an invalid parameter", + "category": "commands", + "subcategory": "info", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "use 'C$'", + "info invalid" + ], + "expected_output": { + "messages": [ + "[error] 'invalid' is not a valid parameter. Use 'server' or 'share'." + ], + "error": true, + "traceback": false + } +} diff --git a/testing/tests/commands/info/info_no_connection.json b/testing/tests/commands/info/info_no_connection.json new file mode 100644 index 0000000..a17a735 --- /dev/null +++ b/testing/tests/commands/info/info_no_connection.json @@ -0,0 +1,16 @@ +{ + "title": "Command 'info': with correct parameters but connection not established", + "category": "commands", + "subcategory": "info", + "parameters": {}, + "smbclientng_commands": [ + "info" + ], + "expected_output": { + "messages": [ + "[error] SMB Session is disconnected." + ], + "error": true, + "traceback": false + } +} diff --git a/testing/tests/commands/info/info_no_parameter.json b/testing/tests/commands/info/info_no_parameter.json new file mode 100644 index 0000000..264da8e --- /dev/null +++ b/testing/tests/commands/info/info_no_parameter.json @@ -0,0 +1,23 @@ +{ + "title": "Command 'info': without specifying a parameter", + "category": "commands", + "subcategory": "info", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "use 'C$'", + "info" + ], + "expected_output": { + "messages": [ + "[+] Server:", + "[+] Share:" + ], + "error": false, + "traceback": false + } +} diff --git a/testing/tests/commands/info/info_server.json b/testing/tests/commands/info/info_server.json new file mode 100644 index 0000000..9f15cff --- /dev/null +++ b/testing/tests/commands/info/info_server.json @@ -0,0 +1,21 @@ +{ + "title": "Command 'info': get information about the server", + "category": "commands", + "subcategory": "info", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "info server" + ], + "expected_output": { + "messages": [ + "[+] Server:" + ], + "error": false, + "traceback": false + } +} diff --git a/testing/tests/commands/info/info_share.json b/testing/tests/commands/info/info_share.json new file mode 100644 index 0000000..959fe5c --- /dev/null +++ b/testing/tests/commands/info/info_share.json @@ -0,0 +1,22 @@ +{ + "title": "Command 'info': get information about the share", + "category": "commands", + "subcategory": "info", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "use 'C$'", + "info share" + ], + "expected_output": { + "messages": [ + "[+] Share:" + ], + "error": false, + "traceback": false + } +} diff --git a/testing/tests/commands/tree/tree_a_non_existing_directory_in_cwd.json b/testing/tests/commands/tree/tree_a_non_existing_directory_in_cwd.json new file mode 100644 index 0000000..254631a --- /dev/null +++ b/testing/tests/commands/tree/tree_a_non_existing_directory_in_cwd.json @@ -0,0 +1,20 @@ +{ + "title": "Command 'tree': with a non-existing directory in CWD", + "category": "commands", + "subcategory": "tree", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "use 'C$'", + "tree './{random_string_8}/'" + ], + "expected_output": { + "messages": [], + "error": false, + "traceback": false + } +} diff --git a/testing/tests/commands/tree/tree_an_existing_directory_in_cwd.json b/testing/tests/commands/tree/tree_an_existing_directory_in_cwd.json new file mode 100644 index 0000000..d640076 --- /dev/null +++ b/testing/tests/commands/tree/tree_an_existing_directory_in_cwd.json @@ -0,0 +1,23 @@ +{ + "title": "Command 'tree': with an existing directory in CWD", + "category": "commands", + "subcategory": "tree", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "use 'C$'", + "tree './Users/'" + ], + "expected_output": { + "messages": [], + "error": false, + "traceback": false + } +} + + + diff --git a/testing/tests/commands/tree/tree_deeply_nested_directory.json b/testing/tests/commands/tree/tree_deeply_nested_directory.json new file mode 100644 index 0000000..7a059eb --- /dev/null +++ b/testing/tests/commands/tree/tree_deeply_nested_directory.json @@ -0,0 +1,20 @@ +{ + "title": "Command 'tree': with a deeply nested directory", + "category": "commands", + "subcategory": "tree", + "parameters": { + "-d": "{auth_domain}", + "-u": "{auth_username}", + "-p": "{auth_password}", + "--host": "{target_host}" + }, + "smbclientng_commands": [ + "use 'C$'", + "tree './Users/Administrator/'" + ], + "expected_output": { + "messages": [], + "error": false, + "traceback": false + } +} \ No newline at end of file diff --git a/testing/tests/setup.ps1 b/testing/tests/setup.ps1 new file mode 100644 index 0000000..1085002 --- /dev/null +++ b/testing/tests/setup.ps1 @@ -0,0 +1,49 @@ +# Function to create a file with specified content +function Create-File { + param ( + [string]$Path, + [string]$Content + ) + New-Item -ItemType File -Path $Path -Force + Set-Content -Path $Path -Value $Content +} + +# Function to create a directory +function Create-Directory { + param ( + [string]$Path + ) + New-Item -ItemType Directory -Path $Path -Force +} + +$baseDir = "C:\TestShare\" + +# Create directories and files for testing + +# Create base share directory +New-PSDrive -Name "TestShare" -PSProvider FileSystem -Root $baseDir -Persist + +# Create a directory structure +Create-Directory -Path "$baseDir\Users\John\Documents" +Create-Directory -Path "$baseDir\Users\John\Documents\Projects" +Create-Directory -Path "$baseDir\Users\John\Documents\Projects\Project1" +Create-Directory -Path "$baseDir\Users\John\Documents\Projects\Project2" +Create-Directory -Path "$baseDir\Users\John\Pictures" +Create-Directory -Path "$baseDir\empty_folder" +Create-Directory -Path "$baseDir\restricted_folder" + +# Create files with different use cases +Create-File -Path "$baseDir\Users\John\Documents\file.txt" -Content "This is a test file." +Create-File -Path "$baseDir\Users\John\Documents\large_file.raw" -Content ("a" * 1000000) # Large file +Create-File -Path "$baseDir\Users\John\Documents\Projects\Project1\project_file1.txt" -Content "Project1 File" +Create-File -Path "$baseDir\Users\John\Documents\Projects\Project2\project_file2.txt" -Content "Project2 File" +Create-File -Path "$baseDir\Users\John\Pictures\image.jpg" -Content "FakeImageContent" +Create-File -Path "$baseDir\Users\John\Documents\document.pdf" -Content "PDF content" +Create-File -Path "$baseDir\Users\John\Documents\report.docx" -Content "Report content" + +# Create files in restricted folder +Create-File -Path "$baseDir\restricted_folder\protected_file.txt" -Content "Protected content" + +# Set restricted folder permissions +$restrictedFolderPath = "$remotePath\restricted_folder" +icacls $restrictedFolderPath /deny "Everyone:(OI)(CI)(F)"