Skip to content

Commit

Permalink
urlchecker: Extract version from deb for rotating url
Browse files Browse the repository at this point in the history
  • Loading branch information
zhsj authored and wjt committed Jan 7, 2025
1 parent 5892302 commit a6fda5c
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/checkers/urlchecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ async def check(self, external_data: ExternalBase):
version_string = await utils.extract_appimage_version(
tmpfile,
)
if url.endswith(".deb"):
with tempfile.NamedTemporaryFile("w+b") as tmpfile:
new_version = await utils.get_extra_data_info_from_url(
url, session=self.session, dest_io=tmpfile
)
version_string = utils.extract_deb_version(
tmpfile,
)
else:
new_version = await utils.get_extra_data_info_from_url(
url, session=self.session
Expand Down
8 changes: 8 additions & 0 deletions src/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import apt_inst
import apt_pkg
import datetime as dt
import zoneinfo
import json
Expand Down Expand Up @@ -449,6 +451,12 @@ async def extract_appimage_version(appimg_io: t.IO):
return kf.get_string(GLib.KEY_FILE_DESKTOP_GROUP, "X-AppImage-Version")


def extract_deb_version(deb_io: t.IO):
assert deb_io.name
control = apt_inst.DebFile(deb_io.name).control.extractdata("control")
return apt_pkg.TagSection(control).get("Version")


_GITHUB_URL_PATTERN = re.compile(
r"""
^[email protected]:
Expand Down
9 changes: 9 additions & 0 deletions tests/com.google.Chrome.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
app-id: com.google.Chrome
modules:
- name: chrome
sources:
- type: extra-data
filename: chrome.deb
url: https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sha256: "0000000000000000000000000000000000000000000000000000000000000000"
size: 0
30 changes: 26 additions & 4 deletions tests/test_urlchecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
from src.lib.utils import init_logging
from src.lib.checksums import MultiDigest

TEST_MANIFEST = os.path.join(os.path.dirname(__file__), "com.unity.UnityHub.yaml")


class TestURLChecker(unittest.IsolatedAsyncioTestCase):
def setUp(self):
init_logging()

async def test_check(self):
checker = ManifestChecker(TEST_MANIFEST)
async def test_check_appimage(self):
checker = ManifestChecker(
os.path.join(os.path.dirname(__file__), "com.unity.UnityHub.yaml")
)
ext_data = await checker.check()

data = self._find_by_filename(ext_data, "UnityHubSetup.AppImage")
Expand All @@ -32,6 +32,28 @@ async def test_check(self):
)
self.assertIsNotNone(data.new_version.version)

async def test_check_deb(self):
checker = ManifestChecker(
os.path.join(os.path.dirname(__file__), "com.google.Chrome.yaml")
)
ext_data = await checker.check()

data = self._find_by_filename(ext_data, "chrome.deb")
self.assertIsNotNone(data)
self.assertEqual(data.filename, "chrome.deb")
self.assertIsNotNone(data.new_version)
self.assertIsInstance(data.new_version.size, int)
self.assertGreater(data.new_version.size, 0)
self.assertIsNotNone(data.new_version.checksum)
self.assertIsInstance(data.new_version.checksum, MultiDigest)
self.assertNotEqual(
data.new_version.checksum,
MultiDigest(
sha256="0000000000000000000000000000000000000000000000000000000000000000" # noqa: E501
),
)
self.assertIsNotNone(data.new_version.version)

def _find_by_filename(self, ext_data, filename):
for data in ext_data:
if data.filename == filename:
Expand Down

0 comments on commit a6fda5c

Please sign in to comment.