def test_do_command_bye(self): """ Test executing the bye command. """ command = "bye" self.mox.ReplayAll() restricted_handler = RestrictedCommandHandler() self.assertEquals(u"terminating", restricted_handler.do_command(command))
def test_parse_body_command_in_set_args(self): """ Test for an allowed command with arguments. """ command = "foobar" args = "some command arguments" hlp = "command help" command_set = [(command, args, hlp)] response = "a response" self.mox.StubOutWithMock(RestrictedCommandHandler, "__init__") self.mox.StubOutWithMock(RestrictedCommandHandler, "do_command") self.mox.StubOutWithMock(configuration.commands, "restricted_set") RestrictedCommandHandler.__init__() configuration.commands.restricted_set().AndReturn(command_set) RestrictedCommandHandler.do_command(command, args).AndReturn(response) self.mox.ReplayAll() restricted_handler = RestrictedCommandHandler() self.assertEquals(response, restricted_handler.parse_body(command))
def test_do_command_no_args(self): """ Test executing a command without arguments. """ command = "ls" args = None method_args = [command] response = "foobar" self.mox.StubOutWithMock(RestrictedCommandHandler, "make_syscall") RestrictedCommandHandler.make_syscall(method_args).AndReturn(response) self.mox.ReplayAll() restricted_handler = RestrictedCommandHandler() self.assertEquals(response, restricted_handler.do_command(command, args))
def test_do_command_popen_raises(self): """ Ensure proper behavior when Popen raises an assertion upon command execution. """ command = "ls" args = "-al" method_args = [command] method_args.extend(args) self.mox.StubOutWithMock(RestrictedCommandHandler, "make_syscall") RestrictedCommandHandler.make_syscall(method_args).AndRaise( OSError(2, None, 'File not found')) self.mox.ReplayAll() restricted_handler = RestrictedCommandHandler() self.assertEqual(type(""), type(restricted_handler.do_command(command, args)))