Ticket #17944: 17944.3.patch

File 17944.3.patch, 7.6 KB (added by Aymeric Augustin, 12 years ago)
  • django/contrib/auth/tests/forms.py

     
    6565
    6666    def test_success(self):
    6767        # The success case.
    68 
    6968        data = {
    7069            'username': 'jsmith@example.com',
    7170            'password1': 'test123',
     
    236235        # Just check we can create it
    237236        form = MyUserForm({})
    238237
     238    def test_bug_17944_empty_password(self):
     239        user = User.objects.get(username='empty_password')
     240        form = UserChangeForm(instance=user)
     241        # Just check that no error is raised.
     242        form.as_table()
     243
     244    def test_bug_17944_unmanageable_password(self):
     245        user = User.objects.get(username='unmanageable_password')
     246        form = UserChangeForm(instance=user)
     247        # Just check that no error is raised.
     248        form.as_table()
     249
     250    def test_bug_17944_unknown_password_algorithm(self):
     251        user = User.objects.get(username='unknown_password')
     252        form = UserChangeForm(instance=user)
     253        # Just check that no error is raised.
     254        form.as_table()
     255
     256
    239257UserChangeFormTest = override_settings(USE_TZ=False)(UserChangeFormTest)
    240258
    241259
  • django/contrib/auth/fixtures/authtestdata.json

     
    11[
    22    {
    3         "pk": "1", 
    4         "model": "auth.user", 
     3        "pk": "1",
     4        "model": "auth.user",
    55        "fields": {
    6             "username": "testclient", 
    7             "first_name": "Test", 
    8             "last_name": "Client", 
    9             "is_active": true, 
    10             "is_superuser": false, 
    11             "is_staff": false, 
    12             "last_login": "2006-12-17 07:03:31", 
    13             "groups": [], 
    14             "user_permissions": [], 
    15             "password": "sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161", 
    16             "email": "testclient@example.com", 
     6            "username": "testclient",
     7            "first_name": "Test",
     8            "last_name": "Client",
     9            "is_active": true,
     10            "is_superuser": false,
     11            "is_staff": false,
     12            "last_login": "2006-12-17 07:03:31",
     13            "groups": [],
     14            "user_permissions": [],
     15            "password": "sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161",
     16            "email": "testclient@example.com",
    1717            "date_joined": "2006-12-17 07:03:31"
    1818        }
    1919    },
    2020    {
    21         "pk": "2", 
    22         "model": "auth.user", 
     21        "pk": "2",
     22        "model": "auth.user",
    2323        "fields": {
    24             "username": "inactive", 
    25             "first_name": "Inactive", 
    26             "last_name": "User", 
    27             "is_active": false, 
    28             "is_superuser": false, 
    29             "is_staff": false, 
    30             "last_login": "2006-12-17 07:03:31", 
    31             "groups": [], 
    32             "user_permissions": [], 
    33             "password": "sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161", 
     24            "username": "inactive",
     25            "first_name": "Inactive",
     26            "last_name": "User",
     27            "is_active": false,
     28            "is_superuser": false,
     29            "is_staff": false,
     30            "last_login": "2006-12-17 07:03:31",
     31            "groups": [],
     32            "user_permissions": [],
     33            "password": "sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161",
    3434            "email": "testclient2@example.com",
    3535            "date_joined": "2006-12-17 07:03:31"
    3636        }
    3737    },
    3838    {
    39         "pk": "3", 
    40         "model": "auth.user", 
     39        "pk": "3",
     40        "model": "auth.user",
    4141        "fields": {
    42             "username": "staff", 
    43             "first_name": "Staff", 
    44             "last_name": "Member", 
    45             "is_active": true, 
    46             "is_superuser": false, 
    47             "is_staff": true, 
    48             "last_login": "2006-12-17 07:03:31", 
    49             "groups": [], 
    50             "user_permissions": [], 
    51             "password": "sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161", 
    52             "email": "staffmember@example.com", 
     42            "username": "staff",
     43            "first_name": "Staff",
     44            "last_name": "Member",
     45            "is_active": true,
     46            "is_superuser": false,
     47            "is_staff": true,
     48            "last_login": "2006-12-17 07:03:31",
     49            "groups": [],
     50            "user_permissions": [],
     51            "password": "sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161",
     52            "email": "staffmember@example.com",
    5353            "date_joined": "2006-12-17 07:03:31"
    5454        }
     55    },
     56    {
     57        "pk": "4",
     58        "model": "auth.user",
     59        "fields": {
     60            "username": "empty_password",
     61            "first_name": "Empty",
     62            "last_name": "Password",
     63            "is_active": true,
     64            "is_superuser": false,
     65            "is_staff": false,
     66            "last_login": "2006-12-17 07:03:31",
     67            "groups": [],
     68            "user_permissions": [],
     69            "password": "",
     70            "email": "empty_password@example.com",
     71            "date_joined": "2006-12-17 07:03:31"
     72        }
     73    },
     74    {
     75        "pk": "5",
     76        "model": "auth.user",
     77        "fields": {
     78            "username": "unmanageable_password",
     79            "first_name": "Unmanageable",
     80            "last_name": "Password",
     81            "is_active": true,
     82            "is_superuser": false,
     83            "is_staff": false,
     84            "last_login": "2006-12-17 07:03:31",
     85            "groups": [],
     86            "user_permissions": [],
     87            "password": "$",
     88            "email": "unmanageable_password@example.com",
     89            "date_joined": "2006-12-17 07:03:31"
     90        }
     91    },
     92    {
     93        "pk": "6",
     94        "model": "auth.user",
     95        "fields": {
     96            "username": "unknown_password",
     97            "first_name": "Unknown",
     98            "last_name": "Password",
     99            "is_active": true,
     100            "is_superuser": false,
     101            "is_staff": false,
     102            "last_login": "2006-12-17 07:03:31",
     103            "groups": [],
     104            "user_permissions": [],
     105            "password": "foo$bar",
     106            "email": "unknown_password@example.com",
     107            "date_joined": "2006-12-17 07:03:31"
     108        }
    55109    }
    56110]
  • django/contrib/auth/forms.py

     
    2929        encoded = smart_str(encoded)
    3030
    3131        if len(encoded) == 32 and '$' not in encoded:
    32             hasher = get_hasher('unsalted_md5')
     32            algorithm = 'unsalted_md5'
    3333        else:
    3434            algorithm = encoded.split('$', 1)[0]
     35
     36        try:
    3537            hasher = get_hasher(algorithm)
     38        except ValueError:
     39            summary = "<strong>%s</strong>" % ugettext("Invalid password format or unknown hashing algorithm.")
     40        else:
     41            summary = ""
     42            for key, value in hasher.safe_summary(encoded).iteritems():
     43                summary += "<strong>%(key)s</strong>: %(value)s " % {"key": ugettext(key), "value": value}
    3644
    37         summary = ""
    38         for key, value in hasher.safe_summary(encoded).iteritems():
    39             summary += "<strong>%(key)s</strong>: %(value)s " % {"key": ugettext(key), "value": value}
    40 
    4145        return mark_safe("<div%(attrs)s>%(summary)s</div>" % {"attrs": flatatt(final_attrs), "summary": summary})
    4246
    4347
Back to Top