summaryrefslogtreecommitdiff
path: root/tests/modeltests/validation
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2011-09-10 01:08:24 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2011-09-10 01:08:24 +0000
commit1a76dbefdfc60e2d5954c0ba614c3d054ba9c3f0 (patch)
tree053c60d65b333df990de1250af0085ec75baf953 /tests/modeltests/validation
parentfbe2eead2fa9d808658ca582241bcacb02618840 (diff)
[1.3.X] Altered the behavior of URLField to avoid a potential DOS vector, and to avoid potential leakage of local filesystem data. A security announcement will be made shortly.
Backport of r16760 from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.3.X@16763 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/modeltests/validation')
-rw-r--r--tests/modeltests/validation/__init__.py4
-rw-r--r--tests/modeltests/validation/models.py1
-rw-r--r--tests/modeltests/validation/tests.py23
3 files changed, 13 insertions, 15 deletions
diff --git a/tests/modeltests/validation/__init__.py b/tests/modeltests/validation/__init__.py
index c8a89cd36f..31c5000ba6 100644
--- a/tests/modeltests/validation/__init__.py
+++ b/tests/modeltests/validation/__init__.py
@@ -1,8 +1,8 @@
-from django.utils import unittest
+from django.test import TestCase
from django.core.exceptions import ValidationError
-class ValidationTestCase(unittest.TestCase):
+class ValidationTestCase(TestCase):
def assertFailsValidation(self, clean, failed_fields):
self.assertRaises(ValidationError, clean)
try:
diff --git a/tests/modeltests/validation/models.py b/tests/modeltests/validation/models.py
index 861d1440fe..91ad87203d 100644
--- a/tests/modeltests/validation/models.py
+++ b/tests/modeltests/validation/models.py
@@ -15,6 +15,7 @@ class ModelToValidate(models.Model):
parent = models.ForeignKey('self', blank=True, null=True, limit_choices_to={'number': 10})
email = models.EmailField(blank=True)
url = models.URLField(blank=True)
+ url_verify = models.URLField(blank=True, verify_exists=True)
f_with_custom_validator = models.IntegerField(blank=True, null=True, validators=[validate_answer_to_universe])
def clean(self):
diff --git a/tests/modeltests/validation/tests.py b/tests/modeltests/validation/tests.py
index 4236d8e7c4..eaf130be29 100644
--- a/tests/modeltests/validation/tests.py
+++ b/tests/modeltests/validation/tests.py
@@ -53,25 +53,22 @@ class BaseModelValidationTests(ValidationTestCase):
mtv = ModelToValidate(number=10, name='Some Name', url='not a url')
self.assertFieldFailsValidationWithMessage(mtv.full_clean, 'url', [u'Enter a valid value.'])
+ #The tests below which use url_verify are deprecated
def test_correct_url_but_nonexisting_gives_404(self):
- mtv = ModelToValidate(number=10, name='Some Name', url='http://google.com/we-love-microsoft.html')
- self.assertFieldFailsValidationWithMessage(mtv.full_clean, 'url', [u'This URL appears to be a broken link.'])
+ mtv = ModelToValidate(number=10, name='Some Name', url_verify='http://qa-dev.w3.org/link-testsuite/http.php?code=404')
+ self.assertFieldFailsValidationWithMessage(mtv.full_clean, 'url_verify', [u'This URL appears to be a broken link.'])
def test_correct_url_value_passes(self):
- mtv = ModelToValidate(number=10, name='Some Name', url='http://www.example.com/')
+ mtv = ModelToValidate(number=10, name='Some Name', url_verify='http://www.google.com/')
self.assertEqual(None, mtv.full_clean()) # This will fail if there's no Internet connection
- def test_correct_https_url_but_nonexisting(self):
- mtv = ModelToValidate(number=10, name='Some Name', url='https://www.example.com/')
- self.assertFieldFailsValidationWithMessage(mtv.full_clean, 'url', [u'This URL appears to be a broken link.'])
-
- def test_correct_ftp_url_but_nonexisting(self):
- mtv = ModelToValidate(number=10, name='Some Name', url='ftp://ftp.google.com/we-love-microsoft.html')
- self.assertFieldFailsValidationWithMessage(mtv.full_clean, 'url', [u'This URL appears to be a broken link.'])
+ def test_correct_url_with_redirect(self):
+ mtv = ModelToValidate(number=10, name='Some Name', url_verify='http://qa-dev.w3.org/link-testsuite/http.php?code=301') #example.com is a redirect to iana.org now
+ self.assertEqual(None, mtv.full_clean()) # This will fail if there's no Internet connection
- def test_correct_ftps_url_but_nonexisting(self):
- mtv = ModelToValidate(number=10, name='Some Name', url='ftps://ftp.google.com/we-love-microsoft.html')
- self.assertFieldFailsValidationWithMessage(mtv.full_clean, 'url', [u'This URL appears to be a broken link.'])
+ def test_correct_https_url_but_nonexisting(self):
+ mtv = ModelToValidate(number=10, name='Some Name', url_verify='https://www.example.com/')
+ self.assertFieldFailsValidationWithMessage(mtv.full_clean, 'url_verify', [u'This URL appears to be a broken link.'])
def test_text_greater_that_charfields_max_length_raises_erros(self):
mtv = ModelToValidate(number=10, name='Some Name'*100)