added suggestions as per http://bugs.foocorp.net/issues/365#note-9
This commit is contained in:
parent
ad35dd490c
commit
9df37e8a4a
@ -15,7 +15,7 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import urlparse
|
import urlparse
|
||||||
from os import getcwd
|
import pkg_resources
|
||||||
|
|
||||||
from nose.tools import assert_equal
|
from nose.tools import assert_equal
|
||||||
|
|
||||||
@ -24,20 +24,18 @@ from mediagoblin.tests.tools import setup_fresh_app, get_test_app
|
|||||||
from mediagoblin import mg_globals
|
from mediagoblin import mg_globals
|
||||||
from mediagoblin import util
|
from mediagoblin import util
|
||||||
|
|
||||||
IMAGE_ROOT = getcwd() + '/mediagoblin/tests/test_submission/'
|
GOOD_JPG = pkg_resources.resource_filename(
|
||||||
GOOD_JPG = 'good.jpg'
|
'mediagoblin.tests', 'test_submission/good.jpg')
|
||||||
GOOD_PNG = 'good.png'
|
GOOD_PNG = pkg_resources.resource_filename(
|
||||||
EVIL_FILE = 'evil'
|
'mediagoblin.tests', 'test_submission/good.png')
|
||||||
EVIL_JPG = 'evil.jpg'
|
EVIL_FILE = pkg_resources.resource_filename(
|
||||||
EVIL_PNG = 'evil.png'
|
'mediagoblin.tests', 'test_submission/evil')
|
||||||
|
EVIL_JPG = pkg_resources.resource_filename(
|
||||||
|
'mediagoblin.tests', 'test_submission/evil.jpg')
|
||||||
|
EVIL_PNG = pkg_resources.resource_filename(
|
||||||
|
'mediagoblin.tests', 'test_submission/evil.png')
|
||||||
|
|
||||||
|
|
||||||
# TODO:
|
|
||||||
# - Define test files as globals
|
|
||||||
# - supported mime types
|
|
||||||
# - unsupported mime type with supported extension
|
|
||||||
# - Remove any imports that aren't neccessary
|
|
||||||
|
|
||||||
class TestSubmission:
|
class TestSubmission:
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.test_app = get_test_app()
|
self.test_app = get_test_app()
|
||||||
@ -79,12 +77,6 @@ class TestSubmission:
|
|||||||
|
|
||||||
|
|
||||||
def test_normal_uploads(self):
|
def test_normal_uploads(self):
|
||||||
# FYI:
|
|
||||||
# upload_files is for file uploads. It should be a list of
|
|
||||||
# [(fieldname, filename, file_content)]. You can also use
|
|
||||||
# just [(fieldname, filename)] and the file content will be
|
|
||||||
# read from disk.
|
|
||||||
|
|
||||||
# Test JPG
|
# Test JPG
|
||||||
# --------
|
# --------
|
||||||
util.clear_test_template_context()
|
util.clear_test_template_context()
|
||||||
@ -92,15 +84,15 @@ class TestSubmission:
|
|||||||
'/submit/', {
|
'/submit/', {
|
||||||
'title': 'Normal upload 1'
|
'title': 'Normal upload 1'
|
||||||
}, upload_files=[(
|
}, upload_files=[(
|
||||||
'file', IMAGE_ROOT + GOOD_JPG)])
|
'file', GOOD_JPG)])
|
||||||
|
|
||||||
# User should be redirected
|
# User should be redirected
|
||||||
response.follow()
|
response.follow()
|
||||||
assert_equal(
|
assert_equal(
|
||||||
urlparse.urlsplit(response.location)[2],
|
urlparse.urlsplit(response.location)[2],
|
||||||
'/submit/success/')
|
'/u/chris/')
|
||||||
assert util.TEMPLATE_TEST_CONTEXT.has_key(
|
assert util.TEMPLATE_TEST_CONTEXT.has_key(
|
||||||
'mediagoblin/submit/success.html')
|
'mediagoblin/user_pages/user.html')
|
||||||
|
|
||||||
# Test PNG
|
# Test PNG
|
||||||
# --------
|
# --------
|
||||||
@ -109,16 +101,14 @@ class TestSubmission:
|
|||||||
'/submit/', {
|
'/submit/', {
|
||||||
'title': 'Normal upload 2'
|
'title': 'Normal upload 2'
|
||||||
}, upload_files=[(
|
}, upload_files=[(
|
||||||
'file', IMAGE_ROOT + GOOD_PNG)])
|
'file', GOOD_PNG)])
|
||||||
|
|
||||||
response.follow()
|
response.follow()
|
||||||
assert_equal(
|
assert_equal(
|
||||||
urlparse.urlsplit(response.location)[2],
|
urlparse.urlsplit(response.location)[2],
|
||||||
'/submit/success/')
|
'/u/chris/')
|
||||||
assert util.TEMPLATE_TEST_CONTEXT.has_key(
|
assert util.TEMPLATE_TEST_CONTEXT.has_key(
|
||||||
'mediagoblin/submit/success.html')
|
'mediagoblin/user_pages/user.html')
|
||||||
|
|
||||||
# TODO: Test additional supported formats
|
|
||||||
|
|
||||||
|
|
||||||
def test_malicious_uploads(self):
|
def test_malicious_uploads(self):
|
||||||
@ -129,35 +119,39 @@ class TestSubmission:
|
|||||||
'/submit/', {
|
'/submit/', {
|
||||||
'title': 'Malicious Upload 2'
|
'title': 'Malicious Upload 2'
|
||||||
}, upload_files=[(
|
}, upload_files=[(
|
||||||
'file', IMAGE_ROOT + EVIL_FILE)])
|
'file', EVIL_FILE)])
|
||||||
|
|
||||||
context = util.TEMPLATE_TEST_CONTEXT['mediagoblin/submit/start.html']
|
context = util.TEMPLATE_TEST_CONTEXT['mediagoblin/submit/start.html']
|
||||||
form = context['submit_form']
|
form = context['submit_form']
|
||||||
assert form.file.errors == ['The file doesn\'t seem to be an image!']
|
assert form.file.errors == ['The file doesn\'t seem to be an image!']
|
||||||
|
|
||||||
|
# NOTE: The following 2 tests will fail. These can be uncommented
|
||||||
|
# after http://bugs.foocorp.net/issues/324 is resolved and
|
||||||
|
# bad files are handled properly.
|
||||||
|
|
||||||
# Test non-supported file with .jpg extension
|
# Test non-supported file with .jpg extension
|
||||||
# -------------------------------------------
|
# -------------------------------------------
|
||||||
util.clear_test_template_context()
|
#util.clear_test_template_context()
|
||||||
response = self.test_app.post(
|
#response = self.test_app.post(
|
||||||
'/submit/', {
|
# '/submit/', {
|
||||||
'title': 'Malicious Upload 2'
|
# 'title': 'Malicious Upload 2'
|
||||||
}, upload_files=[(
|
# }, upload_files=[(
|
||||||
'file', IMAGE_ROOT + EVIL_JPG)])
|
# 'file', EVIL_JPG)])
|
||||||
|
|
||||||
context = util.TEMPLATE_TEST_CONTEXT['mediagoblin/submit/start.html']
|
#context = util.TEMPLATE_TEST_CONTEXT['mediagoblin/submit/start.html']
|
||||||
form = context['submit_form']
|
#form = context['submit_form']
|
||||||
assert form.file.errors == ['The file doesn\'t seem to be an image!']
|
#assert form.file.errors == ['The file doesn\'t seem to be an image!']
|
||||||
|
|
||||||
# Test non-supported file with .png extension
|
# Test non-supported file with .png extension
|
||||||
# -------------------------------------------
|
# -------------------------------------------
|
||||||
util.clear_test_template_context()
|
#util.clear_test_template_context()
|
||||||
response = self.test_app.post(
|
#response = self.test_app.post(
|
||||||
'/submit/', {
|
# '/submit/', {
|
||||||
'title': 'Malicious Upload 3'
|
# 'title': 'Malicious Upload 3'
|
||||||
}, upload_files=[(
|
# }, upload_files=[(
|
||||||
'file', IMAGE_ROOT + EVIL_PNG)])
|
# 'file', EVIL_PNG)])
|
||||||
|
|
||||||
context = util.TEMPLATE_TEST_CONTEXT['mediagoblin/submit/start.html']
|
#context = util.TEMPLATE_TEST_CONTEXT['mediagoblin/submit/start.html']
|
||||||
form = context['submit_form']
|
#form = context['submit_form']
|
||||||
assert form.file.errors == ['The file doesn\'t seem to be an image!']
|
#assert form.file.errors == ['The file doesn\'t seem to be an image!']
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user