watch out for blacklisted guids (bug 624081)
This commit is contained in:
Родитель
2cc8d65fd5
Коммит
e7e7adc2d6
|
@ -3,6 +3,7 @@ from datetime import datetime, timedelta
|
|||
import itertools
|
||||
from urlparse import urlparse
|
||||
|
||||
from django import forms
|
||||
from django.conf import settings
|
||||
from django.core import mail
|
||||
from django.core.cache import cache
|
||||
|
@ -17,7 +18,8 @@ import files.tests
|
|||
from amo import set_user
|
||||
from amo.signals import _connect, _disconnect
|
||||
from addons.models import (Addon, AddonDependency, AddonRecommendation,
|
||||
AddonType, Category, Feature, Persona, Preview)
|
||||
AddonType, BlacklistedGuid, Category, Feature,
|
||||
Persona, Preview)
|
||||
from applications.models import Application, AppVersion
|
||||
from devhub.models import ActivityLog
|
||||
from files.models import File, Platform
|
||||
|
@ -793,6 +795,13 @@ class TestAddonFromUpload(files.tests.UploadTest):
|
|||
for version in ('3.0', '3.6.*'):
|
||||
AppVersion.objects.create(application_id=1, version=version)
|
||||
|
||||
def test_blacklisted_guid(self):
|
||||
BlacklistedGuid.objects.create(guid='guid@xpi')
|
||||
with self.assertRaises(forms.ValidationError) as e:
|
||||
addon = Addon.from_upload(self.get_upload('extension.xpi'),
|
||||
[self.platform])
|
||||
eq_(e.exception.messages, ['Duplicate UUID found.'])
|
||||
|
||||
def test_xpi_attributes(self):
|
||||
addon = Addon.from_upload(self.get_upload('extension.xpi'),
|
||||
[self.platform])
|
||||
|
|
|
@ -126,7 +126,7 @@ def parse_search(filename, addon=None):
|
|||
|
||||
def parse_xpi(xpi, addon=None):
|
||||
"""Extract and parse an XPI."""
|
||||
from addons.models import Addon
|
||||
from addons.models import Addon, BlacklistedGuid
|
||||
# Extract to /tmp
|
||||
path = os.path.join(settings.TMP_PATH, str(time.time()))
|
||||
os.makedirs(path)
|
||||
|
@ -146,8 +146,10 @@ def parse_xpi(xpi, addon=None):
|
|||
shutil.rmtree(path)
|
||||
|
||||
if addon and addon.guid != rdf['guid']:
|
||||
raise forms.ValidationError(_("UUID doesn't match add-on"))
|
||||
if not addon and Addon.objects.filter(guid=rdf['guid']):
|
||||
raise forms.ValidationError(_("UUID doesn't match add-on."))
|
||||
if (not addon
|
||||
and Addon.objects.filter(guid=rdf['guid'])
|
||||
or BlacklistedGuid.objects.filter(guid=rdf['guid']).exists()):
|
||||
raise forms.ValidationError(_('Duplicate UUID found.'))
|
||||
|
||||
if addon and addon.type != rdf['type']:
|
||||
|
|
Загрузка…
Ссылка в новой задаче