Skip to content

Commit

Permalink
Bug 1517743 - support removing newlines & indents for a couple of Fir…
Browse files Browse the repository at this point in the history
…efox nightlies (#854)
  • Loading branch information
nthomas-mozilla authored Jan 7, 2019
1 parent 06b26f0 commit 461c8f3
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
70 changes: 70 additions & 0 deletions auslib/test/web/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ def assertUpdateEqual(self, http_reponse, expected_xml_string):
expected = minidom.parseString(expected_xml_string)
self.assertEqual(returned.toxml(), expected.toxml())

def assertUpdateTextEqual(self, http_response, expected):
self.assertHttpResponse(http_response)
returned = http_response.get_data(as_text=True)
self.assertEqual(returned, expected)


class ClientTestBase(ClientTestCommon):
maxDiff = 2000
Expand Down Expand Up @@ -1665,3 +1670,68 @@ def testNonSubstitutedUrlVariablesReturnEmptyUpdate(self):
def testUnicodeAcceptedInQueryFieldName(self):
ret = self.client.get("/update/6/3/e/2.0.0/1/p/l/a/a/a/a/update.xml?fooÃÃÃÃÃÃbar=1")
self.assertEqual(ret.status_code, 400)


class ClientTestCompactXML(ClientTestCommon):
"""Tests the compact XML needed to rescue two Firefox nightlies (bug 1517743)."""

@classmethod
def setUpClass(cls):
# Error handlers are removed in order to give us better debug messages
cls.error_spec = app.error_handler_spec
# Ripped from https://github.com/mitsuhiko/flask/blob/1f5927eee2288b4aaf508af5dc1f148aa2140d91/flask/app.py#L394
app.error_handler_spec = {None: {}}

@classmethod
def tearDownClass(cls):
app.error_handler_spec = cls.error_spec

def setUp(self):
self.version_fd, self.version_file = mkstemp()
app.config['DEBUG'] = True
app.config['SPECIAL_FORCE_HOSTS'] = ('http://a.com',)
app.config['WHITELISTED_DOMAINS'] = {'a.com': ('b',)}
dbo.setDb('sqlite:///:memory:')
self.metadata.create_all(dbo.engine)
dbo.setDomainWhitelist({'a.com': ('b',)})
self.client = app.test_client()
dbo.rules.t.insert().execute(priority=90, backgroundRate=100, mapping='Firefox-mozilla-central-nightly-latest',
update_type='minor', product='b', data_version=1)
dbo.releases.t.insert().execute(name='Firefox-mozilla-central-nightly-latest', product='b', data_version=1, data=createBlob("""
{
"name": "Firefox-mozilla-central-nightly-latest",
"schema_version": 1,
"appv": "1.0",
"extv": "1.0",
"hashFunction": "sha512",
"platforms": {
"p": {
"buildID": "30000101000000",
"locales": {
"l": {
"complete": {
"filesize": "3",
"from": "*",
"hashValue": "4",
"fileUrl": "http://a.com/z"
}
}
}
}
}
}
"""))

def testGoodNightly(self):
ret = self.client.get('/update/6/b/1.0/20181212121212/p/l/a/a/a/a/a/update.xml')
self.assertUpdateTextEqual(ret, u"""<?xml version="1.0"?>
<updates>
<update type="minor" version="1.0" extensionVersion="1.0" buildID="30000101000000">
<patch type="complete" URL="http://a.com/z" hashFunction="sha512" hashValue="4" size="3"/>
</update>
</updates>""")

def testBrokenNightly(self):
ret = self.client.get('/update/6/b/1.0/20190103220533/p/l/a/a/a/a/a/update.xml')
self.assertUpdateTextEqual(ret, u'<?xml version="1.0"?><updates><update type="minor" version="1.0" extensionVersion="1.0" buildID="30000101000000">'
u'<patch type="complete" URL="http://a.com/z" hashFunction="sha512" hashValue="4" size="3"/></update></updates>')
11 changes: 11 additions & 0 deletions auslib/web/public/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ def get_update_blob(transaction, **url):
# code support queries without it.
if url['queryVersion'] == 1:
url['osVersion'] = ''
# Bug 1517743 - two Firefox nightlies can't parse update.xml when it contains the usual newlines or indentations
squash_response = False

query = getQueryFromURL(url)
LOG.debug("Got query: %s", query)
Expand Down Expand Up @@ -193,6 +195,10 @@ def get_update_blob(transaction, **url):
response_blobs.append({'product_query': query,
'response_release': release,
'response_update_type': update_type})
# Bug 1517743 - we want a cheap test because this will be run on each request
if release['name'] == 'Firefox-mozilla-central-nightly-latest' and query['buildID'] in ('20190103220533', '20190104093221'):
squash_response = True
LOG.debug('Busted nightly detected, will squash xml response')

# getHeaderXML() returns outermost header for an update which
# is same for all release type
Expand Down Expand Up @@ -226,6 +232,11 @@ def get_update_blob(transaction, **url):
xml.append('<updates>')
xml.append('</updates>')
xml = "\n".join(xml)

# Bug 1517743 - remove newlines and 4 space indents
if squash_response:
xml = xml.replace('\n', '').replace(' ', '')

LOG.debug("Sending XML: %s", xml)
response = make_response(xml)
response.headers["Cache-Control"] = app.cacheControl
Expand Down

0 comments on commit 461c8f3

Please sign in to comment.