@@ -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 ;
@@ -67,6 +68,7 @@ protected function setUp(): void
6768 Configuration::loadFromArray ([
6869 'secretsalt ' => 'secretsalt ' ,
6970 ], '[ARRAY] ' , 'simplesaml ' );
71+
7072 }
7173
7274
@@ -117,6 +119,58 @@ public function testSPwithUserId(): void
117119 'F-TICKS/ACME/1.0#RESULT=OK#AP=https://localhost/saml:sp:IdP#RP=https://localhost/idp#CSI=CL ' ,
118120 '/ ' ,
119121 );
122+ $ pattern2 = preg_quote (
123+ '#AM= ' . Constants::AC_UNSPECIFIED
124+ . '#PN=d63bb55765af1321b06950abb5f9787cffd05ef271a09b67964f402f3f209cc6#TS=1000# ' ,
125+ '/ ' ,
126+ );
127+ $ this ->expectOutputRegex ('/^ ' . $ pattern1 . '[^#]+ ' . $ pattern2 . '$/ ' );
128+ $ result = self ::processFilter ($ config , $ request );
129+ $ this ->assertEquals ($ request , $ result );
130+ }
131+
132+
133+ /**
134+ */
135+ public function testSPwithUserIdDifferentProviders (): void
136+ {
137+ $ config = ['federation ' => 'ACME ' , 'logdest ' => 'stdout ' , 'identifyingAttribute ' => 'eduPersonPrincipalName ' ];
138+ $ request = array_merge (self ::$ minRequest , self ::$ spRequest , [
139+ 'Attributes ' => [
140+ 'eduPersonPrincipalName ' => [ 'user2@example.net ' ],
141+ ],
142+ ]);
143+ $ request ['Destination ' ]['entityid ' ] = 'https://localhost/idp2 ' ;
144+ $ request ['saml:sp:IdP ' ] = 'https://localhost/saml:sp:IdP2 ' ;
145+ $ pattern1 = preg_quote (
146+ 'F-TICKS/ACME/1.0#RESULT=OK#AP=https://localhost/saml:sp:IdP2#RP=https://localhost/idp2#CSI=CL ' ,
147+ '/ ' ,
148+ );
149+ $ pattern2 = preg_quote (
150+ '#AM= ' . Constants::AC_UNSPECIFIED
151+ . '#PN=d63bb55765af1321b06950abb5f9787cffd05ef271a09b67964f402f3f209cc6#TS=1000# ' ,
152+ '/ ' ,
153+ );
154+ $ this ->expectOutputRegex ('/^ ' . $ pattern1 . '[^#]+ ' . $ pattern2 . '$/ ' );
155+ $ result = self ::processFilter ($ config , $ request );
156+ $ this ->assertEquals ($ request , $ result );
157+ }
158+
159+
160+ /**
161+ */
162+ public function testSPwithUserIdLegacyBehaviour (): void
163+ {
164+ $ config = ['federation ' => 'ACME ' , 'logdest ' => 'stdout ' , 'identifyingAttribute ' => 'eduPersonPrincipalName ' , 'pnHashIsTargeted ' => 'both ' ,];
165+ $ request = array_merge (self ::$ minRequest , self ::$ spRequest , [
166+ 'Attributes ' => [
167+ 'eduPersonPrincipalName ' => [ 'user2@example.net ' ],
168+ ],
169+ ]);
170+ $ pattern1 = preg_quote (
171+ 'F-TICKS/ACME/1.0#RESULT=OK#AP=https://localhost/saml:sp:IdP#RP=https://localhost/idp#CSI=CL ' ,
172+ '/ ' ,
173+ );
120174 $ pattern2 = preg_quote (
121175 '#AM= ' . Constants::AC_UNSPECIFIED
122176 . '#PN=e5d066a96d5809a21264e153013c3c793e6574cb77afdfa248ad2cefab9b0451#TS=1000# ' ,
@@ -128,6 +182,109 @@ public function testSPwithUserId(): void
128182 }
129183
130184
185+ /**
186+ */
187+ public function testSPwithUserIdSourceTargeted (): void
188+ {
189+ $ config = ['federation ' => 'ACME ' , 'logdest ' => 'stdout ' , 'identifyingAttribute ' => 'eduPersonPrincipalName ' , 'pnHashIsTargeted ' => 'source ' ,];
190+ $ request = array_merge (self ::$ minRequest , self ::$ spRequest , [
191+ 'Attributes ' => [
192+ 'eduPersonPrincipalName ' => [ 'user2@example.net ' ],
193+ ],
194+ ]);
195+ $ pattern1 = preg_quote (
196+ 'F-TICKS/ACME/1.0#RESULT=OK#AP=https://localhost/saml:sp:IdP#RP=https://localhost/idp#CSI=CL ' ,
197+ '/ ' ,
198+ );
199+ $ pattern2 = preg_quote (
200+ '#AM= ' . Constants::AC_UNSPECIFIED
201+ . '#PN=d9b260a0830f4a93b407aaf0a578446880fc8acdc58cd81aecdcde12ec0f8cae#TS=1000# ' ,
202+ '/ ' ,
203+ );
204+ $ this ->expectOutputRegex ('/^ ' . $ pattern1 . '[^#]+ ' . $ pattern2 . '$/ ' );
205+ $ result = self ::processFilter ($ config , $ request );
206+ $ this ->assertEquals ($ request , $ result );
207+ }
208+
209+
210+ /**
211+ */
212+ public function testSPwithUserIdSourceTargetedDifferentDest (): void
213+ {
214+ $ config = ['federation ' => 'ACME ' , 'logdest ' => 'stdout ' , 'identifyingAttribute ' => 'eduPersonPrincipalName ' , 'pnHashIsTargeted ' => 'source ' ,];
215+ $ request = array_merge (self ::$ minRequest , self ::$ spRequest , [
216+ 'Attributes ' => [
217+ 'eduPersonPrincipalName ' => [ 'user2@example.net ' ],
218+ ],
219+ ]);
220+ $ request ['Destination ' ]['entityid ' ] = 'https://localhost/idp2 ' ;
221+ $ pattern1 = preg_quote (
222+ 'F-TICKS/ACME/1.0#RESULT=OK#AP=https://localhost/saml:sp:IdP#RP=https://localhost/idp2#CSI=CL ' ,
223+ '/ ' ,
224+ );
225+ $ pattern2 = preg_quote (
226+ '#AM= ' . Constants::AC_UNSPECIFIED
227+ . '#PN=d9b260a0830f4a93b407aaf0a578446880fc8acdc58cd81aecdcde12ec0f8cae#TS=1000# ' ,
228+ '/ ' ,
229+ );
230+ $ this ->expectOutputRegex ('/^ ' . $ pattern1 . '[^#]+ ' . $ pattern2 . '$/ ' );
231+ $ result = self ::processFilter ($ config , $ request );
232+ $ this ->assertEquals ($ request , $ result );
233+ }
234+
235+
236+ /**
237+ */
238+ public function testSPwithUserIdDestinationTargeted (): void
239+ {
240+ $ config = ['federation ' => 'ACME ' , 'logdest ' => 'stdout ' , 'identifyingAttribute ' => 'eduPersonPrincipalName ' , 'pnHashIsTargeted ' => 'destination ' ,];
241+ $ request = array_merge (self ::$ minRequest , self ::$ spRequest , [
242+ 'Attributes ' => [
243+ 'eduPersonPrincipalName ' => [ 'user2@example.net ' ],
244+ ],
245+ ]);
246+ $ pattern1 = preg_quote (
247+ 'F-TICKS/ACME/1.0#RESULT=OK#AP=https://localhost/saml:sp:IdP#RP=https://localhost/idp#CSI=CL ' ,
248+ '/ ' ,
249+ );
250+ $ pattern2 = preg_quote (
251+ '#AM= ' . Constants::AC_UNSPECIFIED
252+ . '#PN=2497368e277bd4d6f848c268292e85cbe3fe4dfd0920b4ac2f5a419f523d4374#TS=1000# ' ,
253+ '/ ' ,
254+ );
255+ $ this ->expectOutputRegex ('/^ ' . $ pattern1 . '[^#]+ ' . $ pattern2 . '$/ ' );
256+ $ result = self ::processFilter ($ config , $ request );
257+ $ this ->assertEquals ($ request , $ result );
258+ $ request ['saml:sp:IdP ' ] = 'https://localhost/saml:sp:IdP2 ' ;
259+ }
260+
261+
262+ /**
263+ */
264+ public function testSPwithUserIdDestinationTargetedDifferentSource (): void
265+ {
266+ $ config = ['federation ' => 'ACME ' , 'logdest ' => 'stdout ' , 'identifyingAttribute ' => 'eduPersonPrincipalName ' , 'pnHashIsTargeted ' => 'destination ' ,];
267+ $ request = array_merge (self ::$ minRequest , self ::$ spRequest , [
268+ 'Attributes ' => [
269+ 'eduPersonPrincipalName ' => [ 'user2@example.net ' ],
270+ ],
271+ ]);
272+ $ request ['saml:sp:IdP ' ] = 'https://localhost/saml:sp:IdP2 ' ;
273+ $ pattern1 = preg_quote (
274+ 'F-TICKS/ACME/1.0#RESULT=OK#AP=https://localhost/saml:sp:IdP2#RP=https://localhost/idp#CSI=CL ' ,
275+ '/ ' ,
276+ );
277+ $ pattern2 = preg_quote (
278+ '#AM= ' . Constants::AC_UNSPECIFIED
279+ . '#PN=2497368e277bd4d6f848c268292e85cbe3fe4dfd0920b4ac2f5a419f523d4374#TS=1000# ' ,
280+ '/ ' ,
281+ );
282+ $ this ->expectOutputRegex ('/^ ' . $ pattern1 . '[^#]+ ' . $ pattern2 . '$/ ' );
283+ $ result = self ::processFilter ($ config , $ request );
284+ $ this ->assertEquals ($ request , $ result );
285+ }
286+
287+
131288 /**
132289 */
133290 public function testAsIdentityProvider (): void
@@ -144,7 +301,7 @@ public function testAsIdentityProvider(): void
144301 );
145302 $ pattern2 = preg_quote (
146303 '#AM= ' . Constants::AC_PASSWORD
147- . '#PN=d844a9a0666bb3990e88f72b8f5c20accbcfa46f7b8a7ab38593bfbbab6e9cbc #TS= ' ,
304+ . '#PN=16ed2263078ca90f38708681fcf6628d80e0f91f4b5d743054fe8e185c9e0979 #TS= ' ,
148305 '/ ' ,
149306 );
150307 $ this ->expectOutputRegex ('/^ ' . $ pattern1 . '[^#]+ ' . $ pattern2 . '\d+#$/ ' );
@@ -218,7 +375,7 @@ public function testFilteringString(): void
218375 '/ ' ,
219376 );
220377 $ pattern2 = preg_quote (
221- '#PN=d844a9a0666bb3990e88f72b8f5c20accbcfa46f7b8a7ab38593bfbbab6e9cbc #TS= ' ,
378+ '#PN=16ed2263078ca90f38708681fcf6628d80e0f91f4b5d743054fe8e185c9e0979 #TS= ' ,
222379 '/ ' ,
223380 );
224381 $ this ->expectOutputRegex ('/^ ' . $ pattern1 . '[^#]+ ' . $ pattern2 . '\d+#$/ ' );
0 commit comments