Protects against a malformed locales dict (bug 696931)

This commit is contained in:
Kumar McMillan 2011-11-17 18:32:51 -06:00
Родитель 2d3436aa48
Коммит 905ef63c6d
3 изменённых файлов: 34 добавлений и 1 удалений

Просмотреть файл

@ -16,7 +16,7 @@ from django.db import IntegrityError
from django.utils import translation
from mock import patch, Mock
from nose.tools import eq_, assert_not_equal
from nose.tools import eq_, assert_not_equal, raises
import amo
import amo.tests
@ -1509,6 +1509,12 @@ class TestAddonFromUpload(UploadTest):
addon = Addon.from_upload(upload, [self.platform])
eq_(addon.default_locale, 'en-US') # not gb
@raises(forms.ValidationError)
def test_malformed_locales(self):
manifest = self.manifest('malformed-locales.webapp')
upload = self.get_upload(abspath=manifest)
Addon.from_upload(upload, [self.platform])
REDIRECT_URL = 'http://outgoing.mozilla.org/v1/'

Просмотреть файл

@ -0,0 +1,24 @@
{
"version": "1.0",
"name": "MozillaBall",
"description": "Exciting Open Web development action!",
"icons": {
"16": "/img/icon-16.png",
"48": "/img/icon-48.png",
"128": "/img/icon-128.png"
},
"widget": {
"path": "/widget.html",
"width": 100,
"height": 200
},
"developer": {
"name": "Mozilla Labs",
"url": "http://mozillalabs.com"
},
"installs_allowed_from": [
"https://appstore.mozillalabs.com"
],
"locales": [],
"default_locale": "en"
}

Просмотреть файл

@ -194,6 +194,9 @@ class WebAppParser(object):
_('Could not parse webapp manifest file.'))
loc = data.get('default_locale', translation.get_language())
default_locale = self.trans_locale(loc)
if type(data.get('locales')) == list:
raise forms.ValidationError(
_('Your specified app locales are not in the correct format.'))
localized_descr = self.extract_locale(data.get('locales', {}),
'description', default='')
if 'description' in data: