From f3f9c173f5a20eca3c289b0babe63a54ebd77f2a Mon Sep 17 00:00:00 2001 From: Ben Hearsum Date: Mon, 29 Jan 2018 09:49:36 -0500 Subject: [PATCH] bug 1433448: fix distribution matching logic for update query v6 (#459). r=jlorenzo --- auslib/db.py | 19 +++++---- auslib/test/web/test_client.py | 75 +++++++++++++++++++++++++++++++++- 2 files changed, 83 insertions(+), 11 deletions(-) diff --git a/auslib/db.py b/auslib/db.py index ddadd200db..2ac75a6911 100644 --- a/auslib/db.py +++ b/auslib/db.py @@ -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) diff --git a/auslib/test/web/test_client.py b/auslib/test/web/test_client.py index b8a12fbb62..0a4b11276d 100644 --- a/auslib/test/web/test_client.py +++ b/auslib/test/web/test_client.py @@ -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(""" @@ -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(""" @@ -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, """ + + + + + +""") def testVersion3Get(self): ret = self.client.get('/update/3/a/1.0/1/a/a/a/a/a/a/update.xml') @@ -670,6 +701,46 @@ def testVersion3GetWithUpdate(self): +""") + + def testVersion3GetWithDistribution(self): + ret = self.client.get('/update/3/c/1.0/1/p/l/a/a/default/a/update.xml') + self.assertUpdateEqual(ret, """ + + + + + +""") + + 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, """ + + + + + +""") + + 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, """ + + + + + +""") + + 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, """ + + + + + """) def testVersion4Get(self):