1717use Symfony \Bundle \SecurityBundle \DependencyInjection \Security \Factory \FirewallListenerFactoryInterface ;
1818use Symfony \Bundle \SecurityBundle \DependencyInjection \SecurityExtension ;
1919use Symfony \Bundle \SecurityBundle \SecurityBundle ;
20- use Symfony \Bundle \SecurityBundle \Tests \DependencyInjection \Fixtures \UserProvider \DummyProvider ;
20+ use Symfony \Bundle \SecurityBundle \Tests \DependencyInjection \Fixtures \UserProviderFactory \CustomProviderFactory ;
21+ use Symfony \Bundle \SecurityBundle \Tests \DependencyInjection \Fixtures \UserProviderFactory \DummyProviderFactory ;
2122use Symfony \Component \Config \Definition \Builder \NodeDefinition ;
2223use Symfony \Component \Config \Definition \Exception \InvalidConfigurationException ;
2324use Symfony \Component \DependencyInjection \Argument \IteratorArgument ;
@@ -68,16 +69,80 @@ public function testInvalidCheckPath()
6869 $ container ->compile ();
6970 }
7071
72+ public function testFirewallWithCustomUserProvider ()
73+ {
74+ $ container = $ this ->getRawContainer ();
75+
76+ $ extension = $ container ->getExtension ('security ' );
77+ $ extension ->addUserProviderFactory (new CustomProviderFactory ());
78+
79+ $ container ->loadFromExtension ('security ' , [
80+ 'providers ' => [
81+ 'my_app_provider ' => [
82+ 'custom ' => [
83+ 'foo ' => 'baz ' ,
84+ ],
85+ ],
86+ ],
87+
88+ 'firewalls ' => [
89+ 'some_firewall ' => [
90+ 'pattern ' => '/.* ' ,
91+ 'http_basic ' => [],
92+ ],
93+ ],
94+ ]);
95+
96+ $ container ->compile ();
97+
98+ $ this ->assertTrue ($ container ->hasDefinition ('security.user.provider.concrete.my_app_provider ' ));
99+ $ this ->assertEquals ('baz ' , $ container ->getDefinition ('security.user.provider.concrete.my_app_provider ' )->getArgument ('$foo ' ));
100+ }
101+
71102 public function testFirewallWithInvalidUserProvider ()
72103 {
73104 $ container = $ this ->getRawContainer ();
74105
75106 $ extension = $ container ->getExtension ('security ' );
76- $ extension ->addUserProviderFactory (new DummyProvider ());
107+ $ extension ->addUserProviderFactory (new CustomProviderFactory ());
108+
109+ $ container ->loadFromExtension ('security ' , [
110+ 'providers ' => [
111+ 'my_app_provider ' => [
112+ 'some_other ' => [
113+ 'bar ' => 'baz ' ,
114+ ],
115+ ],
116+ ],
117+
118+ 'firewalls ' => [
119+ 'some_firewall ' => [
120+ 'pattern ' => '/.* ' ,
121+ 'http_basic ' => [],
122+ ],
123+ ],
124+ ]);
125+
126+ $ this ->expectException (InvalidConfigurationException::class);
127+ $ this ->expectExceptionMessage ('Unrecognized option "some_other" under "security.providers.my_app_provider". Available options are "chain", "custom", "id", "ldap", "memory". ' );
128+
129+ $ container ->compile ();
130+ }
131+
132+ public function testFirewallWithInvalidUserProviderConfig ()
133+ {
134+ $ container = $ this ->getRawContainer ();
135+
136+ $ extension = $ container ->getExtension ('security ' );
137+ $ extension ->addUserProviderFactory (new CustomProviderFactory ());
77138
78139 $ container ->loadFromExtension ('security ' , [
79140 'providers ' => [
80- 'my_foo ' => ['foo ' => []],
141+ 'my_app_provider ' => [
142+ 'custom ' => [
143+ 'bar ' => 'baz ' ,
144+ ],
145+ ],
81146 ],
82147
83148 'firewalls ' => [
@@ -89,9 +154,42 @@ public function testFirewallWithInvalidUserProvider()
89154 ]);
90155
91156 $ this ->expectException (InvalidConfigurationException::class);
92- $ this ->expectExceptionMessage ('Unable to create definition for "security.user.provider.concrete.my_foo" user provider ' );
157+ $ this ->expectExceptionMessage ('Unrecognized option "bar" under "security.providers.my_app_provider.custom". Available option is "foo". ' );
158+
159+ $ container ->compile ();
160+ }
161+
162+ public function testFirewallWithUserProviderWithoutConfig ()
163+ {
164+ $ container = $ this ->getRawContainer ();
165+
166+ $ extension = $ container ->getExtension ('security ' );
167+ $ extension ->addUserProviderFactory (new DummyProviderFactory ());
168+
169+ $ container ->loadFromExtension ('security ' , [
170+ 'providers ' => [
171+ 'my_app_provider ' => [
172+ 'foo ' => null ,
173+ ],
174+ 'my_other_app_provider ' => [
175+ 'foo ' => [],
176+ ],
177+ ],
178+
179+ 'firewalls ' => [
180+ 'some_firewall ' => [
181+ 'pattern ' => '/.* ' ,
182+ 'http_basic ' => [
183+ 'provider ' => 'my_app_provider ' ,
184+ ],
185+ ],
186+ ],
187+ ]);
93188
94189 $ container ->compile ();
190+
191+ $ this ->assertTrue ($ container ->hasDefinition ('security.user.provider.concrete.my_app_provider ' ));
192+ $ this ->assertTrue ($ container ->hasDefinition ('security.user.provider.concrete.my_other_app_provider ' ));
95193 }
96194
97195 public function testDisableRoleHierarchyVoter ()
0 commit comments