-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-73815] In FiPS mode passwords must be at least 14 characters (…
…#314) * [JENKINS-73815] In FiPS mode passwords must be at least 14 characters long * Use Secret.toString in all checks For simplification
- Loading branch information
Showing
14 changed files
with
167 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package jenkins.plugins.mailer; | ||
|
||
import hudson.ExtensionList; | ||
import hudson.diagnosis.OldDataMonitor; | ||
import hudson.tasks.Mailer; | ||
import io.jenkins.plugins.casc.ConfigurationAsCode; | ||
import io.jenkins.plugins.casc.ConfiguratorException; | ||
import org.htmlunit.WebResponse; | ||
import org.htmlunit.html.HtmlForm; | ||
import org.htmlunit.html.HtmlPage; | ||
import org.junit.Assume; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
import org.jvnet.hudson.test.RealJenkinsRule; | ||
import org.jvnet.hudson.test.recipes.LocalData; | ||
import org.xml.sax.SAXException; | ||
|
||
import java.io.IOException; | ||
import java.io.Serializable; | ||
import java.net.URL; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.containsString; | ||
import static org.hamcrest.Matchers.instanceOf; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.Matchers.nullValue; | ||
import static org.junit.Assert.assertNotEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertNull; | ||
import static org.junit.Assert.fail; | ||
|
||
public class FipsModeTest { | ||
public static final String SHORT_PWD_ERROR_MESSAGE = "When running in FIPS compliance mode, the password must be at least 14 characters long"; | ||
@Rule | ||
public RealJenkinsRule r = new RealJenkinsRule().javaOptions("-Djenkins.security.FIPS140.COMPLIANCE=true").withDebugPort(5008); | ||
|
||
@Test @LocalData | ||
public void testBlowsUpOnStart() throws Throwable { | ||
r.then(FipsModeTest::verifyOldData); | ||
} | ||
|
||
static void verifyOldData(JenkinsRule j) throws Throwable { | ||
OldDataMonitor monitor = ExtensionList.lookupSingleton(OldDataMonitor.class); | ||
Mailer.DescriptorImpl descriptor = Mailer.descriptor(); | ||
assertNull(descriptor.getAuthentication()); | ||
OldDataMonitor.VersionRange versionRange = monitor.getData().get(descriptor); | ||
assertNotNull(versionRange); | ||
assertThat(versionRange.extra, containsString("Mailer SMTP password: " + SHORT_PWD_ERROR_MESSAGE)); | ||
} | ||
|
||
@Test | ||
public void testConfig() throws Throwable { | ||
r.then(FipsModeTest::_testConfig); | ||
} | ||
|
||
public static void _testConfig(JenkinsRule j) throws Exception { | ||
Assume.assumeThat("TODO the form elements for email-ext have the same names", j.getPluginManager().getPlugin("email-ext"), is(nullValue())); | ||
try (JenkinsRule.WebClient wc = j.createWebClient()) { | ||
HtmlPage cp = wc.goTo("configure"); | ||
wc.setThrowExceptionOnFailingStatusCode(false); | ||
HtmlForm form = cp.getFormByName("config"); | ||
|
||
form.getInputByName("_.smtpHost").setValue("acme.com"); | ||
form.getInputByName("_.defaultSuffix").setValue("@acme.com"); | ||
form.getInputByName("_.authentication").setChecked(true); | ||
form.getInputByName("_.username").setValue("user"); | ||
form.getInputByName("_.password").setValue("pass"); | ||
wc.waitForBackgroundJavaScript(1000); | ||
assertThat(form.getTextContent(), containsString(SHORT_PWD_ERROR_MESSAGE)); | ||
HtmlPage page = j.submit(form); | ||
WebResponse webResponse = page.getWebResponse(); | ||
assertNotEquals(200, webResponse.getStatusCode()); | ||
assertThat(webResponse.getContentAsString(), containsString(SHORT_PWD_ERROR_MESSAGE)); | ||
} | ||
|
||
} | ||
|
||
@Test @LocalData | ||
public void casc() throws Throwable { | ||
URL url = getClass().getResource("bad_fips_casc.yaml"); | ||
r.then(new _casc(url.toString())); | ||
} | ||
|
||
public static class _casc implements RealJenkinsRule.Step2<Serializable> { | ||
String resUrl; | ||
|
||
public _casc(String resUrl) { | ||
this.resUrl = resUrl; | ||
} | ||
|
||
@Override | ||
public Serializable run(JenkinsRule r) throws Throwable { | ||
try { | ||
ConfigurationAsCode.get().configure(resUrl); | ||
fail("The configuration should fail."); | ||
} catch (ConfiguratorException e) { | ||
Throwable cause = e.getCause(); | ||
assertNotNull(cause); | ||
cause = cause.getCause(); | ||
assertThat(cause, instanceOf(IllegalArgumentException.class)); | ||
assertThat(cause.getMessage(), containsString(SHORT_PWD_ERROR_MESSAGE)); | ||
} | ||
return null; | ||
} | ||
} | ||
|
||
} |
2 changes: 2 additions & 0 deletions
2
src/test/resources/jenkins/plugins/mailer/FipsModeTest/casc/secrets/hudson.util.Secret
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
...esources/jenkins/plugins/mailer/FipsModeTest/casc/secrets/jenkins.model.Jenkins.crumbSalt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
8e�J�V��W���O��2�t.˿u=� | ||
� | ||
|
1 change: 1 addition & 0 deletions
1
src/test/resources/jenkins/plugins/mailer/FipsModeTest/casc/secrets/master.key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
98e782a367e04fbffad76f28cc32eb0b7757ff91bd31656cdbcc42a0acf3b92f925b0abf9fbbbd51e7d79bace99d182bb4b337a485b519a73e9089c3e6a78184aeb514731bbb578c205879187411f7e8f709f183c5fdf098155ef56362636c4a5762aa831b6d5d82deb1adfc7f306139e6d480093f639484ecb3f9143bc56097 |
Binary file added
BIN
+272 Bytes
...psModeTest/casc/secrets/org.jenkinsci.main.modules.instance_identity.InstanceIdentity.KEY
Binary file not shown.
11 changes: 11 additions & 0 deletions
11
.../resources/jenkins/plugins/mailer/FipsModeTest/testBlowsUpOnStart/hudson.tasks.Mailer.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version='1.1' encoding='UTF-8'?> | ||
<hudson.tasks.Mailer_-DescriptorImpl plugin="mailer@999999-SNAPSHOT"> | ||
<defaultSuffix></defaultSuffix> | ||
<authentication> | ||
<username>smtpusr</username> | ||
<password>{AQAAABAAAAAQcrlS6VKIiJEH44B7K+oxdcs0j4LcZbicOnwQK0Ivlfg=}</password> | ||
</authentication> | ||
<useSsl>true</useSsl> | ||
<useTls>false</useTls> | ||
<charset>UTF-8</charset> | ||
</hudson.tasks.Mailer_-DescriptorImpl> |
5 changes: 5 additions & 0 deletions
5
...ins/mailer/FipsModeTest/testBlowsUpOnStart/jenkins.model.JenkinsLocationConfiguration.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version='1.1' encoding='UTF-8'?> | ||
<jenkins.model.JenkinsLocationConfiguration> | ||
<adminAddress>address not configured yet <nobody@nowhere></adminAddress> | ||
<jenkinsUrl>http://localhost:8080/jenkins/</jenkinsUrl> | ||
</jenkins.model.JenkinsLocationConfiguration> |
2 changes: 2 additions & 0 deletions
2
...sources/jenkins/plugins/mailer/FipsModeTest/testBlowsUpOnStart/secrets/hudson.util.Secret
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
...ns/plugins/mailer/FipsModeTest/testBlowsUpOnStart/secrets/jenkins.model.Jenkins.crumbSalt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
8e�J�V��W���O��2�t.˿u=� | ||
� | ||
|
1 change: 1 addition & 0 deletions
1
src/test/resources/jenkins/plugins/mailer/FipsModeTest/testBlowsUpOnStart/secrets/master.key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
98e782a367e04fbffad76f28cc32eb0b7757ff91bd31656cdbcc42a0acf3b92f925b0abf9fbbbd51e7d79bace99d182bb4b337a485b519a73e9089c3e6a78184aeb514731bbb578c205879187411f7e8f709f183c5fdf098155ef56362636c4a5762aa831b6d5d82deb1adfc7f306139e6d480093f639484ecb3f9143bc56097 |
Binary file added
BIN
+272 Bytes
...tBlowsUpOnStart/secrets/org.jenkinsci.main.modules.instance_identity.InstanceIdentity.KEY
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
unclassified: | ||
mailer: | ||
authentication: | ||
password: "{AQAAABAAAAAQcrlS6VKIiJEH44B7K+oxdcs0j4LcZbicOnwQK0Ivlfg=}" | ||
username: "smtpusr" | ||
charset: "UTF-8" | ||
useSsl: true | ||
useTls: false |