@@ -12,6 +12,65 @@ OAuth authentication services.
12
12
This article explains the two most popular techniques to avoid these issues and
13
13
create fast tests when using authentication.
14
14
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
+ <encoder class =" App\Entity\User" <!-- Use your user class name here -->
49
+ algorithm="auto" <!-- This should be the same value as in config/packages/security.yaml -->
50
+ cost="4" <!-- Lowest possible value for bcrypt -->
51
+ time_cost="3" <!-- Lowest possible value for argon -->
52
+ memory_cost="10" <!-- Lowest possible value for argon -->
53
+ />
54
+ </config >
55
+ </srv : container >
56
+
57
+ .. code-block :: php
58
+
59
+ // config/packages/test/security.php
60
+ use App\Entity\User;
61
+
62
+ $container->loadFromExtension('security', [
63
+ 'encoders' => [
64
+ // Use your user class name here
65
+ User::class => [
66
+ 'algorithm' => 'auto', // This should be the same value as in config/packages/security.yaml
67
+ 'cost' => 4, // Lowest possible value for bcrypt
68
+ 'time_cost' => 3, // Lowest possible value for argon
69
+ 'memory_cost' => 10, // Lowest possible value for argon
70
+ ]
71
+ ],
72
+ ]);
73
+
15
74
Using a Faster Authentication Mechanism Only for Tests
16
75
------------------------------------------------------
17
76
0 commit comments