13
13
14
14
namespace FOS \OAuthServerBundle \Tests \DependencyInjection ;
15
15
16
+ use FOS \OAuthServerBundle \DependencyInjection \FOSOAuthServerExtension ;
17
+ use Symfony \Component \Config \Definition \Exception \InvalidConfigurationException ;
16
18
use Symfony \Component \Config \FileLocator ;
19
+ use Symfony \Component \DependencyInjection \ContainerBuilder ;
20
+ use Symfony \Component \DependencyInjection \ParameterBag \ParameterBag ;
17
21
use Symfony \Component \Routing \Loader \XmlFileLoader ;
18
22
19
23
class FOSOAuthServerExtensionTest extends \PHPUnit \Framework \TestCase
20
24
{
25
+ private $ container ;
26
+
27
+ public function setUp ()
28
+ {
29
+ $ parameterBag = new ParameterBag ();
30
+ $ this ->container = new ContainerBuilder ($ parameterBag );
31
+
32
+ parent ::setUp ();
33
+ }
34
+
21
35
public function testLoadAuthorizeRouting ()
22
36
{
23
37
$ locator = new FileLocator ();
@@ -39,4 +53,103 @@ public function testLoadTokenRouting()
39
53
$ this ->assertSame ('/oauth/v2/token ' , $ tokenRoute ->getPath ());
40
54
$ this ->assertSame (['GET ' , 'POST ' ], $ tokenRoute ->getMethods ());
41
55
}
56
+
57
+ public function testWithoutService ()
58
+ {
59
+ $ config = [
60
+ 'db_driver ' => 'orm ' ,
61
+ 'client_class ' => 'dumb_class ' ,
62
+ 'access_token_class ' => 'dumb_access_token_class ' ,
63
+ 'refresh_token_class ' => 'dumb_refresh_token_class ' ,
64
+ 'auth_code_class ' => 'dumb_auth_code_class ' ,
65
+ ];
66
+ $ instance = new FOSOAuthServerExtension ();
67
+ $ instance ->load ([$ config ], $ this ->container );
68
+
69
+ $ this ->assertSame (
70
+ $ this ->container ->getParameter ('fos_oauth_server.server.options ' ),
71
+ []
72
+ );
73
+ }
74
+
75
+ public function testStringSupportedScopes ()
76
+ {
77
+ $ scopes = 'scope1 scope2 scope3 scope4 ' ;
78
+
79
+ $ config = [
80
+ 'db_driver ' => 'orm ' ,
81
+ 'client_class ' => 'dumb_class ' ,
82
+ 'access_token_class ' => 'dumb_access_token_class ' ,
83
+ 'refresh_token_class ' => 'dumb_refresh_token_class ' ,
84
+ 'auth_code_class ' => 'dumb_auth_code_class ' ,
85
+ 'service ' => [
86
+ 'options ' => [
87
+ 'supported_scopes ' => $ scopes ,
88
+ ],
89
+ ],
90
+ ];
91
+
92
+ $ instance = new FOSOAuthServerExtension ();
93
+ $ instance ->load ([$ config ], $ this ->container );
94
+
95
+ $ this ->assertSame (
96
+ $ this ->container ->getParameter ('fos_oauth_server.server.options ' ),
97
+ [
98
+ 'supported_scopes ' => 'scope1 scope2 scope3 scope4 ' ,
99
+ ]
100
+ );
101
+ }
102
+
103
+ public function testArraySupportedScopes ()
104
+ {
105
+ $ scopes = ['scope1 ' , 'scope2 ' , 'scope3 ' , 'scope4 ' ];
106
+
107
+ $ config = [
108
+ 'db_driver ' => 'orm ' ,
109
+ 'client_class ' => 'dumb_class ' ,
110
+ 'access_token_class ' => 'dumb_access_token_class ' ,
111
+ 'refresh_token_class ' => 'dumb_refresh_token_class ' ,
112
+ 'auth_code_class ' => 'dumb_auth_code_class ' ,
113
+ 'service ' => [
114
+ 'options ' => [
115
+ 'supported_scopes ' => $ scopes ,
116
+ 'enforce_redirect ' => true ,
117
+ ],
118
+ ],
119
+ ];
120
+ $ instance = new FOSOAuthServerExtension ();
121
+ $ instance ->load ([$ config ], $ this ->container );
122
+
123
+ $ this ->assertSame (
124
+ $ this ->container ->getParameter ('fos_oauth_server.server.options ' ),
125
+ [
126
+ 'supported_scopes ' => 'scope1 scope2 scope3 scope4 ' ,
127
+ 'enforce_redirect ' => true ,
128
+ ]
129
+ );
130
+ }
131
+
132
+ public function testArraySupportedScopesWithSpace ()
133
+ {
134
+ $ scopes = ['scope1 scope2 ' , 'scope3 ' , 'scope4 ' ];
135
+
136
+ $ config = [
137
+ 'db_driver ' => 'orm ' ,
138
+ 'client_class ' => 'dumb_class ' ,
139
+ 'access_token_class ' => 'dumb_access_token_class ' ,
140
+ 'refresh_token_class ' => 'dumb_refresh_token_class ' ,
141
+ 'auth_code_class ' => 'dumb_auth_code_class ' ,
142
+ 'service ' => [
143
+ 'options ' => [
144
+ 'supported_scopes ' => $ scopes ,
145
+ 'enforce_redirect ' => true ,
146
+ ],
147
+ ],
148
+ ];
149
+ $ instance = new FOSOAuthServerExtension ();
150
+
151
+ $ this ->expectException (InvalidConfigurationException::class);
152
+ $ this ->expectExceptionMessage ('The array notation for supported_scopes should not contain spaces in array items. Either use full array notation or use the string notation for supported_scopes. See https://git.io/vx1X0 for more informations. ' );
153
+ $ instance ->load ([$ config ], $ this ->container );
154
+ }
42
155
}
0 commit comments