authentik.core.tests.test_hash_password_command
Tests for hash_password management command.
1"""Tests for hash_password management command.""" 2 3from io import StringIO 4 5from django.contrib.auth.hashers import check_password 6from django.core.management import call_command 7from django.core.management.base import CommandError 8from django.test import TestCase 9 10 11class TestHashPasswordCommand(TestCase): 12 """Test hash_password management command.""" 13 14 def test_hash_password(self): 15 """Test hashing a password.""" 16 out = StringIO() 17 call_command("hash_password", "test123", stdout=out) 18 hashed = out.getvalue().strip() 19 20 self.assertTrue(hashed.startswith("pbkdf2_sha256$")) 21 self.assertTrue(check_password("test123", hashed)) 22 23 def test_hash_password_empty_fails(self): 24 """Test that empty password raises error.""" 25 with self.assertRaises(CommandError) as ctx: 26 call_command("hash_password", "") 27 28 self.assertIn("Password cannot be empty", str(ctx.exception))
class
TestHashPasswordCommand(django.test.testcases.TestCase):
12class TestHashPasswordCommand(TestCase): 13 """Test hash_password management command.""" 14 15 def test_hash_password(self): 16 """Test hashing a password.""" 17 out = StringIO() 18 call_command("hash_password", "test123", stdout=out) 19 hashed = out.getvalue().strip() 20 21 self.assertTrue(hashed.startswith("pbkdf2_sha256$")) 22 self.assertTrue(check_password("test123", hashed)) 23 24 def test_hash_password_empty_fails(self): 25 """Test that empty password raises error.""" 26 with self.assertRaises(CommandError) as ctx: 27 call_command("hash_password", "") 28 29 self.assertIn("Password cannot be empty", str(ctx.exception))
Test hash_password management command.
def
test_hash_password(self):
15 def test_hash_password(self): 16 """Test hashing a password.""" 17 out = StringIO() 18 call_command("hash_password", "test123", stdout=out) 19 hashed = out.getvalue().strip() 20 21 self.assertTrue(hashed.startswith("pbkdf2_sha256$")) 22 self.assertTrue(check_password("test123", hashed))
Test hashing a password.
def
test_hash_password_empty_fails(self):
24 def test_hash_password_empty_fails(self): 25 """Test that empty password raises error.""" 26 with self.assertRaises(CommandError) as ctx: 27 call_command("hash_password", "") 28 29 self.assertIn("Password cannot be empty", str(ctx.exception))
Test that empty password raises error.