Import apache2 for testing
Create `971-Robot-Code/ldap.json`. It is a JSON file with the LDAP URL
and password.
{
"ldap_bind_dn": "...",
"ldap_url": "...",
"ldap_password": "..."
}
Run like this:
$ bazel run //build_tests:apache_https_demo
Then you can navigate to `https://localhost:7000`.
If the ports are taken, customize with:
* `--https_port`
* `--wrapped_port`
Signed-off-by: Philipp Schrader <philipp.schrader@gmail.com>
Change-Id: I56432388b774932fc6cf295da52ac8bc9e974cd7
diff --git a/build_tests/dummy_http_server.py b/build_tests/dummy_http_server.py
new file mode 100644
index 0000000..f65122a
--- /dev/null
+++ b/build_tests/dummy_http_server.py
@@ -0,0 +1,48 @@
+"""This is a dummy server to demonstrate the apache_wrapper() rule.
+
+Don't run this server on its own. Instead run the
+`//build_tests:apache_https_demo` binary.
+
+When you authenticate against Apache via LDAP, this server prints the username
+you authenticated with and the path from the GET request.
+"""
+
+import base64
+from http.server import BaseHTTPRequestHandler, HTTPServer
+import os
+
+def parse_auth(authorization):
+ auth_type, auth_info = authorization.split(" ", maxsplit=1)
+ if auth_type != "Basic":
+ raise ValueError(f"Unknown auth type: {auth_type}")
+ username, _ = base64.b64decode(auth_info).decode().split(":", 1)
+ return username
+
+class Server(BaseHTTPRequestHandler):
+ def _set_response(self):
+ self.send_response(200)
+ self.send_header("Content-type", "text/html")
+ self.end_headers()
+
+ def _write(self, text):
+ self.wfile.write(text.encode("utf-8"))
+
+ def do_GET(self):
+ self._set_response()
+ self._write(f"GET request for {self.path}")
+ self._write("<br/>")
+ username = parse_auth(self.headers["Authorization"])
+ self._write(f"Hello, {username}")
+
+def main():
+ port = int(os.environ["APACHE_WRAPPED_PORT"])
+ server_address = ("", port)
+ httpd = HTTPServer(server_address, Server)
+ try:
+ httpd.serve_forever()
+ except KeyboardInterrupt:
+ pass
+ httpd.server_close()
+
+if __name__ == "__main__":
+ main()