aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_http.py
diff options
context:
space:
mode:
authorcoletdev <coletdjnz@protonmail.com>2022-05-02 19:59:45 +1200
committerGitHub <noreply@github.com>2022-05-02 07:59:45 +0000
commitbb58c9ed5c3121bf55edcac9af8d62f5143b89d8 (patch)
treef7a4f792529513c6892c66b86840c39fc02a1429 /test/test_http.py
parentafac4caa7db30804bebac33e53c3cb0237958224 (diff)
downloadhypervideo-pre-bb58c9ed5c3121bf55edcac9af8d62f5143b89d8.tar.lz
hypervideo-pre-bb58c9ed5c3121bf55edcac9af8d62f5143b89d8.tar.xz
hypervideo-pre-bb58c9ed5c3121bf55edcac9af8d62f5143b89d8.zip
Add support for SSL client certificate authentication (#3435)
Adds `--client-certificate`, `--client-certificate-key`, `--client-certificate-password` Authored-by: coletdjnz Co-authored-by: df <fieldhouse@gmx.net> Co-authored-by: pukkandan <pukkandan.ytdlp@gmail.com>
Diffstat (limited to 'test/test_http.py')
-rw-r--r--test/test_http.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/test/test_http.py b/test/test_http.py
index d99be8be4..fb8c9f4e9 100644
--- a/test/test_http.py
+++ b/test/test_http.py
@@ -85,6 +85,50 @@ class TestHTTPS(unittest.TestCase):
self.assertEqual(r['entries'][0]['url'], 'https://127.0.0.1:%d/vid.mp4' % self.port)
+class TestClientCert(unittest.TestCase):
+ def setUp(self):
+ certfn = os.path.join(TEST_DIR, 'testcert.pem')
+ self.certdir = os.path.join(TEST_DIR, 'testdata', 'certificate')
+ cacertfn = os.path.join(self.certdir, 'ca.crt')
+ self.httpd = compat_http_server.HTTPServer(('127.0.0.1', 0), HTTPTestRequestHandler)
+ sslctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
+ sslctx.verify_mode = ssl.CERT_REQUIRED
+ sslctx.load_verify_locations(cafile=cacertfn)
+ sslctx.load_cert_chain(certfn, None)
+ self.httpd.socket = sslctx.wrap_socket(self.httpd.socket, server_side=True)
+ self.port = http_server_port(self.httpd)
+ self.server_thread = threading.Thread(target=self.httpd.serve_forever)
+ self.server_thread.daemon = True
+ self.server_thread.start()
+
+ def _run_test(self, **params):
+ ydl = YoutubeDL({
+ 'logger': FakeLogger(),
+ # Disable client-side validation of unacceptable self-signed testcert.pem
+ # The test is of a check on the server side, so unaffected
+ 'nocheckcertificate': True,
+ **params,
+ })
+ r = ydl.extract_info('https://127.0.0.1:%d/video.html' % self.port)
+ self.assertEqual(r['entries'][0]['url'], 'https://127.0.0.1:%d/vid.mp4' % self.port)
+
+ def test_certificate_combined_nopass(self):
+ self._run_test(client_certificate=os.path.join(self.certdir, 'clientwithkey.crt'))
+
+ def test_certificate_nocombined_nopass(self):
+ self._run_test(client_certificate=os.path.join(self.certdir, 'client.crt'),
+ client_certificate_key=os.path.join(self.certdir, 'client.key'))
+
+ def test_certificate_combined_pass(self):
+ self._run_test(client_certificate=os.path.join(self.certdir, 'clientwithencryptedkey.crt'),
+ client_certificate_password='foobar')
+
+ def test_certificate_nocombined_pass(self):
+ self._run_test(client_certificate=os.path.join(self.certdir, 'client.crt'),
+ client_certificate_key=os.path.join(self.certdir, 'clientencrypted.key'),
+ client_certificate_password='foobar')
+
+
def _build_proxy_handler(name):
class HTTPTestRequestHandler(compat_http_server.BaseHTTPRequestHandler):
proxy_name = name