@@ -12,6 +12,66 @@ 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
+
30
+ encoders :
31
+ # use your user class name here
32
+ App\Entity\User :
33
+ # This should be the same value as in config/packages/security.yaml
34
+ algorithm : auto
35
+ cost : 4 # Lowest possible value for bcrypt
36
+ time_cost : 3 # Lowest possible value for argon
37
+ memory_cost : 10 # Lowest possible value for argon
38
+
39
+ .. code-block :: xml
40
+
41
+ <!-- config/packages/test/security.xml -->
42
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
43
+ <srv : container xmlns =" http://symfony.com/schema/dic/security"
44
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
45
+ xmlns : srv =" http://symfony.com/schema/dic/services"
46
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
47
+ https://symfony.com/schema/dic/services/services-1.0.xsd" >
48
+
49
+ <config >
50
+ <encoder class =" App\Entity\User"
51
+ algorithm =" auto"
52
+ cost =" 4"
53
+ time_cost =" 3"
54
+ memory_cost =" 10"
55
+ />
56
+ </config >
57
+ </srv : container >
58
+
59
+ .. code-block :: php
60
+
61
+ // config/packages/test/security.php
62
+ use App\Entity\User;
63
+
64
+ $container->loadFromExtension('security', [
65
+ 'encoders' => [
66
+ User::class => [
67
+ 'algorithm' => 'auto',
68
+ 'cost' => 4,
69
+ 'time_cost' => 3,
70
+ 'memory_cost' => 10,
71
+ ]
72
+ ],
73
+ ]);
74
+
15
75
Using a Faster Authentication Mechanism Only for Tests
16
76
------------------------------------------------------
17
77
0 commit comments