Skip to content

Commit af02e62

Browse files
committed
Parse Firefox VPN versions using StrictVersion
As far as I can tell, version numbers only contain digits and periods, so we can do without LooseVersion here, reject bad version strings, and ensure comparisons work. Fixes #3441
1 parent 4548548 commit af02e62

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/auslib/util/versions.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,14 @@ def _cmp(self, other):
153153
return 1
154154

155155

156+
def FirefoxVPNVersion(version):
157+
try:
158+
return StrictVersion(version)
159+
except ValueError:
160+
raise BadDataError(f"Invalid app version {version}")
161+
162+
163+
156164
class PostModernMozillaVersion(StrictVersion):
157165
"""A version class that supports Firefox versions 5.0 and up, which
158166
may have "a1" but not "b2" tags in them"""
@@ -281,7 +289,7 @@ def decrement_version(version):
281289

282290
def get_version_class(product):
283291
if product in ("FirefoxVPN", "Guardian"):
284-
return LooseVersion
292+
return FirefoxVPNVersion
285293

286294
return MozillaVersion
287295

tests/web/test_json.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,3 +521,10 @@ def testJSONForAppReleaseBlob(client):
521521
assert ret.status_code < 500
522522
ret = client.get("/json/2/b/127.0/p/release/default/update.json")
523523
assert ret.status_code < 500
524+
525+
526+
@pytest.mark.usefixtures("guardian_db")
527+
def testJSONBadAppVersion(client):
528+
ret = client.get("/update/1/Guardian/0_4/default/WINNT_x86_64/en-US/release/update.xml")
529+
assert ret.status_code == 400
530+
assert ret.text == "Invalid app version 0_4"

0 commit comments

Comments
 (0)