-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-74964] Fix: Display error message when adding invalid certif…
…icate credentials
- Loading branch information
Showing
10 changed files
with
210 additions
and
7 deletions.
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
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
75 changes: 75 additions & 0 deletions
75
src/test/java/com/cloudbees/plugins/credentials/impl/CertificateCredentialsImplFIPSTest.java
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,75 @@ | ||
package com.cloudbees.plugins.credentials.impl; | ||
|
||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.apache.commons.text.StringEscapeUtils; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TemporaryFolder; | ||
import org.jvnet.hudson.test.RealJenkinsRule; | ||
|
||
import hudson.ExtensionList; | ||
import hudson.model.Descriptor; | ||
import hudson.util.FormValidation; | ||
|
||
import com.cloudbees.plugins.credentials.CredentialsScope; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.junit.Assert.assertThrows; | ||
|
||
public class CertificateCredentialsImplFIPSTest { | ||
|
||
@Rule | ||
public RealJenkinsRule rule = new RealJenkinsRule().javaOptions("-Djenkins.security.FIPS140.COMPLIANCE=true"); | ||
|
||
@Rule | ||
public TemporaryFolder tmp = new TemporaryFolder(); | ||
|
||
String pemCert; | ||
String pemKey; | ||
|
||
@Before | ||
public void setup() throws IOException { | ||
pemCert = IOUtils.toString(CertificateCredentialsImplFIPSTest.class.getResource("FIPSCerts.pem"), | ||
StandardCharsets.UTF_8); | ||
pemKey = IOUtils.toString(CertificateCredentialsImplFIPSTest.class.getResource("FIPSKey.pem"), | ||
StandardCharsets.UTF_8); | ||
} | ||
|
||
@Test | ||
public void doCheckPasswordTest() throws Throwable { | ||
rule.then(r -> { | ||
CertificateCredentialsImpl.DescriptorImpl descriptor = ExtensionList.lookupSingleton( | ||
CertificateCredentialsImpl.DescriptorImpl.class); | ||
FormValidation result = descriptor.doCheckPassword("passwordFipsCheck"); | ||
assertThat(result.kind, is(FormValidation.Kind.OK)); | ||
result = descriptor.doCheckPassword("foo"); | ||
assertThat(result.kind, is(FormValidation.Kind.ERROR)); | ||
assertThat(result.getMessage(), | ||
is(StringEscapeUtils.escapeHtml4(Messages.CertificateCredentialsImpl_ShortPasswordFIPS()))); | ||
}); | ||
} | ||
|
||
@Test | ||
public void invalidPEMKeyStoreTest() throws Throwable { | ||
CertificateCredentialsImpl.PEMEntryKeyStoreSource storeSource = new CertificateCredentialsImpl.PEMEntryKeyStoreSource( | ||
pemCert, pemKey); | ||
rule.then(r -> { | ||
new CertificateCredentialsImpl(CredentialsScope.GLOBAL, "certificate-validation", | ||
"Validate the certificate credentials", "passwordFipsCheck", storeSource); | ||
|
||
assertThrows(Descriptor.FormException.class, | ||
() -> new CertificateCredentialsImpl(CredentialsScope.GLOBAL, "certificate-validation", | ||
"Validate the certificate password", "foo", storeSource)); | ||
assertThrows(Descriptor.FormException.class, | ||
() -> new CertificateCredentialsImpl(CredentialsScope.GLOBAL, "certificate-validation", | ||
"Validate the certificate keyStore", "passwordFipsCheck", | ||
new CertificateCredentialsImpl.PEMEntryKeyStoreSource( | ||
null, null))); | ||
}); | ||
} | ||
} |
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
20 changes: 20 additions & 0 deletions
20
src/test/resources/com/cloudbees/plugins/credentials/impl/FIPSCerts.pem
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,20 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIDTzCCAjegAwIBAgIUWcaB9PB40lCu4um/CD8Ni6yNxkwwDQYJKoZIhvcNAQEL | ||
BQAwUDELMAkGA1UEBhMCSU4xCzAJBgNVBAgMAlROMREwDwYDVQQHDAhUaXJ1cHB1 | ||
cjEhMB8GA1UECgwYSW50ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMB4XDTI0MTEyODE2 | ||
MzI1OFoXDTI1MTEyODE2MzI1OFowUDELMAkGA1UEBhMCSU4xCzAJBgNVBAgMAlRO | ||
MREwDwYDVQQHDAhUaXJ1cHB1cjEhMB8GA1UECgwYSW50ZXJuZXQgV2lkZ2l0cyBQ | ||
dHkgTHRkMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAo8dgK5e2+wy3 | ||
2uRxF8hiaSFnUjfKOVDYrj+RbZ+ss9Kzxm2T3nfGcjGKHVHTvkaoduVdF95V8RtQ | ||
I2lbwPnb/RKY6+Rlx+74e6Aw+KvCAEFa0lt0dST7IpErEetDppkkR5N/RbVXvon8 | ||
sbJSHRZQOazFD2fG6MJJYiHqLC9xqfKOrZ07JQ9/J/mXN05mTG3gWXIlaJxf6hv3 | ||
+n2NfkaTioor9dHGwr03S9D4CJWbJvk2006WCh9TEKCrG+oOAU/Fm+mlWndeResv | ||
EWHiH13BMOsqWj/q9QlMYnmRl4MN00SSKKREQAUAAd6WbXg6+iavxGpN8eJw4O72 | ||
wti2bS6I4wIDAQABoyEwHzAdBgNVHQ4EFgQUsACQZeota/vgn2vOY0EVIMoKM7Iw | ||
DQYJKoZIhvcNAQELBQADggEBAEZ7qOLFPL4QJYcD3DYohFyOR2QeQQ5sceLlCg+/ | ||
vtET3TPqBGswHER4fkOUgehud9i/h6ff33KCgTGMpGCWkYISaAbCQgGeD8AJQIOX | ||
aWQ12Ux/E98a4Bk9nid0moiXKTXzMBule44JolGWroxayrJnYDCo39IraJO6XxlK | ||
SJnI1dA1uRuJl6XKHr1N/knH3QBE4wI3CjqHc9qjTXVprhRosmTykvIeLaNL/ZxW | ||
/QnKD5VRWRmHFom03COkmPSyGWNp225dLgN+rv9e2Pvn0AP8CeUJAoWSXwxGpv9Y | ||
AgIsGfIhwQIt3AsmmujlaLvjRQpxBh00ba77kteFR4S3WMk= | ||
-----END CERTIFICATE----- |
28 changes: 28 additions & 0 deletions
28
src/test/resources/com/cloudbees/plugins/credentials/impl/FIPSKey.pem
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,28 @@ | ||
-----BEGIN PRIVATE KEY----- | ||
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQChhYxialRHFZdE | ||
Y1d6A0zTCi6pMnQlk/DU2xt2qV6xrI/Jkz0xIuDjCA/vD4EyEEh7aPEY5Ooxz6zz | ||
tmrhF8nG2Nis4UBAxtTHqV2D5eLPfxtrRMccrIYh6121K0B45vqcHpBq/nFMNGyK | ||
q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