def test_exec_ok(self): self.create_aws_server() server_pid = -1 try: self.connect_s3() self.connect_kms() self.create_credentials(keymap) port = find_open_port() server = Server( "s3://credentials/credentials.txt", port, region=region, kms_host="127.0.0.1", kms_port=self.aws.port, s3_host="127.0.0.1", s3_port=self.aws.port, s3_secure=False, kms_secure=False, aws_access_key_id=access_key, aws_secret_access_key=secret_key, ) server_runner = Thread(target=server.run) server_runner.start() try: # Send a request client = KDistConnection( host="127.0.0.1", port=port, is_secure=False, aws_access_key_id=access_key, aws_secret_access_key=secret_key, ) client.auth_region_name = region client.auth_service_name = "kdist" result = client.execute(command=["/bin/pwd"], directory="/") self.assertEqual(result["returncode"], 0) self.assertEqual(result["stdout"], "/\n") self.assertEqual(result["stderr"], "") result = client.execute(command=["/does/not/exist"], directory="/") self.assertEqual(result["returncode"], 127) finally: server.handler.server.shutdown() server_runner.join() finally: self.aws.stop() if server_pid != -1: kill(server_pid, SIGKILL)
def test_bad_params(self): self.create_aws_server() server_pid = -1 try: self.connect_s3() self.connect_kms() self.create_credentials(keymap) port = find_open_port() server = Server( "s3://credentials/credentials.txt", port, region=region, kms_host="127.0.0.1", kms_port=self.aws.port, s3_host="127.0.0.1", s3_port=self.aws.port, s3_secure=False, kms_secure=False, aws_access_key_id=access_key, aws_secret_access_key=secret_key, ) server_runner = Thread(target=server.run) server_runner.start() try: # Send a request client = KDistConnection( host="127.0.0.1", port=port, is_secure=False, aws_access_key_id=access_key, aws_secret_access_key=secret_key, ) client.auth_region_name = region client.auth_service_name = "kdist" for cmd in [[], "asdf", [{"x": "y"}]]: try: result = client.execute(command=cmd, directory="/") self.fail("Expected KDistServerError") except KDistServerError: pass for env in [["foo"], "", {"x": []}, {"": "x"}]: try: result = client.execute(command=["/bin/pwd"], directory="/", environment=env) self.fail("Expected KDistServerError: env=%r" % env) except KDistServerError: pass for user in [7, ["root"], "this-user-does-not-exist"]: try: result = client.execute(command=["/bin/pwd"], directory="/", user=user) self.fail("Expected KDistServerError") except KDistServerError: pass for dir in [7, ["/"], {"1": "2"}]: try: result = client.execute(command=["/bin/pwd"], directory=dir) self.fail("Expected KDistServerError") except KDistServerError: pass for stdin in [10, [], {"1": "2"}]: try: result = client.execute(command=["/bin/pwd"], directory="/", stdin=stdin) self.fail("Expected KDistServerError") except KDistServerError: pass finally: server.handler.server.shutdown() server_runner.join() finally: self.aws.stop() if server_pid != -1: kill(server_pid, SIGKILL)