def test_help_command(self): test_client, test_server = setup_test_sockets(8023) plugin_test = TelnetPlugin(test_server, setup_test_config(8023, 'telnet', 'TelnetPlugin'), None) test_client.send(b'help\r\n') plugin_test.command() self.assertEqual(test_client.recv(2), b'. ') help = test_client.recv(1024).decode() self.assertEqual("options:\t" in help, True) self.assertEqual("options:\t\t" in help, False) self.assertEqual("help:" in help, True) self.assertEqual("echo:" in help, True) self.assertEqual("quit:" in help, True) self.assertEqual("__init__:" in help, False) self.assertEqual("basic list of options available to user" in help, True) self.assertEqual("detailed description of options" in help, True) self.assertEqual("prompt to echo back typing" in help, True) self.assertEqual("close telnet connection to server" in help, True) self.assertEqual(plugin_test.get_entry(), {'test': {'input_type': 'command', 'user_input': 'help'}}) test_server.close() test_client.close()
def test_echo_no_arguments(self): test_client, test_server = setup_test_sockets(8023) plugin_test = TelnetPlugin(test_server, setup_test_config(8023, 'telnet', 'TelnetPlugin'), None) test_client.send(b'echo\r\n') test_client.send(b'test test\r\n') plugin_test.command() self.assertEqual(plugin_test.get_entry(), {'test': {'input_type': 'echo', 'user_input': 'test test'}}) test_server.close() test_client.close()
def test_locked_command(self): test_client, test_server = setup_test_sockets(8023) plugin_test = TelnetPlugin(test_server, setup_test_config(8023, 'telnet', 'TelnetPlugin'), None) test_client.send(b'__class__\r\n') plugin_test.command() self.assertEqual(test_client.recv(2), b'. ') self.assertEqual(test_client.recv(1024), b'%unrecognized command - type options for a list\r\n') self.assertEqual(plugin_test.get_entry(), {'test': {'input_type': 'command', 'user_input': '__class__'}}) test_server.close() test_client.close()
def test_quit_command(self): test_client, test_server = setup_test_sockets(8023) plugin_test = TelnetPlugin(test_server, setup_test_config(8023, 'telnet', 'TelnetPlugin'), None) test_client.send(b'quit\r\n') plugin_test.command() self.assertEqual(test_client.recv(2), b'. ') self.assertEqual(test_client.recv(1024), b'\nGoodbye\n') self.assertEqual(plugin_test.get_entry(), {'test': {'input_type': 'command', 'user_input': 'quit'}}) test_server.close() test_client.close()
def test_options_command(self): test_client, test_server = setup_test_sockets(8023) plugin_test = TelnetPlugin(test_server, setup_test_config(8023, 'telnet', 'TelnetPlugin'), None) test_client.send(b'options\r\n') plugin_test.command() self.assertEqual(test_client.recv(2), b'. ') options = test_client.recv(1024).decode() self.assertEqual("options\t\t" in options, True) self.assertEqual("help\t\t" in options, True) self.assertEqual("echo\t\t" in options, True) self.assertEqual("quit\t\t" in options, True) self.assertEqual("__init__\t\t" in options, False) self.assertEqual(plugin_test.get_entry(), {'test': {'input_type': 'command', 'user_input': 'options'}}) test_server.close() test_client.close()