|
1 | 1 | package com.onelogin.saml2.test.authn; |
2 | 2 |
|
| 3 | +import com.onelogin.saml2.authn.SamlResponse; |
| 4 | +import com.onelogin.saml2.http.HttpRequest; |
| 5 | +import com.onelogin.saml2.model.SamlResponseStatus; |
| 6 | +import com.onelogin.saml2.settings.Saml2Settings; |
| 7 | +import com.onelogin.saml2.settings.SettingsBuilder; |
| 8 | +import com.onelogin.saml2.util.Constants; |
| 9 | +import com.onelogin.saml2.util.Util; |
| 10 | +import org.hamcrest.Matchers; |
| 11 | +import org.joda.time.Instant; |
| 12 | +import org.junit.Test; |
| 13 | +import org.w3c.dom.Document; |
| 14 | +import org.w3c.dom.Node; |
| 15 | +import org.w3c.dom.NodeList; |
| 16 | + |
| 17 | +import java.util.ArrayList; |
| 18 | +import java.util.HashMap; |
| 19 | +import java.util.List; |
| 20 | +import java.util.concurrent.CopyOnWriteArrayList; |
| 21 | +import java.util.concurrent.ExecutorService; |
| 22 | +import java.util.concurrent.Executors; |
| 23 | +import java.util.concurrent.TimeUnit; |
| 24 | +import java.util.concurrent.atomic.AtomicInteger; |
| 25 | + |
3 | 26 | import static org.hamcrest.CoreMatchers.containsString; |
4 | 27 | import static org.hamcrest.CoreMatchers.not; |
5 | 28 | import static org.hamcrest.Matchers.contains; |
| 29 | +import static org.hamcrest.Matchers.is; |
6 | 30 | import static org.junit.Assert.assertEquals; |
7 | 31 | import static org.junit.Assert.assertFalse; |
8 | 32 | import static org.junit.Assert.assertNull; |
9 | 33 | import static org.junit.Assert.assertThat; |
10 | 34 | import static org.junit.Assert.assertTrue; |
11 | 35 |
|
12 | | -import java.util.ArrayList; |
13 | | -import java.util.HashMap; |
14 | | -import java.util.List; |
15 | | - |
16 | | -import org.joda.time.Instant; |
17 | | -import org.junit.Test; |
18 | | -import org.w3c.dom.Document; |
19 | | -import org.w3c.dom.Node; |
20 | | -import org.w3c.dom.NodeList; |
21 | | - |
22 | | -import com.onelogin.saml2.authn.SamlResponse; |
23 | | -import com.onelogin.saml2.http.HttpRequest; |
24 | | -import com.onelogin.saml2.model.SamlResponseStatus; |
25 | | -import com.onelogin.saml2.settings.Saml2Settings; |
26 | | -import com.onelogin.saml2.settings.SettingsBuilder; |
27 | | -import com.onelogin.saml2.util.Constants; |
28 | | -import com.onelogin.saml2.util.Util; |
29 | | - |
30 | 36 | public class AuthnResponseTest { |
31 | 37 | private static final String ACS_URL = "http://localhost:8080/java-saml-jspsample/acs.jsp"; |
32 | 38 |
|
@@ -1373,6 +1379,42 @@ public void testIsValidSubjectConfirmation_multipleIssues() throws Exception { |
1373 | 1379 | "\n[2] SubjectConfirmationData is no longer valid"); |
1374 | 1380 | } |
1375 | 1381 |
|
| 1382 | + @Test |
| 1383 | + public void testIsValid_multipleThreads() throws Exception { |
| 1384 | + // having |
| 1385 | + final int jobCount = 100; |
| 1386 | + final int threadCount = 5; |
| 1387 | + final ExecutorService executor = Executors.newFixedThreadPool(threadCount); |
| 1388 | + final List<Throwable> errors = new CopyOnWriteArrayList<>(); |
| 1389 | + final AtomicInteger successCount = new AtomicInteger(); |
| 1390 | + |
| 1391 | + // when |
| 1392 | + for (int i = 0; i < jobCount; i++) { |
| 1393 | + executor.submit(new Runnable() { |
| 1394 | + @Override |
| 1395 | + public void run() { |
| 1396 | + try { |
| 1397 | + Saml2Settings settings = new SettingsBuilder().fromFile("config/config.my.properties").build(); |
| 1398 | + settings.setWantAssertionsSigned(false); |
| 1399 | + settings.setWantMessagesSigned(true); |
| 1400 | + final String samlResponseEncoded = loadSignMessageAndEncode("data/responses/valid_idp_initiated_response.xml"); |
| 1401 | + |
| 1402 | + assertResponseValid(settings, samlResponseEncoded, true, true, null); |
| 1403 | + successCount.incrementAndGet(); |
| 1404 | + } catch (Throwable e) { |
| 1405 | + errors.add(e); |
| 1406 | + } |
| 1407 | + } |
| 1408 | + }); |
| 1409 | + } |
| 1410 | + executor.shutdown(); |
| 1411 | + executor.awaitTermination(30, TimeUnit.SECONDS); |
| 1412 | + |
| 1413 | + // then |
| 1414 | + assertThat(errors, Matchers.empty()); |
| 1415 | + assertThat(successCount.get(), is(jobCount)); |
| 1416 | + } |
| 1417 | + |
1376 | 1418 | /** |
1377 | 1419 | * Tests the isValid method of SamlResponse |
1378 | 1420 | * Case: Datetime with Miliseconds |
|
0 commit comments