From 31df6f91d13c5bcc40d919791ac0b8cbb5244e65 Mon Sep 17 00:00:00 2001 From: dylanljones Date: Tue, 11 Feb 2025 22:57:23 +0100 Subject: [PATCH] test: download key in unlock test --- tests/test_db6.py | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/tests/test_db6.py b/tests/test_db6.py index 096c51d..ad3af4e 100644 --- a/tests/test_db6.py +++ b/tests/test_db6.py @@ -3,8 +3,10 @@ # Date: 2023-02-01 import os +import re import shutil import tempfile +import urllib.request from pathlib import Path import pytest @@ -36,6 +38,40 @@ # Playlist ID PID1 = 2602250856 # Trial playlist - Cloud Library Sync +KEY_SOURCES = [ + { + "url": r"https://raw.githubusercontent.com/mganss/CueGen/19878e6eb3f586dee0eb3eb4f2ce3ef18309de9d/CueGen/Generator.cs", # noqa: E501 + "regex": re.compile( + r'((.|\n)*)Config\.UseSqlCipher.*\?.*"(?P.*)".*:.*null', + flags=re.IGNORECASE | re.MULTILINE, + ), + }, + { + "url": r"https://raw.githubusercontent.com/dvcrn/go-rekordbox/8be6191ba198ed7abd4ad6406d177ed7b4f749b5/cmd/getencryptionkey/main.go", # noqa: E501 + "regex": re.compile( + r'((.|\n)*)fmt\.Print\("(?P.*)"\)', flags=re.IGNORECASE | re.MULTILINE + ), + }, +] + + +def download_db6_key(): + dp = "" + for source in KEY_SOURCES: + url = source["url"] + regex = source["regex"] + + res = urllib.request.urlopen(url) + data = res.read().decode("utf-8") + match = regex.match(data) + if match: + dp = match.group("dp") + break + if dp: + return dp + else: + raise Exception("No key found in the online sources.") + @pytest.fixture def db(): @@ -54,7 +90,8 @@ def test_open_rekordbox_database(): def test_unlock_rekordbox_database(): - con = open_rekordbox_database(LOCKED, unlock=True) + dp = download_db6_key() + con = open_rekordbox_database(LOCKED, key=dp, unlock=True) con.execute("SELECT name FROM sqlite_master WHERE type='table';") con.close()