Skip to content

Commit

Permalink
bug 1433448: fix distribution matching logic for update query v6 (#459)…
Browse files Browse the repository at this point in the history
…. r=jlorenzo
  • Loading branch information
bhearsum committed Jan 29, 2018
1 parent 515239f commit f3f9c17
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 11 deletions.
19 changes: 10 additions & 9 deletions auslib/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -1601,18 +1601,19 @@ def getRawMatches():
((self.buildTarget == updateQuery['buildTarget']) | (self.buildTarget == null())) &
((self.headerArchitecture == updateQuery['headerArchitecture']) | (self.headerArchitecture == null()))
]
# Query version 2 doesn't have distribution information, and to keep
# us maximally flexible, we won't match any rules that have
# distribution update set.
if updateQuery['queryVersion'] == 2:
where.extend([(self.distribution == null()) & (self.distVersion == null())])
# Only query versions 3 and 4 have distribution information, so we
# need to consider it.
if updateQuery['queryVersion'] in (3, 4):
if "distribution" in updateQuery:
where.extend([
((self.distribution == updateQuery['distribution']) | (self.distribution == null()))
])
else:
where.extend([(self.distribution == null())])

if "distVersion" in updateQuery:
where.extend([
((self.distribution == updateQuery['distribution']) | (self.distribution == null())) &
((self.distVersion == updateQuery['distVersion']) | (self.distVersion == null()))
])
else:
where.extend([(self.distVersion == null())])

self.log.debug("where: %s" % where)
return self.select(where=where, transaction=transaction)
Expand Down
75 changes: 73 additions & 2 deletions auslib/test/web/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ def setUp(self):
}
}
"""))

dbo.rules.t.insert().execute(priority=90, backgroundRate=100, mapping='c', update_type='minor', product='c',
distribution='default', data_version=1)
dbo.releases.t.insert().execute(name='c', product='c', data_version=1, data=createBlob("""
Expand All @@ -255,6 +254,32 @@ def setUp(self):
}
}
}
"""))
dbo.rules.t.insert().execute(priority=80, backgroundRate=100, mapping='c2', update_type='minor', product='c',
data_version=1)
dbo.releases.t.insert().execute(name='c2', product='c', data_version=1, data=createBlob("""
{
"name": "c2",
"schema_version": 1,
"appv": "15.0",
"extv": "15.0",
"hashFunction": "sha512",
"platforms": {
"p": {
"buildID": "51",
"locales": {
"l": {
"complete": {
"filesize": "52",
"from": "*",
"hashValue": "53",
"fileUrl": "http://a.com/x"
}
}
}
}
}
}
"""))
dbo.rules.t.insert().execute(priority=90, backgroundRate=100, mapping='d', update_type='minor', product='d', data_version=1)
dbo.releases.t.insert().execute(name='d', product='d', data_version=1, data=createBlob("""
Expand Down Expand Up @@ -656,7 +681,13 @@ def testVersion2Get(self):

def testVersion2GetIgnoresRuleWithDistribution(self):
ret = self.client.get('/update/2/c/10.0/1/p/l/a/a/update.xml')
self.assertUpdatesAreEmpty(ret)
self.assertUpdateEqual(ret, """<?xml version="1.0"?>
<updates>
<update type="minor" version="15.0" extensionVersion="15.0" buildID="51">
<patch type="complete" URL="http://a.com/x" hashFunction="sha512" hashValue="53" size="52"/>
</update>
</updates>
""")

def testVersion3Get(self):
ret = self.client.get('/update/3/a/1.0/1/a/a/a/a/a/a/update.xml')
Expand All @@ -670,6 +701,46 @@ def testVersion3GetWithUpdate(self):
<patch type="complete" URL="http://a.com/z" hashFunction="sha512" hashValue="4" size="3"/>
</update>
</updates>
""")

def testVersion3GetWithDistribution(self):
ret = self.client.get('/update/3/c/1.0/1/p/l/a/a/default/a/update.xml')
self.assertUpdateEqual(ret, """<?xml version="1.0"?>
<updates>
<update type="minor" version="10.0" extensionVersion="10.0" buildID="11">
<patch type="complete" URL="http://a.com/y" hashFunction="sha512" hashValue="13" size="12"/>
</update>
</updates>
""")

def testVersion4GetWithDistribution(self):
ret = self.client.get('/update/4/c/1.0/1/p/l/a/a/default/a/a/update.xml')
self.assertUpdateEqual(ret, """<?xml version="1.0"?>
<updates>
<update type="minor" version="10.0" extensionVersion="10.0" buildID="11">
<patch type="complete" URL="http://a.com/y" hashFunction="sha512" hashValue="13" size="12"/>
</update>
</updates>
""")

def testVersion6GetWithDistribution(self):
ret = self.client.get('/update/6/c/1.0/1/p/l/a/a/SSE/default/a/update.xml')
self.assertUpdateEqual(ret, """<?xml version="1.0"?>
<updates>
<update type="minor" version="10.0" extensionVersion="10.0" buildID="11">
<patch type="complete" URL="http://a.com/y" hashFunction="sha512" hashValue="13" size="12"/>
</update>
</updates>
""")

def testVersion6GetDoesntMatchWrongDistribution(self):
ret = self.client.get('/update/6/c/1.0/1/p/l/a/a/SSE/a/a/update.xml')
self.assertUpdateEqual(ret, """<?xml version="1.0"?>
<updates>
<update type="minor" version="15.0" extensionVersion="15.0" buildID="51">
<patch type="complete" URL="http://a.com/x" hashFunction="sha512" hashValue="53" size="52"/>
</update>
</updates>
""")

def testVersion4Get(self):
Expand Down

0 comments on commit f3f9c17

Please sign in to comment.