Internal Server Error if 'Sync URL' Setting has a preceding whitespace (or is not a URL)

Bug #1499062 reported by Andres Rodriguez on 2015-09-23
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
MAAS
Critical
Jeffrey C Jones

Bug Description

2015-09-23 16:06:35 [HTTPChannel,439,127.0.0.1] 500 Error - /MAAS/settings/
        Traceback (most recent call last):
          File "/usr/lib/django16/django/core/handlers/wsgi.py", line 206, in __call__
            response = self.get_response(request)
          File "/usr/lib/python2.7/dist-packages/maasserver/utils/views.py", line 236, in get_response
            response = get_response(request)
          File "/usr/lib/python2.7/dist-packages/maasserver/utils/views.py", line 210, in get_response
            return django_get_response(request)
          File "/usr/lib/django16/django/core/handlers/base.py", line 194, in get_response
            response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
        --- <exception caught here> ---
          File "/usr/lib/django16/django/core/handlers/base.py", line 112, in get_response
            response = wrapped_callback(request, *callback_args, **callback_kwargs)
          File "/usr/lib/python2.7/dist-packages/maasserver/utils/views.py", line 189, in view_atomic_with_post_commit_savepoint
            return view_atomic(*args, **kwargs)
          File "/usr/lib/django16/django/db/transaction.py", line 371, in inner
            return func(*args, **kwargs)
          File "/usr/lib/django16/django/contrib/auth/decorators.py", line 22, in _wrapped_view
            return view_func(request, *args, **kwargs)
          File "/usr/lib/python2.7/dist-packages/maasserver/views/settings.py", line 205, in settings
            'boot_source', "Configuration updated.")
          File "/usr/lib/python2.7/dist-packages/maasserver/views/__init__.py", line 219, in process_form
            form.save()
          File "/usr/lib/python2.7/dist-packages/maasserver/forms.py", line 1435, in save
            boot_source.save()
          File "/usr/lib/python2.7/dist-packages/maasserver/models/cleansave.py", line 37, in save
            self.full_clean()
          File "/usr/lib/django16/django/db/models/base.py", line 950, in full_clean
            raise ValidationError(errors)
        django.core.exceptions.ValidationError: {'url': [u'Enter a valid URL.']}

Related branches

Changed in maas:
milestone: none → 1.9.0
importance: Undecided → Critical
status: New → Confirmed
Changed in maas:
status: Confirmed → In Progress
assignee: nobody → Jeffrey C Jones (trapnine)
summary: - Internal Server Error if 'Sync URL' Setting has a preseeding whitespace
+ Internal Server Error if 'Sync URL' Setting has a preceding whitespace

BootSourceSettings Model uses URLField and BootSourceSettingsForm does not (it uses CharField, which can be any string). So the form doesn't strip() nor does it check for URL formatting, then it tries to save() it into the Model and boom.

As an aside: I've noticed our Forms don't use any 'stripping' CharField (the default CharField doesn't do it for obvious reasons). Many of our string form fields SHOULD strip surrounding whitespace, since many of them are file paths, names, etc. Non-stripped whitespace could cause lots of problems, and even if it is user error, we should use the forms to clean these inputs up.

I've created and employed one for the other field on this Form (boot_source_keyring, since it's a file path and shouldn't start or end with spaces).

summary: Internal Server Error if 'Sync URL' Setting has a preceding whitespace
+ (or is not a URL)
Changed in maas:
status: In Progress → Fix Committed
Changed in maas:
status: Fix Committed → Fix Released
no longer affects: maas/1.8
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers