Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1933266 - Add support for mirror URLs for GMP plugins. #3251

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions src/auslib/blobs/gmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,28 @@ def getInnerXML(self, updateQuery, update_type, allowlistedDomains, specialForce
url = platformData["fileUrl"]
if isForbiddenUrl(url, updateQuery["product"], allowlistedDomains):
continue
mirrorUrls = []
if "mirrorUrls" in platformData:
for mirrorUrl in platformData["mirrorUrls"]:
if isForbiddenUrl(mirrorUrl, updateQuery["product"], allowlistedDomains):
continue
mirrorUrls.append(mirrorUrl)
vendorXML.append(
' <addon id="%s" URL="%s" hashFunction="%s" hashValue="%s" size="%s" version="%s"/>'
% (vendor, url, self["hashFunction"], platformData["hashValue"], platformData["filesize"], vendorInfo["version"])
' <addon id="%s" URL="%s" hashFunction="%s" hashValue="%s" size="%s" version="%s"%s>'
% (
vendor,
url,
self["hashFunction"],
platformData["hashValue"],
platformData["filesize"],
vendorInfo["version"],
"" if mirrorUrls else "/",
)
)
if mirrorUrls:
for mirrorUrl in mirrorUrls:
vendorXML.append(' <mirror URL="%s"/>' % (mirrorUrl))
vendorXML.append(" </addon>")

return vendorXML

Expand All @@ -85,4 +103,8 @@ def containsForbiddenDomain(self, product, allowlistedDomains):
if "fileUrl" in platform:
if isForbiddenUrl(platform["fileUrl"], product, allowlistedDomains):
return True
if "mirrorUrls" in platform:
for mirrorUrl in platform["mirrorUrls"]:
if isForbiddenUrl(mirrorUrl, product, allowlistedDomains):
return True
return False
11 changes: 11 additions & 0 deletions src/auslib/blobs/schemas/gmp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,18 @@
hashValue:
type: string
description: The hash (using the "hashFunction" algorithm) of the file for this vendor+platform combination. The client uses this to help verify it after downloading.
# For backwards compatibility reasons, fileUrl and mirrorUrls are two
# separate properties, both containing URLs from which the addon can be
# downloaded. The fileUrl is the primary URL which should be tried first.
# If that fails and the client supports it, it should attempt the mirror
# URLs in the given order.
fileUrl:
type: string
description: Where the client can download the file for this vendor+platform combination.
format: uri
mirrorUrls:
type: array
description: Alternative locations where the client can download the file for this vendor+platform combination.
items:
type: string
format: uri
137 changes: 137 additions & 0 deletions tests/blobs/test_gmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@ def setUp(self):
"hashValue": "666",
"fileUrl": "http://evil.com/fire"
},
"t": {
"filesize": 21,
"hashValue": "22",
"fileUrl": "http://boring.com/qux",
"mirrorUrls": [
"http://boring.com/qux_alt",
"http://boring.com/qux_alt2"
]
},
"u": {
"filesize": 23,
"hashValue": "24",
"fileUrl": "http://boring.com/baz",
"mirrorUrls": ["http://evil.com/fire"]
},
"default": {
"filesize": 20,
"hashValue": "50",
Expand Down Expand Up @@ -121,6 +136,15 @@ def testGetPlatformData(self):
expected = {"filesize": 4, "hashValue": "5", "fileUrl": "http://boring.com/blah"}
self.assertEqual(self.blob.getPlatformData("c", "q2"), expected)

def testGetPlatformDataWithMirror(self):
expected = {
"filesize": 21,
"hashValue": "22",
"fileUrl": "http://boring.com/qux",
"mirrorUrls": ["http://boring.com/qux_alt", "http://boring.com/qux_alt2"],
}
self.assertEqual(self.blob.getPlatformData("d", "t"), expected)

def testGetPlatformDataRaisesBadDataError(self):
self.assertRaises(BadDataError, self.blob.getPlatformData, "c", "f")

Expand Down Expand Up @@ -188,6 +212,38 @@ def testGMPUpdateWithAlias(self):
self.assertCountEqual(returned, expected)
self.assertEqual(returned_footer.strip(), expected_footer.strip())

def testGMPUpdateWithMirror(self):
updateQuery = {
"product": "gg",
"version": "3",
"buildID": "1",
"buildTarget": "t",
"locale": "l",
"channel": "a",
"osVersion": "a",
"distribution": "a",
"distVersion": "a",
"force": 0,
}
returned_header = self.blob.getInnerHeaderXML(updateQuery, "minor", self.allowlistedDomains, self.specialForceHosts)
returned = self.blob.getInnerXML(updateQuery, "minor", self.allowlistedDomains, self.specialForceHosts)
returned_footer = self.blob.getInnerFooterXML(updateQuery, "minor", self.allowlistedDomains, self.specialForceHosts)
returned = [x.strip() for x in returned]
expected_header = "<addons>"
expected = [
"""
<addon id="d" URL="http://boring.com/qux" hashFunction="SHA512" hashValue="22" size="21" version="5">
""",
'<mirror URL="http://boring.com/qux_alt"/>',
'<mirror URL="http://boring.com/qux_alt2"/>',
"</addon>",
]
expected = [x.strip() for x in expected]
expected_footer = "</addons>"
self.assertEqual(returned_header.strip(), expected_header.strip())
self.assertCountEqual(returned, expected)
self.assertEqual(returned_footer.strip(), expected_footer.strip())

def testGMPUpdateSingleAddons(self):
updateQuery = {
"product": "gg",
Expand Down Expand Up @@ -274,6 +330,35 @@ def testGMPWithForbiddenDomain(self):
self.assertCountEqual(returned, expected)
self.assertEqual(returned_footer.strip(), expected_footer.strip())

def testGMPWithForbiddenDomainInMirror(self):
updateQuery = {
"product": "gg",
"version": "3",
"buildID": "1",
"buildTarget": "u",
"locale": "l",
"channel": "a",
"osVersion": "a",
"distribution": "a",
"distVersion": "a",
"force": 0,
}
returned_header = self.blob.getInnerHeaderXML(updateQuery, "minor", self.allowlistedDomains, self.specialForceHosts)
returned = self.blob.getInnerXML(updateQuery, "minor", self.allowlistedDomains, self.specialForceHosts)
returned_footer = self.blob.getInnerFooterXML(updateQuery, "minor", self.allowlistedDomains, self.specialForceHosts)
returned = [x.strip() for x in returned]
expected_header = "<addons>"
expected = [
"""
<addon id="d" URL="http://boring.com/baz" hashFunction="SHA512" hashValue="24" size="23" version="5"/>
""",
]
expected = [x.strip() for x in expected]
expected_footer = "</addons>"
self.assertEqual(returned_header.strip(), expected_header.strip())
self.assertCountEqual(returned, expected)
self.assertEqual(returned_footer.strip(), expected_footer.strip())

def testContainsForbiddenDomain(self):
blob = GMPBlobV1()
blob.loadJSON(
Expand All @@ -295,6 +380,32 @@ def testContainsForbiddenDomain(self):
}
}
}
"""
)
self.assertTrue(blob.containsForbiddenDomain("gg", self.allowlistedDomains))

def testContainsForbiddenDomainInMirror(self):
blob = GMPBlobV1()
blob.loadJSON(
"""
{
"name": "fake",
"schema_version": 1000,
"hashFunction": "SHA512",
"vendors": {
"c": {
"version": "1",
"platforms": {
"p": {
"filesize": 2,
"hashValue": "3",
"fileUrl": "http://a.com/blah",
"mirrorUrls": ["http://evil.com/blah"]
}
}
}
}
}
"""
)
self.assertTrue(blob.containsForbiddenDomain("gg", self.allowlistedDomains))
Expand All @@ -320,6 +431,32 @@ def testDoesNotContainForbiddenDomain(self):
}
}
}
"""
)
self.assertFalse(blob.containsForbiddenDomain("gg", self.allowlistedDomains))

def testDoesNotContainForbiddenDomainWithMirror(self):
blob = GMPBlobV1()
blob.loadJSON(
"""
{
"name": "fake",
"schema_version": 1000,
"hashFunction": "SHA512",
"vendors": {
"c": {
"version": "1",
"platforms": {
"p": {
"filesize": 2,
"hashValue": "3",
"fileUrl": "http://a.com/blah",
"mirrorUrls": ["http://a.com/blah2"]
}
}
}
}
}
"""
)
self.assertFalse(blob.containsForbiddenDomain("gg", self.allowlistedDomains))
Expand Down