From 64c425364ebb81f12107d0cb4a8ea6c79b65eac2 Mon Sep 17 00:00:00 2001 From: Matthew Broadway Date: Thu, 3 Jun 2021 21:59:32 +0100 Subject: [PATCH] using hashlib for PBKDF2 --- test/test_cookies.py | 14 +++++++------- youtube_dl/cookies.py | 39 ++++++++++++++++++++------------------- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/test/test_cookies.py b/test/test_cookies.py index d217e46ef..dbdb2f912 100644 --- a/test/test_cookies.py +++ b/test/test_cookies.py @@ -2,7 +2,7 @@ import unittest from youtube_dl import cookies from youtube_dl.cookies import LinuxChromeCookieDecryptor, WindowsChromeCookieDecryptor, CRYPTO_AVAILABLE, \ - MacChromeCookieDecryptor + MacChromeCookieDecryptor, Logger class MonkeyPatch: @@ -23,22 +23,22 @@ class MonkeyPatch: @unittest.skipIf(not CRYPTO_AVAILABLE, 'cryptography library not available') class TestCookies(unittest.TestCase): def test_chrome_cookie_decryptor_linux_derive_key(self): - key = LinuxChromeCookieDecryptor.derive_key('abc') + key = LinuxChromeCookieDecryptor.derive_key(b'abc') assert key == b'7\xa1\xec\xd4m\xfcA\xc7\xb19Z\xd0\x19\xdcM\x17' def test_chrome_cookie_decryptor_mac_derive_key(self): - key = MacChromeCookieDecryptor.derive_key('abc') + key = MacChromeCookieDecryptor.derive_key(b'abc') assert key == b'Y\xe2\xc0\xd0P\xf6\xf4\xe1l\xc1\x8cQ\xcb|\xcdY' def test_chrome_cookie_decryptor_linux_v10(self): - with MonkeyPatch(cookies, '_get_linux_keyring_password', lambda *args, **kwargs: ''): + with MonkeyPatch(cookies, '_get_linux_keyring_password', lambda *args, **kwargs: b''): encrypted_value = b'v10\xccW%\xcd\xe6\xe6\x9fM" \xa7\xb0\xca\xe4\x07\xd6' value = 'USD' decryptor = LinuxChromeCookieDecryptor('Chrome') assert decryptor.decrypt(encrypted_value) == value def test_chrome_cookie_decryptor_linux_v11(self): - with MonkeyPatch(cookies, '_get_linux_keyring_password', lambda *args, **kwargs: ''): + with MonkeyPatch(cookies, '_get_linux_keyring_password', lambda *args, **kwargs: b''): encrypted_value = b'v11#\x81\x10>`w\x8f)\xc0\xb2\xc1\r\xf4\x1al\xdd\x93\xfd\xf8\xf8N\xf2\xa9\x83\xf1\xe9o\x0elVQd' value = 'tz=Europe.London' decryptor = LinuxChromeCookieDecryptor('Chrome') @@ -49,11 +49,11 @@ class TestCookies(unittest.TestCase): lambda *args, **kwargs: b'Y\xef\xad\xad\xeerp\xf0Y\xe6\x9b\x12\xc2 2: raise ValueError('invalid browser specification: "{}"'.format(browser_specification)) browser_name, profile = parts - if _is_path(profile): + if profile is not None and _is_path(profile): profile = os.path.expanduser(profile) return browser_name, profile