|
2 | 2 |
|
3 | 3 | import static org.hamcrest.CoreMatchers.containsString; |
4 | 4 | import static org.hamcrest.CoreMatchers.not; |
| 5 | +import static org.hamcrest.Matchers.*; |
5 | 6 | import static org.junit.Assert.assertEquals; |
6 | 7 | import static org.junit.Assert.assertThat; |
7 | 8 | import static org.junit.Assert.assertNull; |
|
16 | 17 |
|
17 | 18 | import javax.servlet.http.HttpServletRequest; |
18 | 19 |
|
| 20 | +import org.joda.time.Instant; |
19 | 21 | import org.junit.Test; |
20 | 22 | import org.w3c.dom.Document; |
21 | 23 | import org.w3c.dom.Node; |
@@ -474,6 +476,48 @@ public void testGetSessionIndex() throws Exception { |
474 | 476 | assertEquals("_7164a9a9f97828bfdb8d0ebc004a05d2e7d873f70c", samlResponse.getSessionIndex()); |
475 | 477 | } |
476 | 478 |
|
| 479 | + @Test |
| 480 | + public void testGetAssertionDetails() throws Exception { |
| 481 | + final SamlResponse samlResponse = new SamlResponse( |
| 482 | + new SettingsBuilder().fromFile("config/config.my.properties").build(), |
| 483 | + mockRequestWithSamlResponse(Util.getFileAsString("data/responses/response1.xml.base64")) |
| 484 | + ); |
| 485 | + final List<Instant> notOnOrAfters = samlResponse.getNotOnOrAfter(); |
| 486 | + |
| 487 | + assertEquals("pfxa46574df-b3b0-a06a-23c8-636413198772", samlResponse.getAssertionId()); |
| 488 | + assertThat(notOnOrAfters, contains(new Instant("2010-11-18T22:02:37Z"))); |
| 489 | + |
| 490 | + } |
| 491 | + |
| 492 | + @Test |
| 493 | + public void testGetAssertionDetails_encrypted() throws Exception { |
| 494 | + final SamlResponse samlResponse = new SamlResponse( |
| 495 | + new SettingsBuilder().fromFile("config/config.my.properties").build(), |
| 496 | + mockRequestWithSamlResponse(Util.getFileAsString("data/responses/valid_encrypted_assertion.xml.base64")) |
| 497 | + ); |
| 498 | + final List<Instant> notOnOrAfters = samlResponse.getNotOnOrAfter(); |
| 499 | + |
| 500 | + assertEquals("_519c2712648ee09a06d1f9a08e9e835715fea60267", samlResponse.getAssertionId()); |
| 501 | + assertThat(notOnOrAfters, contains(new Instant("2055-06-07T20:17:08Z"))); |
| 502 | + |
| 503 | + } |
| 504 | + |
| 505 | + @Test |
| 506 | + public void testGetAssertionDetails_multiple() throws Exception { |
| 507 | + Saml2Settings settings = new SettingsBuilder().fromFile("config/config.my.properties").build(); |
| 508 | + settings.setWantAssertionsSigned(false); |
| 509 | + settings.setWantMessagesSigned(true); |
| 510 | + |
| 511 | + final SamlResponse samlResponse = new SamlResponse( |
| 512 | + settings, |
| 513 | + mockRequestWithSamlResponse(loadSignMessageAndEncode("data/responses/invalids/invalid_subjectconfirmation_multiple_issues.xml")) |
| 514 | + ); |
| 515 | + final List<Instant> notOnOrAfters = samlResponse.getNotOnOrAfter(); |
| 516 | + |
| 517 | + assertEquals("pfx7841991c-c73f-4035-e2ee-c170c0e1d3e4", samlResponse.getAssertionId()); |
| 518 | + assertThat(notOnOrAfters, contains(new Instant("2120-06-17T14:53:44Z"), new Instant("2010-06-17T14:53:44Z"))); |
| 519 | + } |
| 520 | + |
477 | 521 | /** |
478 | 522 | * Tests the getAttributes method of SamlResponse |
479 | 523 | * |
|
0 commit comments