33namespace Simplesamlphp \Casserver ;
44
55use DOMDocument ;
6+ use PHPUnit \Framework \TestCase ;
67use SimpleSAML \Test \BuiltInServer ;
78
89/**
1314 *
1415 * @package Simplesamlphp\Casserver
1516 */
16- class LoginIntegrationTest extends \ PHPUnit \ Framework \ TestCase
17+ class LoginIntegrationTest extends TestCase
1718{
1819 /** @var string $LINK_URL */
1920 private static $ LINK_URL = '/module.php/casserver/login.php ' ;
2021
22+ /** @var string $VALIDATE_URL */
23+ private static $ VALIDATE_URL = '/module.php/casserver/serviceValidate.php ' ;
24+
2125 /**
2226 * @var string $SAMLVALIDATE_URL
2327 */
@@ -129,10 +133,13 @@ public function testWrongServiceUrl()
129133
130134
131135 /**
132- * test a valid service URL
136+ * Test a valid service URL
137+ * @dataProvider validServiceUrlProvider
138+ * @param string $serviceParam The name of the query parameter to use for the service url
139+ * @param string $ticketParam The name of the query parameter that will contain the ticket
133140 * @return void
134141 */
135- public function testValidServiceUrl ()
142+ public function testValidServiceUrl (string $ serviceParam , string $ ticketParam )
136143 {
137144 $ service_url = 'http://host1.domain:1234/path1 ' ;
138145
@@ -141,7 +148,7 @@ public function testValidServiceUrl()
141148 /** @var array $resp */
142149 $ resp = $ this ->server ->get (
143150 self ::$ LINK_URL ,
144- [' service ' => $ service_url ],
151+ [$ serviceParam => $ service_url ],
145152 [
146153 CURLOPT_COOKIEJAR => $ this ->cookies_file ,
147154 CURLOPT_COOKIEFILE => $ this ->cookies_file
@@ -150,7 +157,71 @@ public function testValidServiceUrl()
150157 $ this ->assertEquals (302 , $ resp ['code ' ]);
151158
152159 $ this ->assertStringStartsWith (
153- $ service_url . '?ticket=ST- ' ,
160+ $ service_url . '? ' . $ ticketParam . '=ST- ' ,
161+ $ resp ['headers ' ]['Location ' ],
162+ 'Ticket should be part of the redirect. '
163+ );
164+
165+ // Config ticket can be validated
166+ $ matches = [];
167+ $ this ->assertEquals (1 , preg_match ("@ $ ticketParam=(.*)@ " , $ resp ['headers ' ]['Location ' ], $ matches ));
168+ $ ticket = $ matches [1 ];
169+ $ resp = $ this ->server ->get (
170+ self ::$ VALIDATE_URL ,
171+ [
172+ $ serviceParam => $ service_url ,
173+ 'ticket ' => $ ticket ,
174+ ],
175+ [
176+ CURLOPT_COOKIEJAR => $ this ->cookies_file ,
177+ CURLOPT_COOKIEFILE => $ this ->cookies_file
178+ ]
179+ );
180+ $ expectedResponse = '<?xml version="1.0"?>
181+ <cas:serviceResponse xmlns:cas="http://www.yale.edu/tp/cas">
182+ <cas:authenticationSuccess>
183+ <cas:user>testuser@example.com</cas:user>
184+ <cas:attributes>
185+ <cas:eduPersonPrincipalName>testuser@example.com</cas:eduPersonPrincipalName>
186+ <cas:base64Attributes>false</cas:base64Attributes>
187+ </cas:attributes>
188+ </cas:authenticationSuccess>
189+ </cas:serviceResponse> ' ;
190+ $ this ->assertEquals (200 , $ resp ['code ' ]);
191+ $ this ->assertEquals ($ expectedResponse , $ resp ['body ' ]);
192+ }
193+
194+ public function validServiceUrlProvider (): array
195+ {
196+ return [
197+ ['service ' , 'ticket ' ],
198+ ['TARGET ' , 'SAMLart ' ]
199+ ];
200+ }
201+
202+ /**
203+ * Test changing the ticket name
204+ * @return void
205+ */
206+ public function testValidTicketNameOverride ()
207+ {
208+ $ service_url = 'http://changeTicketParam/abc ' ;
209+
210+ $ this ->authenticate ();
211+
212+ /** @var array $resp */
213+ $ resp = $ this ->server ->get (
214+ self ::$ LINK_URL ,
215+ ['TARGET ' => $ service_url ],
216+ [
217+ CURLOPT_COOKIEJAR => $ this ->cookies_file ,
218+ CURLOPT_COOKIEFILE => $ this ->cookies_file
219+ ]
220+ );
221+ $ this ->assertEquals (302 , $ resp ['code ' ]);
222+
223+ $ this ->assertStringStartsWith (
224+ $ service_url . '?myTicket=ST- ' ,
154225 $ resp ['headers ' ]['Location ' ],
155226 'Ticket should be part of the redirect. '
156227 );
0 commit comments