def test_run_plugin_post_echo_x_forwarded_path_reverse_proxy_rewrite(): s = "pds" try: apc = echo_pc plugin_config.add_plugin_configs([apc]) plugin.run_container(apc) container_name = apc["name"] time.sleep(CLIENT_DELAY) reverse_proxy_rewrite = "reverse_proxy_path" resp = requests.post(f"{base_url}/plugin/{container_name}/index.json", headers={"Content-Type": "application/json", "X-Forwarded-Path": reverse_proxy_rewrite}, json=s) assert resp.status_code == 200 assert resp.json()["data"] == json.dumps(s) assert resp.json()["method"] == "POST" assert "X-Forwarded-Path" in resp.json()["headers"] assert resp.json()["headers"]["X-Forwarded-Path"] == f"{reverse_proxy_rewrite}/v1/plugin/{container_name}" finally: plugin.stop_container(apc) plugin.remove_container(apc) plugin_config.delete_plugin_configs({})
def test_run_container_get_echo_404(): try: apc = echo_pc plugin.run_container(apc) container_name = apc["name"] time.sleep(CLIENT_DELAY) resp = requests.get("http://{host}/?status=404".format(host=container_name)) assert resp.status_code == 404 finally: plugin.stop_container(apc) plugin.remove_container(apc)
def test_run_container_environment_post_echo(): s = "pds" try: apc = echo_pc2 plugin.run_container(apc) container_name = apc["name"] time.sleep(CLIENT_DELAY) resp = requests.post("http://{host}/".format(host=container_name), headers={"Content-Type": "application/json"}, json=s) assert resp.status_code == 200 assert resp.json()["data"] == json.dumps(s) assert resp.json()["method"] == "POST" finally: plugin.stop_container(apc) plugin.remove_container(apc)
def test_run_container_post_echo_404(): s = "pds" try: apc = echo_pc plugin.run_container(apc) container_name = apc["name"] time.sleep(CLIENT_DELAY) resp = requests.post("http://{host}/?status=404".format(host=container_name), headers={"Content-Type": "application/json"}, json=s) assert resp.status_code == 404 finally: plugin.stop_container(apc) plugin.remove_container(apc)
def test_run_container_get_echo(): try: apc = echo_pc plugin.run_container(apc) container_name = apc["name"] time.sleep(CLIENT_DELAY) resp = requests.get(f"http://{container_name}/") assert resp.status_code == 200 assert resp.json()["method"] == "GET" finally: plugin.stop_container(apc) plugin.remove_container(apc)
def test_run_plugin_container_get_echo_405(): try: apc = echo_pc plugin_config.add_plugin_configs([apc]) container_name = apc["name"] ps = plugin_config.get_plugin_configs({"name": container_name}) assert len(ps) == 1 apc = ps[0] plugin.run_container(apc) time.sleep(CLIENT_DELAY) resp = requests.get(f"{base_url}/plugin/{container_name}/index.json?status=405") assert resp.status_code == 405 finally: api.delete_containers() plugin_config.delete_plugin_configs({})
def test_run_plugin_container_post_echo_405(): s = "pds" try: apc = echo_pc plugin_config.add_plugin_configs([apc]) container_name = apc["name"] ps = plugin_config.get_plugin_configs({"name": container_name}) assert len(ps) == 1 apc = ps[0] plugin.run_container(apc) time.sleep(CLIENT_DELAY) resp = requests.post(f"{base_url}/plugin/{container_name}/index.json?status=405", headers={"Content-Type": "application/json"}, json=s) assert resp.status_code == 405 finally: api.delete_containers() plugin_config.delete_plugin_configs({})
def test_run_container_get(): with tempfile.TemporaryDirectory(prefix="/tmp/") as temp_dir_name: os.chmod(temp_dir_name, 0o755) s = "pds" with open(os.path.join(temp_dir_name, "index.json"), "w+") as f: f.write(json.dumps(s)) try: apc = pc(temp_dir_name) plugin.run_container(apc) container_name = apc["name"] resp = requests.get("http://{host}/index.json".format(host=container_name)) assert resp.status_code == 200 assert resp.json() == s finally: plugin.stop_container(apc) plugin.remove_container(apc)
def test_run_plugin_get_echo_x_forwarded_path(): try: apc = echo_pc plugin_config.add_plugin_configs([apc]) plugin.run_container(apc) container_name = apc["name"] time.sleep(CLIENT_DELAY) resp = requests.get(f"{base_url}/plugin/{container_name}/index.json") assert resp.status_code == 200 assert resp.json()["method"] == "GET" assert "X-Forwarded-Path" in resp.json()["headers"] assert resp.json()["headers"]["X-Forwarded-Path"] == f"/v1/plugin/{container_name}" finally: plugin.stop_container(apc) plugin.remove_container(apc) plugin_config.delete_plugin_configs({})
def test_run_plugin_container(): with tempfile.TemporaryDirectory(prefix="/tmp/") as temp_dir_name: os.chmod(temp_dir_name, 0o755) s = "pds" with open(os.path.join(temp_dir_name, "index.json"), "w+") as f: f.write(json.dumps(s)) try: apc = pc(temp_dir_name) plugin_config.add_plugin_configs([apc]) ps = plugin_config.get_plugin_configs({"name": name}) assert len(ps) == 1 apc = ps[0] plugin.run_container(apc) resp = requests.get(f"{base_url}/plugin/{name}/index.json") assert resp.status_code == 200 assert resp.json() == s finally: api.delete_containers() plugin_config.delete_plugin_configs({})
def test_run_container_get_relative_path(): host_cwd_mount = os.environ["HOST_CWD_MOUNT"] with tempfile.TemporaryDirectory(prefix=os.path.join(host_cwd_mount, "")) as temp_dir_name: _, basename = os.path.split(temp_dir_name) os.chmod(temp_dir_name, 0o755) s = "pds" with open(os.path.join(temp_dir_name, "index.json"), "w+") as f: f.write(json.dumps(s)) try: apc = pc(f"./{basename}") plugin.run_container(apc) container_name = apc["name"] resp = requests.get("http://{host}/index.json".format(host=container_name)) assert resp.status_code == 200 assert resp.json() == s finally: plugin.stop_container(apc) plugin.remove_container(apc)
def add_containers(): for pc in plugin_config.get_plugin_configs({}): plugin.run_container(pc)
def add_plugin_container(name): pc = plugin_config.get_plugin_config(name) plugin.run_container(pc)