1010use SimpleSAML \Module \casserver \Cas \TicketValidator ;
1111use SimpleSAML \Utils \Random ;
1212
13- /**
14- * Created by PhpStorm.
15- * User: patrick
16- * Date: 8/23/19
17- * Time: 12:13 PM
18- */
1913class TicketValidatorTest extends TestCase
2014{
2115 /**
@@ -35,6 +29,8 @@ class TicketValidatorTest extends TestCase
3529 protected function setUp (): void
3630 {
3731 parent ::setUp ();
32+ Configuration::clearInternalState ();
33+ putenv ('SIMPLESAMLPHP_CONFIG_DIR= ' . dirname (__DIR__ ) . '/config ' );
3834 $ casConfig = Configuration::loadFromArray ([
3935 'ticketstore ' => [
4036 'class ' => 'casserver:FileSystemTicketStore ' ,
@@ -131,6 +127,39 @@ public function testExpiredTicket()
131127 $ this ->assertNull ($ this ->ticketStore ->getTicket ($ id ), "ticket deleted after loading " );
132128 }
133129
130+ /**
131+ * @dataProvider urlSanitizationProvider
132+ * @param string $serviceUrl The service url that will get sanitized
133+ * @param string $expectedSanitzedUrl The expected result
134+ * @return void
135+ */
136+ public function testUrlSanitization (string $ serviceUrl , string $ expectedSanitzedUrl ): void
137+ {
138+ $ this ->assertEquals ($ expectedSanitzedUrl , TicketValidator::sanitize ($ serviceUrl ));
139+ }
140+
141+ /**
142+ * Urls to test
143+ * @return array
144+ */
145+ public function urlSanitizationProvider ()
146+ {
147+ return [
148+ [
149+ 'https://example.edu/kc/portal.do;jsessionid=99AC064A12?a=b ' ,
150+ 'https://example.edu/kc/portal.do?a=b ' ,
151+ ],
152+ [
153+ 'https://example.edu/kc/portal.do?a=b ' ,
154+ 'https://example.edu/kc/portal.do?a=b ' ,
155+ ],
156+ [
157+ 'https://k.edu/kc/portal.do;jsessionid=99AC064A127?ct=Search&cu=https://k.edu/kc/as.do?ssf=456*&rsol=1 ' ,
158+ 'https://k.edu/kc/portal.do?ct=Search&cu=https://k.edu/kc/as.do?ssf=456*&rsol=1 ' ,
159+ ]
160+ ];
161+ }
162+
134163
135164 /**
136165 * Create a ticket to use for testing
0 commit comments