Ejemplo n.º 1
0
    def test_update_password_hash(self):
        """Test if checking the password with an old hash automatically updates the hash."""

        hashers = ('django.contrib.auth.hashers.PBKDF2PasswordHasher', PASSWORD_HASHERS[0], )

        with self.settings(PASSWORD_HASHERS=hashers):
            load_hashers()
            resp = self.post('/users/%s/' % username1, {'password': password1, })
            self.assertEqual(resp.status_code, http_client.NO_CONTENT)
            u = user_backend.get(username=username1)
            self.assertTrue(u.password.startswith('pbkdf2_sha256$'))
Ejemplo n.º 2
0
    def test_base(self):
        with self.settings(PASSWORD_HASHERS=[self.hasher, ]):
            load_hashers(settings.PASSWORD_HASHERS)

            for password in PASSWORDS:
                orig = self.alt_hasher.encrypt(password)
                conv = self.converter.from_orig(orig)

                # see if we get a working hash:
                self.assertTrue(check_password(password, conv))

                # convert back and test with passlib:
                back = self.converter.to_orig(conv)
                self.assertEqual(orig, back)
    def test_check(self):
        with self.settings(PASSWORD_HASHERS=[self.path, ]):
            load_hashers(settings.PASSWORD_HASHERS)

            for password in PASSWORDS:
                encoded = make_password(password)
                self.assertTrue(check_password(password, encoded))

                # test to_orig, done here, to save a few hash-generations
                encoded_orig = self.hasher.to_orig(encoded)
                self.assertTrue(self.hasher.hasher.verify(password, encoded_orig))

                back = self.hasher.from_orig(encoded_orig)
                self.assertEqual(encoded, back)
Ejemplo n.º 4
0
    def test_check(self):
        with self.settings(PASSWORD_HASHERS=[self.path, ]):
            load_hashers(settings.PASSWORD_HASHERS)

            for password in PASSWORDS:
                encoded = make_password(password)
                self.assertTrue(check_password(password, encoded))

                # test safe_summary():
                summary = self.hasher.safe_summary(encoded)
                self.assertTrue(isinstance(summary, SortedDict))
                self.assertTrue(len(summary) >= 1)

                # test to_orig, done here, to save a few hash-generations
                encoded_orig = self.hasher.to_orig(encoded)
                self.assertTrue(self.hasher.hasher.verify(password, encoded_orig))

                back = self.hasher.from_orig(encoded_orig)
                self.assertEqual(encoded, back)
Ejemplo n.º 5
0
    def test_service_hashes(self):
        # test various passwords:
        path = os.path.join(self.base, 'services3.json')
        with capture() as (stdout, stderr):
            restauth_import([path])

            self.assertEqual(stderr.getvalue(), '')
            self.assertHasLine(stdout, '^Services:$')
            self.assertHasLine(stdout, '^\* new1.example.com: Set password from input data.$')
            self.assertHasLine(stdout, '^\* new2.example.com: Set password from input data.$')
            self.assertHasLine(stdout, '^\* new3.example.com: Set password from input data.$')

        with override_settings(PASSWORD_HASHERS=PASSWORD_HASHERS):
            load_hashers()
            self.assertTrue(Service.objects.get(
                username='******').check_password('12345678'))
            self.assertTrue(Service.objects.get(
                username='******').check_password('foobar'))
            self.assertTrue(Service.objects.get(
                username='******').check_password('foobar'))
        load_hashers()
Ejemplo n.º 6
0
    def test_service_hashes(self):
        # test various passwords:
        path = os.path.join(self.base, 'services3.json')
        with capture() as (stdout, stderr):
            restauth_import([path])

            self.assertEqual(stderr.getvalue(), '')
            self.assertHasLine(stdout, '^Services:$')
            self.assertHasLine(stdout, '^\* new1.example.com: Set password from input data.$')
            self.assertHasLine(stdout, '^\* new2.example.com: Set password from input data.$')
            self.assertHasLine(stdout, '^\* new3.example.com: Set password from input data.$')

        with override_settings(PASSWORD_HASHERS=PASSWORD_HASHERS):
            load_hashers()
            self.assertTrue(Service.objects.get(
                username='******').check_password('12345678'))
            self.assertTrue(Service.objects.get(
                username='******').check_password('foobar'))
            self.assertTrue(Service.objects.get(
                username='******').check_password('foobar'))
        load_hashers()
Ejemplo n.º 7
0
 def setUp(self):
     load_hashers(password_hashers=default_hashers)
Ejemplo n.º 8
0
 def setUp(self):
     load_hashers(password_hashers=default_hashers)
Ejemplo n.º 9
0
 def setUp(self):
     load_hashers()
Ejemplo n.º 10
0
 def setUpClass(cls):
     load_hashers(('django.contrib.auth.hashers.MD5PasswordHasher', ))
Ejemplo n.º 11
0
 def setUp(self):
     load_hashers()
Ejemplo n.º 12
0
 def setUp(self):
     # Required in Django 1.4, not in 1.5
     super(HashTestMixin, self).setUp()
     with self.settings(PASSWORD_HASHERS=self.hashers):
         load_hashers()
Ejemplo n.º 13
0
 def setUpClass(cls):
     load_hashers(('django.contrib.auth.hashers.MD5PasswordHasher', ))