Skip to content

Commit c1f089c

Browse files
Test coverage for /.well-known/security.txt (#2860)
1 parent 31a5b5c commit c1f089c

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

src/org/labkey/test/tests/SecurityTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,14 @@
4949
import org.openqa.selenium.support.ui.ExpectedConditions;
5050

5151
import java.io.IOException;
52+
import java.io.StringReader;
53+
import java.time.ZonedDateTime;
54+
import java.time.format.DateTimeFormatter;
5255
import java.util.Arrays;
5356
import java.util.Collections;
5457
import java.util.HashSet;
5558
import java.util.List;
59+
import java.util.Properties;
5660
import java.util.Set;
5761

5862
import static org.junit.Assert.assertEquals;
@@ -122,6 +126,28 @@ protected void doCleanup(boolean afterTest) throws TestTimeoutException
122126
DbLoginUtils.resetDbLoginConfig(cn);
123127
}
124128

129+
@Test
130+
public void testSecurityTxt() throws IOException
131+
{
132+
getDriver().navigate().to(WebTestHelper.getBaseURL() + "/.well-known/security.txt");
133+
134+
String body = getBodyText();
135+
136+
Properties props = new Properties();
137+
props.load(new StringReader(body));
138+
139+
assertTrue("security.txt missing Contact", props.containsKey("Contact"));
140+
assertTrue("security.txt missing Policy", props.containsKey("Policy"));
141+
assertTrue("security.txt missing Expires", props.containsKey("Expires"));
142+
143+
String expiresStr = props.getProperty("Expires");
144+
ZonedDateTime expires = ZonedDateTime.parse(expiresStr, DateTimeFormatter.ISO_INSTANT.withZone(java.time.ZoneId.of("UTC")));
145+
ZonedDateTime nextYear = ZonedDateTime.now(java.time.ZoneId.of("UTC")).plusYears(1);
146+
147+
// If this assert fails, edit security.txt to use something more than a year in the future
148+
assertTrue("security.txt 'Expires' value should be more than a year in the future: " + expiresStr, expires.isAfter(nextYear));
149+
}
150+
125151
@Test
126152
public void testSteps() throws IOException
127153
{

0 commit comments

Comments
 (0)