@@ -54,6 +54,7 @@ class FticksTest extends TestCase
5454 */
5555 private static function processFilter (array $ config , array $ request ): array
5656 {
57+ $ _SERVER ['REQUEST_URI ' ] = '/simplesaml/ ' ; /* suppress warning from SimpleSAML/Utils/HTTP */
5758 $ filter = new Fticks ($ config , null );
5859 $ filter ->process ($ request );
5960 return $ request ;
@@ -117,6 +118,63 @@ public function testSPwithUserId(): void
117118 'F-TICKS/ACME/1.0#RESULT=OK#AP=https://localhost/saml:sp:IdP#RP=https://localhost/idp#CSI=CL ' ,
118119 '/ ' ,
119120 );
121+ $ pattern2 = preg_quote (
122+ '#AM= ' . Constants::AC_UNSPECIFIED
123+ . '#PN=d63bb55765af1321b06950abb5f9787cffd05ef271a09b67964f402f3f209cc6#TS=1000# ' ,
124+ '/ ' ,
125+ );
126+ $ this ->expectOutputRegex ('/^ ' . $ pattern1 . '[^#]+ ' . $ pattern2 . '$/ ' );
127+ $ result = self ::processFilter ($ config , $ request );
128+ $ this ->assertEquals ($ request , $ result );
129+ }
130+
131+
132+ /**
133+ */
134+ public function testSPwithUserIdDifferentProviders (): void
135+ {
136+ $ config = ['federation ' => 'ACME ' , 'logdest ' => 'stdout ' , 'identifyingAttribute ' => 'eduPersonPrincipalName ' ];
137+ $ request = array_merge (self ::$ minRequest , self ::$ spRequest , [
138+ 'Attributes ' => [
139+ 'eduPersonPrincipalName ' => [
'[email protected] ' ],
140+ ],
141+ ]);
142+ $ request ['Destination ' ]['entityid ' ] = 'https://localhost/idp2 ' ;
143+ $ request ['saml:sp:IdP ' ] = 'https://localhost/saml:sp:IdP2 ' ;
144+ $ pattern1 = preg_quote (
145+ 'F-TICKS/ACME/1.0#RESULT=OK#AP=https://localhost/saml:sp:IdP2#RP=https://localhost/idp2#CSI=CL ' ,
146+ '/ ' ,
147+ );
148+ $ pattern2 = preg_quote (
149+ '#AM= ' . Constants::AC_UNSPECIFIED
150+ . '#PN=d63bb55765af1321b06950abb5f9787cffd05ef271a09b67964f402f3f209cc6#TS=1000# ' ,
151+ '/ ' ,
152+ );
153+ $ this ->expectOutputRegex ('/^ ' . $ pattern1 . '[^#]+ ' . $ pattern2 . '$/ ' );
154+ $ result = self ::processFilter ($ config , $ request );
155+ $ this ->assertEquals ($ request , $ result );
156+ }
157+
158+
159+ /**
160+ */
161+ public function testSPwithUserIdLegacyBehaviour (): void
162+ {
163+ $ config = [
164+ 'federation ' => 'ACME ' ,
165+ 'logdest ' => 'stdout ' ,
166+ 'identifyingAttribute ' => 'eduPersonPrincipalName ' ,
167+ 'pnHashIsTargeted ' => 'both ' ,
168+ ];
169+ $ request = array_merge (self ::$ minRequest , self ::$ spRequest , [
170+ 'Attributes ' => [
171+ 'eduPersonPrincipalName ' => [
'[email protected] ' ],
172+ ],
173+ ]);
174+ $ pattern1 = preg_quote (
175+ 'F-TICKS/ACME/1.0#RESULT=OK#AP=https://localhost/saml:sp:IdP#RP=https://localhost/idp#CSI=CL ' ,
176+ '/ ' ,
177+ );
120178 $ pattern2 = preg_quote (
121179 '#AM= ' . Constants::AC_UNSPECIFIED
122180 . '#PN=e5d066a96d5809a21264e153013c3c793e6574cb77afdfa248ad2cefab9b0451#TS=1000# ' ,
@@ -128,6 +186,129 @@ public function testSPwithUserId(): void
128186 }
129187
130188
189+ /**
190+ */
191+ public function testSPwithUserIdSourceTargeted (): void
192+ {
193+ $ config = [
194+ 'federation ' => 'ACME ' ,
195+ 'logdest ' => 'stdout ' ,
196+ 'identifyingAttribute ' => 'eduPersonPrincipalName ' ,
197+ 'pnHashIsTargeted ' => 'source ' ,
198+ ];
199+ $ request = array_merge (self ::$ minRequest , self ::$ spRequest , [
200+ 'Attributes ' => [
201+ 'eduPersonPrincipalName ' => [
'[email protected] ' ],
202+ ],
203+ ]);
204+ $ pattern1 = preg_quote (
205+ 'F-TICKS/ACME/1.0#RESULT=OK#AP=https://localhost/saml:sp:IdP#RP=https://localhost/idp#CSI=CL ' ,
206+ '/ ' ,
207+ );
208+ $ pattern2 = preg_quote (
209+ '#AM= ' . Constants::AC_UNSPECIFIED
210+ . '#PN=d9b260a0830f4a93b407aaf0a578446880fc8acdc58cd81aecdcde12ec0f8cae#TS=1000# ' ,
211+ '/ ' ,
212+ );
213+ $ this ->expectOutputRegex ('/^ ' . $ pattern1 . '[^#]+ ' . $ pattern2 . '$/ ' );
214+ $ result = self ::processFilter ($ config , $ request );
215+ $ this ->assertEquals ($ request , $ result );
216+ }
217+
218+
219+ /**
220+ */
221+ public function testSPwithUserIdSourceTargetedDifferentDest (): void
222+ {
223+ $ config = [
224+ 'federation ' => 'ACME ' ,
225+ 'logdest ' => 'stdout ' ,
226+ 'identifyingAttribute ' => 'eduPersonPrincipalName ' ,
227+ 'pnHashIsTargeted ' => 'source ' ,
228+ ];
229+ $ request = array_merge (self ::$ minRequest , self ::$ spRequest , [
230+ 'Attributes ' => [
231+ 'eduPersonPrincipalName ' => [
'[email protected] ' ],
232+ ],
233+ ]);
234+ $ request ['Destination ' ]['entityid ' ] = 'https://localhost/idp2 ' ;
235+ $ pattern1 = preg_quote (
236+ 'F-TICKS/ACME/1.0#RESULT=OK#AP=https://localhost/saml:sp:IdP#RP=https://localhost/idp2#CSI=CL ' ,
237+ '/ ' ,
238+ );
239+ $ pattern2 = preg_quote (
240+ '#AM= ' . Constants::AC_UNSPECIFIED
241+ . '#PN=d9b260a0830f4a93b407aaf0a578446880fc8acdc58cd81aecdcde12ec0f8cae#TS=1000# ' ,
242+ '/ ' ,
243+ );
244+ $ this ->expectOutputRegex ('/^ ' . $ pattern1 . '[^#]+ ' . $ pattern2 . '$/ ' );
245+ $ result = self ::processFilter ($ config , $ request );
246+ $ this ->assertEquals ($ request , $ result );
247+ }
248+
249+
250+ /**
251+ */
252+ public function testSPwithUserIdDestinationTargeted (): void
253+ {
254+ $ config = [
255+ 'federation ' => 'ACME ' ,
256+ 'logdest ' => 'stdout ' ,
257+ 'identifyingAttribute ' => 'eduPersonPrincipalName ' ,
258+ 'pnHashIsTargeted ' => 'destination ' ,
259+ ];
260+ $ request = array_merge (self ::$ minRequest , self ::$ spRequest , [
261+ 'Attributes ' => [
262+ 'eduPersonPrincipalName ' => [
'[email protected] ' ],
263+ ],
264+ ]);
265+ $ pattern1 = preg_quote (
266+ 'F-TICKS/ACME/1.0#RESULT=OK#AP=https://localhost/saml:sp:IdP#RP=https://localhost/idp#CSI=CL ' ,
267+ '/ ' ,
268+ );
269+ $ pattern2 = preg_quote (
270+ '#AM= ' . Constants::AC_UNSPECIFIED
271+ . '#PN=2497368e277bd4d6f848c268292e85cbe3fe4dfd0920b4ac2f5a419f523d4374#TS=1000# ' ,
272+ '/ ' ,
273+ );
274+ $ this ->expectOutputRegex ('/^ ' . $ pattern1 . '[^#]+ ' . $ pattern2 . '$/ ' );
275+ $ result = self ::processFilter ($ config , $ request );
276+ $ this ->assertEquals ($ request , $ result );
277+ $ request ['saml:sp:IdP ' ] = 'https://localhost/saml:sp:IdP2 ' ;
278+ }
279+
280+
281+ /**
282+ */
283+ public function testSPwithUserIdDestinationTargetedDifferentSource (): void
284+ {
285+ $ config = [
286+ 'federation ' => 'ACME ' ,
287+ 'logdest ' => 'stdout ' ,
288+ 'identifyingAttribute ' => 'eduPersonPrincipalName ' ,
289+ 'pnHashIsTargeted ' => 'destination ' ,
290+ ];
291+ $ request = array_merge (self ::$ minRequest , self ::$ spRequest , [
292+ 'Attributes ' => [
293+ 'eduPersonPrincipalName ' => [
'[email protected] ' ],
294+ ],
295+ ]);
296+ $ request ['saml:sp:IdP ' ] = 'https://localhost/saml:sp:IdP2 ' ;
297+ $ pattern1 = preg_quote (
298+ 'F-TICKS/ACME/1.0#RESULT=OK#AP=https://localhost/saml:sp:IdP2#RP=https://localhost/idp#CSI=CL ' ,
299+ '/ ' ,
300+ );
301+ $ pattern2 = preg_quote (
302+ '#AM= ' . Constants::AC_UNSPECIFIED
303+ . '#PN=2497368e277bd4d6f848c268292e85cbe3fe4dfd0920b4ac2f5a419f523d4374#TS=1000# ' ,
304+ '/ ' ,
305+ );
306+ $ this ->expectOutputRegex ('/^ ' . $ pattern1 . '[^#]+ ' . $ pattern2 . '$/ ' );
307+ $ result = self ::processFilter ($ config , $ request );
308+ $ this ->assertEquals ($ request , $ result );
309+ }
310+
311+
131312 /**
132313 */
133314 public function testAsIdentityProvider (): void
@@ -144,7 +325,7 @@ public function testAsIdentityProvider(): void
144325 );
145326 $ pattern2 = preg_quote (
146327 '#AM= ' . Constants::AC_PASSWORD
147- . '#PN=d844a9a0666bb3990e88f72b8f5c20accbcfa46f7b8a7ab38593bfbbab6e9cbc #TS= ' ,
328+ . '#PN=16ed2263078ca90f38708681fcf6628d80e0f91f4b5d743054fe8e185c9e0979 #TS= ' ,
148329 '/ ' ,
149330 );
150331 $ this ->expectOutputRegex ('/^ ' . $ pattern1 . '[^#]+ ' . $ pattern2 . '\d+#$/ ' );
@@ -218,7 +399,7 @@ public function testFilteringString(): void
218399 '/ ' ,
219400 );
220401 $ pattern2 = preg_quote (
221- '#PN=d844a9a0666bb3990e88f72b8f5c20accbcfa46f7b8a7ab38593bfbbab6e9cbc #TS= ' ,
402+ '#PN=16ed2263078ca90f38708681fcf6628d80e0f91f4b5d743054fe8e185c9e0979 #TS= ' ,
222403 '/ ' ,
223404 );
224405 $ this ->expectOutputRegex ('/^ ' . $ pattern1 . '[^#]+ ' . $ pattern2 . '\d+#$/ ' );
0 commit comments