Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Commit

Permalink
ensure a string doesnt throw a 500 (bug 789616)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy McKay committed Mar 6, 2013
1 parent 6e7ddcc commit 7ad77b0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
4 changes: 4 additions & 0 deletions mkt/api/forms.py
Expand Up @@ -117,6 +117,10 @@ def clean_upload(self):
return super(NewPackagedForm, self).clean_upload()


class PreviewArgsForm(happyforms.Form):
app = forms.IntegerField()


class PreviewJSONForm(happyforms.Form):
file = JSONField(required=True)
position = forms.IntegerField(required=True)
Expand Down
10 changes: 8 additions & 2 deletions mkt/api/resources.py
Expand Up @@ -25,7 +25,8 @@
MarketplaceAuthentication)
from mkt.api.base import MarketplaceResource
from mkt.api.forms import (CategoryForm, DeviceTypeForm, NewPackagedForm,
PreviewJSONForm, StatusForm, UploadForm)
PreviewArgsForm, PreviewJSONForm, StatusForm,
UploadForm)
from mkt.developers import tasks
from mkt.developers.forms import NewManifestForm, PreviewForm
from mkt.submit.forms import AppDetailsBasicForm
Expand Down Expand Up @@ -301,8 +302,13 @@ class Meta:
filtering = {'addon': ALL_WITH_RELATIONS}

def obj_create(self, bundle, request, **kwargs):
# Ensure that people don't pass strings through.
args = PreviewArgsForm(request.GET)
if not args.is_valid():
raise self.form_errors(args)

addon = self.get_object_or_404(Addon,
pk=request.GET.get('app'),
pk=args.cleaned_data['app'],
type=amo.ADDON_WEBAPP)
if not AppOwnerAuthorization().is_authorized(request, object=addon):
raise ImmediateHttpResponse(response=http.HttpForbidden())
Expand Down
7 changes: 7 additions & 0 deletions mkt/api/tests/test_handlers.py
Expand Up @@ -672,6 +672,13 @@ def test_post_preview(self):
eq_(previews.count(), 1)
eq_(previews.all()[0].position, 1)

def test_wrong_url(self):
url = list(self.list_url)
url[-1]['app'] = 'booyah'
res = self.client.post(url, data=json.dumps(self.good))
eq_(res.status_code, 400)
eq_(self.get_error(res)['app'], [u'Enter a whole number.'])

def test_not_mine(self):
self.app.authors.clear()
res = self.client.post(self.list_url, data=json.dumps(self.good))
Expand Down

0 comments on commit 7ad77b0

Please sign in to comment.