Fix contrib/mitm-ui by serving test components

With this fix in place the script mitm-serve-app-dev.sh works
as advertised. It proxies the https prod server and even allows
login. It is fairly slow though compared to run-server.sh, so
it cannot fully replace it at this point.

Note that there is also a WIP Change I0ff7e314a for getting us
from mitmproxy 2.0.2 to 4.0.4.

Change-Id: Id79510228d6e701f724cc947146768fabae58457
This commit is contained in:
brohlfs
2019-03-22 12:27:33 +01:00
parent 027551fb11
commit 618c4fe470
4 changed files with 26 additions and 7 deletions

View File

@@ -8,7 +8,10 @@
cd ~/gerrit
~/mitm-gerrit/mitm-serve-app-dev.sh
```
3. Install MITM certificates
3. Make sure that the browser uses the proxy provided by the command line,
e.g. if you are a Googler check that the BeyondCorp extension uses the
"System/Alternative" proxy.
4. Install MITM certificates
- Open http://mitm.it in the proxied browser window
- Follow the instructions to install MITM certs

View File

@@ -36,6 +36,7 @@ docker run --rm -it \
-v ~/.mitmproxy:/home/mitmproxy/.mitmproxy \
-v ${mitm_dir}:${mitm_dir} \
-v ${gerrit_dir}:${gerrit_dir} \
-v ${gerrit_dir}/bazel-out:${gerrit_dir}/bazel-out \
-v ${extra_volume} \
-p 8888:8888 \
mitmproxy/mitmproxy:2.0.2 \

View File

@@ -8,6 +8,8 @@ fi
mitm_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
bazel build //polygerrit-ui/app:test_components &
${mitm_dir}/dev-chrome.sh &
${mitm_dir}/mitm-docker.sh "serve-app-dev.py --app $(pwd)/polygerrit-ui/app/"
${mitm_dir}/mitm-docker.sh "serve-app-dev.py --app $(pwd)/polygerrit-ui/app/ --components $(pwd)/bazel-bin/polygerrit-ui/app/"

View File

@@ -28,16 +28,19 @@
from mitmproxy import http
from mitmproxy.script import concurrent
import re
import argparse
import os.path
import json
import mimetypes
import os.path
import re
import zipfile
class Server:
def __init__(self, devpath, plugins, pluginroot, assets, strip_assets, theme):
def __init__(self, devpath, components, plugins, pluginroot, assets, strip_assets, theme):
if devpath:
print("Serving app from " + devpath)
if components:
print("Serving components from " + components)
if pluginroot:
print("Serving plugins from " + pluginroot)
if assets:
@@ -52,6 +55,7 @@ class Server:
else:
self.plugins = {}
self.devpath = devpath
self.components = components
self.pluginroot = pluginroot
self.strip_assets = strip_assets
self.theme = theme
@@ -92,6 +96,7 @@ def response(flow: http.HTTPFlow) -> None:
m = re.match(".+polygerrit_ui/\d+\.\d+/(.+)", flow.request.path)
pluginmatch = re.match("^/plugins/(.+)", flow.request.path)
localfile = ""
content = ""
if flow.request.path == "/config/server/info":
config = json.loads(flow.response.content[5:].decode('utf8'))
if server.theme:
@@ -105,6 +110,9 @@ def response(flow: http.HTTPFlow) -> None:
flow.response.content = str.encode(")]}'\n" + json.dumps(config))
if m is not None:
filepath = m.groups()[0]
if (filepath.startswith("bower_components/")):
with zipfile.ZipFile(server.components + "test_components.zip") as bower_zip:
content = bower_zip.read(filepath)
localfile = server.devpath + filepath
elif pluginmatch is not None:
pluginfile = flow.request.path_components[-1]
@@ -131,7 +139,10 @@ def response(flow: http.HTTPFlow) -> None:
if localfile and os.path.isfile(localfile):
if pluginmatch is not None:
print("Serving " + flow.request.path + " from " + localfile)
flow.response.content = server.readfile(localfile)
content = server.readfile(localfile)
if content:
flow.response.content = content
flow.response.status_code = 200
localtype = mimetypes.guess_type(localfile)
if localtype and localtype[0]:
@@ -142,13 +153,15 @@ def expandpath(path):
parser = argparse.ArgumentParser()
parser.add_argument("--app", type=str, default="", help="Path to /polygerrit-ui/app/")
parser.add_argument("--components", type=str, default="", help="Path to test_components.zip")
parser.add_argument("--plugins", type=str, default="", help="Comma-separated list of plugin files to add/replace")
parser.add_argument("--plugin_root", type=str, default="", help="Path containing individual plugin files to replace")
parser.add_argument("--assets", type=str, default="", help="Path containing assets file to import.")
parser.add_argument("--strip_assets", action="store_true", help="Strip plugin bundles from the response.")
parser.add_argument("--theme", type=str, help="Path to the default site theme to be used.")
parser.add_argument("--theme", default="", type=str, help="Path to the default site theme to be used.")
args = parser.parse_args()
server = Server(expandpath(args.app) + '/',
expandpath(args.components) + '/',
args.plugins,
expandpath(args.plugin_root) + '/',
args.assets and expandpath(args.assets),