Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug 1021021: add schema for h264 updates - add gmp blob. r=nthomas
- Loading branch information
Showing
4 changed files
with
298 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import re | ||
|
||
from auslib.AUS import containsForbiddenDomain | ||
from auslib.blobs.base import Blob | ||
|
||
|
||
class GMPBlobV1(Blob): | ||
format_ = { | ||
"name": None, | ||
"schema_version": None, | ||
"hashFunction": None, | ||
"vendors": { | ||
"*": { | ||
"version": None, | ||
"platforms": { | ||
"*": { | ||
"alias": None, | ||
"filesize": None, | ||
"hashValue": None, | ||
"fileUrl": None | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
def __init__(self, **kwargs): | ||
Blob.__init__(self, **kwargs) | ||
if "schema_version" not in self: | ||
self["schema_version"] = 1000 | ||
|
||
def getVendorsForPlatform(self, platform): | ||
for v in self["vendors"]: | ||
if platform in self["vendors"][v]["platforms"]: | ||
yield v | ||
|
||
def getResolvedPlatform(self, vendor, platform): | ||
return self['vendors'][vendor]['platforms'][platform].get('alias', platform) | ||
|
||
def getPlatformData(self, vendor, platform): | ||
platform = self.getResolvedPlatform(vendor, platform) | ||
return self['vendors'][vendor]['platforms'][platform] | ||
|
||
def shouldServeUpdate(self, updateQuery): | ||
# GMP updates should always be returned. It is the responsibility | ||
# of the client to decide whether or not any action needs to be taken. | ||
return True | ||
|
||
# Because specialForceHosts is only relevant to our own internal servers, | ||
# and these type of updates are always served externally, we don't process | ||
# them in GMP blobs. | ||
def createXML(self, updateQuery, update_type, whitelistedDomains, specialForceHosts): | ||
buildTarget = updateQuery["buildTarget"] | ||
|
||
vendorXML = [] | ||
for vendor in self.getVendorsForPlatform(buildTarget): | ||
vendorInfo = self["vendors"][vendor] | ||
platformData = self.getPlatformData(vendor, buildTarget) | ||
|
||
url = platformData["fileUrl"] | ||
if containsForbiddenDomain(url, whitelistedDomains): | ||
continue | ||
vendorXML.append(' <addon id="%s" URL="%s" hashFunction="%s" hashValue="%s" size="%d" version="%s"/>' % \ | ||
(vendor, url, self["hashFunction"], platformData["hashValue"], | ||
platformData["filesize"], vendorInfo["version"])) | ||
|
||
xml = ['<?xml version="1.0"?>'] | ||
xml.append('<updates>') | ||
if vendorXML: | ||
xml.append(' <addons>') | ||
xml.extend(vendorXML) | ||
xml.append(' </addons>') | ||
xml.append('</updates>') | ||
# ensure valid xml by using the right entity for ampersand | ||
return re.sub('&(?!amp;)','&', '\n'.join(xml)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
import mock | ||
from tempfile import mkstemp | ||
import unittest | ||
from xml.dom import minidom | ||
|
||
from auslib.blobs.gmp import GMPBlobV1 | ||
import auslib.log | ||
|
||
|
||
class TestSchema1Blob(unittest.TestCase): | ||
maxDiff = 2000 | ||
|
||
def setUp(self): | ||
self.cef_patcher = mock.patch("auslib.log.cef_event") | ||
self.cef_patcher.start() | ||
self.specialForceHosts = ["http://a.com"] | ||
self.whitelistedDomains = ["a.com", "boring.com"] | ||
self.blob = GMPBlobV1() | ||
self.blob.loadJSON(""" | ||
{ | ||
"name": "fake", | ||
"schema_version": 1000, | ||
"hashFunction": "SHA512", | ||
"vendors": { | ||
"c": { | ||
"version": "1", | ||
"platforms": { | ||
"p": { | ||
"filesize": 2, | ||
"hashValue": "3", | ||
"fileUrl": "http://a.com/blah" | ||
}, | ||
"q": { | ||
"filesize": 4, | ||
"hashValue": "5", | ||
"fileUrl": "http://boring.com/blah" | ||
}, | ||
"q2": { | ||
"alias": "q" | ||
} | ||
} | ||
}, | ||
"d": { | ||
"version": "5", | ||
"platforms": { | ||
"q": { | ||
"filesize": 10, | ||
"hashValue": "11", | ||
"fileUrl": "http://boring.com/foo" | ||
}, | ||
"r": { | ||
"filesize": 666, | ||
"hashValue": "666", | ||
"fileUrl": "http://evil.com/fire" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
""") | ||
|
||
def tearDown(self): | ||
self.cef_patcher.stop() | ||
|
||
def testGetVendorsForPlatform(self): | ||
vendors = set([v for v in self.blob.getVendorsForPlatform("q")]) | ||
self.assertEquals(set(["c", "d"]), vendors) | ||
|
||
def testGetVendorsForPlatformOnlyInOne(self): | ||
vendors = set([v for v in self.blob.getVendorsForPlatform("r")]) | ||
self.assertEquals(set(["d"]), vendors) | ||
|
||
def testGetResolvedPlatform(self): | ||
self.assertEquals("q", self.blob.getResolvedPlatform("c", "q2")) | ||
|
||
def testGetPlatformData(self): | ||
expected = { | ||
"filesize": 4, | ||
"hashValue": "5", | ||
"fileUrl": "http://boring.com/blah", | ||
} | ||
self.assertEquals(self.blob.getPlatformData("c", "q2"), expected) | ||
|
||
def testGMPUpdate(self): | ||
updateQuery = { | ||
"product": "gg", "version": "3", "buildID": "1", | ||
"buildTarget": "p", "locale": "l", "channel": "a", | ||
"osVersion": "a", "distribution": "a", "distVersion": "a", | ||
"force": 0 | ||
} | ||
returned = self.blob.createXML(updateQuery, "minor", self.whitelistedDomains, self.specialForceHosts) | ||
returned = minidom.parseString(returned) | ||
expected = minidom.parseString("""<?xml version="1.0"?> | ||
<updates> | ||
<addons> | ||
<addon id="c" URL="http://a.com/blah" hashFunction="SHA512" hashValue="3" size="2" version="1"/> | ||
</addons> | ||
</updates> | ||
""") | ||
self.assertEqual(returned.toxml(), expected.toxml()) | ||
|
||
def testGMPUpdateWithAlias(self): | ||
updateQuery = { | ||
"product": "gg", "version": "3", "buildID": "1", | ||
"buildTarget": "q2", "locale": "l", "channel": "a", | ||
"osVersion": "a", "distribution": "a", "distVersion": "a", | ||
"force": 0 | ||
} | ||
returned = self.blob.createXML(updateQuery, "minor", self.whitelistedDomains, self.specialForceHosts) | ||
returned = minidom.parseString(returned) | ||
expected = minidom.parseString("""<?xml version="1.0"?> | ||
<updates> | ||
<addons> | ||
<addon id="c" URL="http://boring.com/blah" hashFunction="SHA512" hashValue="5" size="4" version="1"/> | ||
</addons> | ||
</updates> | ||
""") | ||
self.assertEqual(returned.toxml(), expected.toxml()) | ||
|
||
def testGMPUpdateMultipleAddons(self): | ||
updateQuery = { | ||
"product": "gg", "version": "3", "buildID": "1", | ||
"buildTarget": "q", "locale": "l", "channel": "a", | ||
"osVersion": "a", "distribution": "a", "distVersion": "a", | ||
"force": 0 | ||
} | ||
returned = self.blob.createXML(updateQuery, "minor", self.whitelistedDomains, self.specialForceHosts) | ||
returned = minidom.parseString(returned) | ||
expected = minidom.parseString("""<?xml version="1.0"?> | ||
<updates> | ||
<addons> | ||
<addon id="c" URL="http://boring.com/blah" hashFunction="SHA512" hashValue="5" size="4" version="1"/> | ||
<addon id="d" URL="http://boring.com/foo" hashFunction="SHA512" hashValue="11" size="10" version="5"/> | ||
</addons> | ||
</updates> | ||
""") | ||
self.assertEqual(returned.toxml(), expected.toxml()) | ||
|
||
def testGMPWithForbiddenDomain(self): | ||
updateQuery = { | ||
"product": "gg", "version": "3", "buildID": "1", | ||
"buildTarget": "r", "locale": "l", "channel": "a", | ||
"osVersion": "a", "distribution": "a", "distVersion": "a", | ||
"force": 0 | ||
} | ||
with mock.patch("auslib.AUS.cef_event") as c: | ||
returned = self.blob.createXML(updateQuery, "minor", self.whitelistedDomains, self.specialForceHosts) | ||
returned = minidom.parseString(returned) | ||
self.assertEqual(returned.getElementsByTagName('updates')[0].firstChild.nodeValue, '\n') |