Skip to content

Commit f81b6d7

Browse files
author
Corentin Groix
committed
Fix some time sensitive tests
Some test were failing since last June, because some notOnOrAfter saml node expired. Since the library use Joda Time for these check, we can use the DateTimeUtils.setCurrentMillisFixed utility to make them pass.
1 parent 95549b5 commit f81b6d7

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

core/src/test/java/com/onelogin/saml2/test/authn/AuthnResponseTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212
import com.onelogin.saml2.util.Util;
1313

1414
import org.hamcrest.Matchers;
15+
import org.joda.time.DateTime;
16+
import org.joda.time.DateTimeUtils;
1517
import org.joda.time.Instant;
18+
import org.joda.time.format.ISODateTimeFormat;
19+
import org.junit.After;
20+
import org.junit.Before;
1621
import org.junit.Rule;
1722
import org.junit.Test;
1823
import org.junit.rules.ExpectedException;
@@ -23,6 +28,7 @@
2328

2429
import java.io.IOException;
2530
import java.util.ArrayList;
31+
import java.util.Date;
2632
import java.util.HashMap;
2733
import java.util.List;
2834
import java.util.concurrent.CopyOnWriteArrayList;
@@ -50,6 +56,18 @@ public class AuthnResponseTest {
5056
@Rule
5157
public ExpectedException expectedEx = ExpectedException.none();
5258

59+
@Before
60+
public void setDateTime() {
61+
//All calls to Joda time check will use this timestamp as "now" value :
62+
setDateTime("2020-06-01T00:00:00Z");
63+
}
64+
65+
@After
66+
public void goBackToNormal() {
67+
DateTimeUtils.setCurrentMillisSystem();
68+
}
69+
70+
5371
/**
5472
* Tests the constructor of SamlResponse
5573
*
@@ -2678,5 +2696,10 @@ private static HttpRequest newHttpRequest(String samlResponseEncoded) {
26782696
private static HttpRequest newHttpRequest(String requestURL, String samlResponseEncoded) {
26792697
return new HttpRequest(requestURL).addParameter("SAMLResponse", samlResponseEncoded);
26802698
}
2699+
2700+
private void setDateTime(String ISOTimeStamp) {
2701+
DateTime dateTime = ISODateTimeFormat.dateTimeNoMillis().withZoneUTC().parseDateTime(ISOTimeStamp);
2702+
DateTimeUtils.setCurrentMillisFixed(dateTime.toDate().getTime());
2703+
}
26812704
}
26822705

0 commit comments

Comments
 (0)