@@ -12,6 +12,71 @@ OAuth authentication services.
1212This article explains the two most popular techniques to avoid these issues and
1313create fast tests when using authentication.
1414
15+ Improving Password Encoder Speed in Tests
16+ -----------------------------------------
17+
18+ By default, password encoders are resource intensive and take time. This is
19+ important to generate secure password hashes. In tests however, secure hashes
20+ are not important, waste resources and increase test times. You can reduce
21+ the *work factor * for your encoders by adding the following *only in your test
22+ environment *:
23+
24+ .. configuration-block ::
25+
26+ .. code-block :: yaml
27+
28+ # config/packages/test/security.yaml
29+ encoders :
30+ # Use your user class name here
31+ App\Entity\User :
32+ algorithm : auto # This should be the same value as in config/packages/security.yaml
33+ cost : 4 # Lowest possible value for bcrypt
34+ time_cost : 3 # Lowest possible value for argon
35+ memory_cost : 10 # Lowest possible value for argon
36+
37+ .. code-block :: xml
38+
39+ <!-- config/packages/test/security.xml -->
40+ <?xml version =" 1.0" encoding =" UTF-8" ?>
41+ <srv : container xmlns =" http://symfony.com/schema/dic/security"
42+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
43+ xmlns : srv =" http://symfony.com/schema/dic/services"
44+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
45+ https://symfony.com/schema/dic/services/services-1.0.xsd" >
46+
47+ <config >
48+ <!-- class: Use your user class name here -->
49+ <!-- algorithm: This should be the same value as in config/packages/security.yaml -->
50+ <!-- cost: Lowest possible value for bcrypt -->
51+ <!-- time_cost: Lowest possible value for argon -->
52+ <!-- memory_cost: Lowest possible value for argon -->
53+ <encoder
54+ class =" App\Entity\User"
55+ algorithm =" auto"
56+ cost =" 4"
57+ time_cost =" 3"
58+ memory_cost =" 10"
59+ />
60+ </config >
61+ </srv : container >
62+
63+ .. code-block :: php
64+
65+ // config/packages/test/security.php
66+ use App\Entity\User;
67+
68+ $container->loadFromExtension('security', [
69+ 'encoders' => [
70+ // Use your user class name here
71+ User::class => [
72+ 'algorithm' => 'auto', // This should be the same value as in config/packages/security.yaml
73+ 'cost' => 4, // Lowest possible value for bcrypt
74+ 'time_cost' => 3, // Lowest possible value for argon
75+ 'memory_cost' => 10, // Lowest possible value for argon
76+ ]
77+ ],
78+ ]);
79+
1580 Using a Faster Authentication Mechanism Only for Tests
1681------------------------------------------------------
1782
0 commit comments