1313#CoversClass(SimpleSAML\Module\sqlauth\Auth\Source\SQL::class)
1414class SQLTest extends TestCase
1515{
16- // Subclasses can override this to test other wrapper classes
17- protected string $ wrapperClassName = '\SimpleSAML\Test\Module\sqlauth\Auth\Source\SQLWrapper ' ;
18-
1916 /** @var array<string, string> */
2017 private array $ info = ['AuthId ' => 'testAuthId ' ];
2118
@@ -80,11 +77,21 @@ public static function setUpBeforeClass(): void
8077 }
8178
8279
80+ /**
81+ * @param array<mixed> $info
82+ * @param array<mixed> $config
83+ */
84+ protected function createWrapper (array $ info , array $ config ): WrapperInterface
85+ {
86+ return new SQLWrapper ($ info , $ config );
87+ }
88+
89+
8390 public function testBasicSingleSuccess (): void
8491 {
8592 // Correct username/password
8693 $ this ->config ['query ' ] = "select givenName, email from users where uid=:username and password=:password " ;
87- $ ret = ( new $ this ->wrapperClassName ($ this ->info , $ this ->config ) )->callLogin ('bob ' , 'password ' );
94+ $ ret = $ this ->createWrapper ($ this ->info , $ this ->config )->callLogin ('bob ' , 'password ' );
8895 asort ($ ret );
8996 $ this ->assertCount (2 , $ ret );
9097 $ this ->assertEquals ($ ret , [
@@ -99,7 +106,7 @@ public function testBasicSingleUsernameRegexSuccess(): void
99106 // Correct username/password
100107 $ this ->config ['query ' ] = "select givenName, email from users where uid=:username and password=:password " ;
101108 $ this ->config ['username_regex ' ] = '/^[a-z]+$/ ' ; // Username must be a single lower case word
102- $ ret = ( new $ this ->wrapperClassName ($ this ->info , $ this ->config ) )->callLogin ('bob ' , 'password ' );
109+ $ ret = $ this ->createWrapper ($ this ->info , $ this ->config )->callLogin ('bob ' , 'password ' );
103110 asort ($ ret );
104111 $ this ->assertCount (2 , $ ret );
105112 $ this ->assertEquals ($ ret , [
@@ -115,7 +122,7 @@ public function testBasicSingleUsernameRegexFailedLogin(): void
115122 // Correct username/password, but doesn't match the username regex
116123 $ this ->config ['query ' ] = "select givenName, email from users where uid=:username and password=:password " ;
117124 $ this ->config ['username_regex ' ] = '/^\d+$/ ' ; // Username must be a non-negative integer
118- $ ret = ( new $ this ->wrapperClassName ($ this ->info , $ this ->config ) )->callLogin ('bob ' , 'password ' );
125+ $ ret = $ this ->createWrapper ($ this ->info , $ this ->config )->callLogin ('bob ' , 'password ' );
119126 asort ($ ret );
120127 $ this ->assertCount (0 , $ ret );
121128 }
@@ -127,7 +134,7 @@ public function testBasicSingleUsernameRegexFailedLoginNonExistingUser(): void
127134 // Correct username/password, but doesn't match the username regex
128135 $ this ->config ['query ' ] = "select givenName, email from users where uid=:username and password=:password " ;
129136 $ this ->config ['username_regex ' ] = '/^\d+$/ ' ; // Username must be a non-negative integer
130- $ ret = ( new $ this ->wrapperClassName ($ this ->info , $ this ->config ) )->callLogin ('henry ' , 'password ' );
137+ $ ret = $ this ->createWrapper ($ this ->info , $ this ->config )->callLogin ('henry ' , 'password ' );
131138 asort ($ ret );
132139 $ this ->assertCount (0 , $ ret );
133140 }
@@ -138,7 +145,7 @@ public function testBasicSingleFailedLogin(): void
138145 $ this ->expectException (\SimpleSAML \Error \Error::class);
139146 // Wrong username/password
140147 $ this ->config ['query ' ] = "select givenName, email from users where uid=:username and password=:password " ;
141- $ ret = ( new $ this ->wrapperClassName ($ this ->info , $ this ->config ) )->callLogin ('alice ' , 'wrong ' );
148+ $ ret = $ this ->createWrapper ($ this ->info , $ this ->config )->callLogin ('alice ' , 'wrong ' );
142149 $ this ->assertCount (0 , $ ret );
143150 }
144151
@@ -149,10 +156,10 @@ public function testJoinSingleSuccess(): void
149156 $ this ->config ['query ' ] = "
150157 select u.givenName, u.email, ug.groupname
151158 from users u left join usergroups ug on (u.uid=ug.uid)
152- where u.uid=:username and u.password=:password " ;
153- $ ret = (new $ this ->wrapperClassName ($ this ->info , $ this ->config ))->callLogin ('bob ' , 'password ' );
159+ where u.uid=:username and u.password=:password
160+ order by ug.groupname " ;
161+ $ ret = $ this ->createWrapper ($ this ->info , $ this ->config )->callLogin ('bob ' , 'password ' );
154162 asort ($ ret );
155- asort ($ ret ['groupname ' ]);
156163 $ this ->assertCount (3 , $ ret );
157164 $ this ->assertEquals ($ ret , [
158165 'email ' => ['bob@example.com ' ],
@@ -170,7 +177,7 @@ public function testJoinSingleFailedLogin(): void
170177 select u.givenName, u.email, ug.groupname
171178 from users u left join usergroups ug on (u.uid=ug.uid)
172179 where u.uid=:username and u.password=:password " ;
173- $ ret = ( new $ this ->wrapperClassName ($ this ->info , $ this ->config ) )->callLogin ('alice ' , 'wrong ' );
180+ $ ret = $ this ->createWrapper ($ this ->info , $ this ->config )->callLogin ('alice ' , 'wrong ' );
174181 $ this ->assertCount (0 , $ ret );
175182 }
176183
@@ -180,11 +187,10 @@ public function testMultiQuerySuccess(): void
180187 // Correct username/password
181188 $ this ->config ['query ' ] = [
182189 "select givenName, email from users where uid=:username and password=:password " ,
183- "select groupname from usergroups where uid=:username " ,
190+ "select groupname from usergroups where uid=:username order by groupname " ,
184191 ];
185- $ ret = ( new $ this ->wrapperClassName ($ this ->info , $ this ->config ) )->callLogin ('bob ' , 'password ' );
192+ $ ret = $ this ->createWrapper ($ this ->info , $ this ->config )->callLogin ('bob ' , 'password ' );
186193 asort ($ ret );
187- asort ($ ret ['groupname ' ]);
188194 $ this ->assertCount (3 , $ ret );
189195 $ this ->assertEquals ($ ret , [
190196 'email ' => ['bob@example.com ' ],
@@ -202,7 +208,7 @@ public function testMultiQueryFailedLogin(): void
202208 "select givenName, email from users where uid=:username and password=:password " ,
203209 "select groupname from usergroups where uid=:username " ,
204210 ];
205- $ ret = ( new $ this ->wrapperClassName ($ this ->info , $ this ->config ) )->callLogin ('alice ' , 'wrong ' );
211+ $ ret = $ this ->createWrapper ($ this ->info , $ this ->config )->callLogin ('alice ' , 'wrong ' );
206212 $ this ->assertCount (0 , $ ret );
207213 }
208214
@@ -212,12 +218,11 @@ public function testMultiQuerySubsequentNoRowsSuccess(): void
212218 // Correct username/password. Second query returns no rows, third query returns just one row
213219 $ this ->config ['query ' ] = [
214220 "select givenName, email from users where uid=:username and password=:password " ,
215- "select groupname from usergroups where uid=:username and groupname like '%nomatch%' " ,
216- "select groupname from usergroups where uid=:username and groupname like 'stud%' " ,
221+ "select groupname from usergroups where uid=:username and groupname like '%nomatch%' order by groupname " ,
222+ "select groupname from usergroups where uid=:username and groupname like 'stud%' order by groupname " ,
217223 ];
218- $ ret = ( new $ this ->wrapperClassName ($ this ->info , $ this ->config ) )->callLogin ('bob ' , 'password ' );
224+ $ ret = $ this ->createWrapper ($ this ->info , $ this ->config )->callLogin ('bob ' , 'password ' );
219225 asort ($ ret );
220- asort ($ ret ['groupname ' ]);
221226 $ this ->assertCount (3 , $ ret );
222227 $ this ->assertEquals ($ ret , [
223228 'email ' => ['bob@example.com ' ],
@@ -232,12 +237,11 @@ public function testMultiQuerySubsequentAppendSuccess(): void
232237 // Correct username/password. Second query returns a row, third query appends one row
233238 $ this ->config ['query ' ] = [
234239 "select givenName, email from users where uid=:username and password=:password " ,
235- "select groupname from usergroups where uid=:username and groupname like 'stud%' " ,
236- "select groupname from usergroups where uid=:username and groupname like '%sers' " ,
240+ "select groupname from usergroups where uid=:username and groupname like 'stud%' order by groupname " ,
241+ "select groupname from usergroups where uid=:username and groupname like '%sers' order by groupname " ,
237242 ];
238- $ ret = ( new $ this ->wrapperClassName ($ this ->info , $ this ->config ) )->callLogin ('bob ' , 'password ' );
243+ $ ret = $ this ->createWrapper ($ this ->info , $ this ->config )->callLogin ('bob ' , 'password ' );
239244 asort ($ ret );
240- asort ($ ret ['groupname ' ]);
241245 $ this ->assertCount (3 , $ ret );
242246 $ this ->assertEquals ($ ret , [
243247 'email ' => ['bob@example.com ' ],
0 commit comments