From a18c003e3b7497a4e5c8d4fd2f42e82fa4f59bed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Mu=C3=B1iz?= Date: Wed, 1 Sep 2021 12:21:05 +0200 Subject: [PATCH] [JENKINS-66514] BaseStandardCredentials ID validation error See details in JENKINS-66514 The fix is to remove the unnecesary explicit `checkUrl` so the legacy validation method is nt used. The check URL will be calculated automatically and the "new" (years old) mechanism kicks in. The test is checking that the validation error shows up when needed (and only when needed). --- .../id-and-description.jelly | 1 - .../impl/BaseStandardCredentialsTest.java | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/resources/com/cloudbees/plugins/credentials/impl/BaseStandardCredentials/id-and-description.jelly b/src/main/resources/com/cloudbees/plugins/credentials/impl/BaseStandardCredentials/id-and-description.jelly index a3a35c7be..ca3ae2d1c 100644 --- a/src/main/resources/com/cloudbees/plugins/credentials/impl/BaseStandardCredentials/id-and-description.jelly +++ b/src/main/resources/com/cloudbees/plugins/credentials/impl/BaseStandardCredentials/id-and-description.jelly @@ -31,7 +31,6 @@ diff --git a/src/test/java/com/cloudbees/plugins/credentials/impl/BaseStandardCredentialsTest.java b/src/test/java/com/cloudbees/plugins/credentials/impl/BaseStandardCredentialsTest.java index d6c8d5eee..dd8c30ba4 100644 --- a/src/test/java/com/cloudbees/plugins/credentials/impl/BaseStandardCredentialsTest.java +++ b/src/test/java/com/cloudbees/plugins/credentials/impl/BaseStandardCredentialsTest.java @@ -29,6 +29,7 @@ import com.cloudbees.plugins.credentials.CredentialsStore; import com.cloudbees.plugins.credentials.common.IdCredentials; import com.cloudbees.plugins.credentials.domains.Domain; +import com.gargoylesoftware.htmlunit.html.HtmlPage; import hudson.model.ModelObject; import hudson.model.User; import hudson.security.ACL; @@ -41,11 +42,15 @@ import org.junit.Test; import org.jvnet.hudson.test.JenkinsRule; import org.jvnet.hudson.test.MockFolder; +import org.xml.sax.SAXException; import static hudson.util.FormValidation.Kind.ERROR; import static hudson.util.FormValidation.Kind.OK; import static hudson.util.FormValidation.Kind.WARNING; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.core.StringContains.containsString; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; public class BaseStandardCredentialsTest { @@ -138,6 +143,17 @@ public void run() { // TODO could test the case that alice has Item.READ but not CredentialsProvider.VIEW on a folder, and mocks a web request passing that folder as context } + + @Test + public void noIDValidationMessageOnCredentialsUpdate() throws IOException, SAXException { + // create credentials with ID test + CredentialsStore store = lookupStore(r.jenkins); + addCreds(store, CredentialsScope.GLOBAL, "test"); + // check there is no validation message about a duplicated ID when updating + JenkinsRule.WebClient webClient = r.createWebClient(); + HtmlPage htmlPage = webClient.goTo("credentials/store/system/domain/_/credential/test/update"); + assertThat(htmlPage.asText(), not(containsString("This ID is already in use"))); + } private static CredentialsStore lookupStore(ModelObject object) { Iterator stores = CredentialsProvider.lookupStores(object).iterator();