diff options
author | Hubert Hirtz <hubert@hirtz.pm> | 2021-04-19 14:07:45 +0200 |
---|---|---|
committer | pukkandan <pukkandan.ytdlp@gmail.com> | 2021-05-24 03:38:02 +0530 |
commit | 5435dcf96ec444c92a402d0eb169d94015c0e6ba (patch) | |
tree | b1e840df5ef5aca1ebc05e7a469f7929cc3c450b /test/test_utils.py | |
parent | f17c70227055a4415f604d644704eec9c3f4fe21 (diff) | |
download | hypervideo-pre-5435dcf96ec444c92a402d0eb169d94015c0e6ba.tar.lz hypervideo-pre-5435dcf96ec444c92a402d0eb169d94015c0e6ba.tar.xz hypervideo-pre-5435dcf96ec444c92a402d0eb169d94015c0e6ba.zip |
Handle Basic Auth `user:pass` in URLs
Fixes https://github.com/ytdl-org/youtube-dl/issues/20258, https://github.com/ytdl-org/youtube-dl/issues/26211
Authored by: hhirtz, pukkandan
Diffstat (limited to 'test/test_utils.py')
-rw-r--r-- | test/test_utils.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/test/test_utils.py b/test/test_utils.py index d0571c6f2..a8666caab 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -66,6 +66,7 @@ from yt_dlp.utils import ( sanitize_filename, sanitize_path, sanitize_url, + sanitized_Request, expand_path, prepend_extension, replace_extension, @@ -239,6 +240,15 @@ class TestUtil(unittest.TestCase): self.assertEqual(sanitize_url('rmtps://foo.bar'), 'rtmps://foo.bar') self.assertEqual(sanitize_url('https://foo.bar'), 'https://foo.bar') + def test_extract_basic_auth(self): + auth_header = lambda url: sanitized_Request(url).get_header('Authorization') + self.assertFalse(auth_header('http://foo.bar')) + self.assertFalse(auth_header('http://:foo.bar')) + self.assertEqual(auth_header('http://@foo.bar'), 'Basic Og==') + self.assertEqual(auth_header('http://:pass@foo.bar'), 'Basic OnBhc3M=') + self.assertEqual(auth_header('http://user:@foo.bar'), 'Basic dXNlcjo=') + self.assertEqual(auth_header('http://user:pass@foo.bar'), 'Basic dXNlcjpwYXNz') + def test_expand_path(self): def env(var): return '%{0}%'.format(var) if sys.platform == 'win32' else '${0}'.format(var) |